SDK Auth#

This documentation auto-generates details about the Authentication and Authorization functionality provided by the SDK.

Service Auth#

HMAC authentication assistance methods.

exception libs.sdk.src.destiny_sdk.auth.AuthException(status_code: Annotated[int, Doc('\n                HTTP status code to send to the client.\n                ')], detail: Annotated[Any, Doc('\n                Any data to be sent to the client in the `detail` key of the JSON\n                response.\n                ')] = None, headers: Annotated[Dict[str, str] | None, Doc('\n                Any headers to send to the client in the response.\n                ')] = None)[source]#

An exception related to HTTP authentication.

Raised by implementations of the AuthMethod protocol.

raise AuthException(
    status_code=status.HTTP_401_UNAUTHORIZED,
    detail="Unable to parse authentication token.",
)
add_note()[source]#

Exception.add_note(note) – add a note to the exception

args[source]#
with_traceback()[source]#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class libs.sdk.src.destiny_sdk.auth.BypassHMACAuth(*args, **kwargs)[source]#

A fake auth class that will always respond successfully.

Intended for use in local environments and for testing.

Not for production use!

class libs.sdk.src.destiny_sdk.auth.HMACAuth(secret_key: str)[source]#

Adds HMAC auth when used as a router or endpoint dependency.

class libs.sdk.src.destiny_sdk.auth.HMACAuthMethod(*args, **kwargs)[source]#

Protocol for HMAC auth methods, enforcing the implmentation of __call__().

This allows FastAPI to call class instances as depenedencies in FastAPI routes, see https://fastapi.tiangolo.com/advanced/advanced-dependencies

auth = HMACAuthMethod()

router = APIRouter(
    prefix="/robots", tags=["robot"], dependencies=[Depends(auth)]
)
pydantic model libs.sdk.src.destiny_sdk.auth.HMACAuthorizationHeaders[source]#

The HTTP authorization headers required for HMAC authentication.

Expects the following headers to be present in the request

  • Authorization: Signature [request signature]

  • X-Client-Id: [UUID]

  • X-Request-Timestamp: [float]

Show Entity Relationship Diagram
digraph "Entity Relationship Diagram created by erdantic" {
   graph [fontcolor=gray66,
      fontname="Times New Roman,Times,Liberation Serif,serif",
      fontsize=9,
      nodesep=0.5,
      rankdir=LR,
      ranksep=1.5
   ];
   node [fontname="Times New Roman,Times,Liberation Serif,serif",
      fontsize=14,
      label="\N",
      shape=plain
   ];
   edge [dir=both];
   "libs.sdk.src.destiny_sdk.auth.HMACAuthorizationHeaders"   [label=<<table border="0" cellborder="1" cellspacing="0"><tr><td port="_root" colspan="2"><b>HMACAuthorizationHeaders</b></td></tr><tr><td>signature</td><td port="signature">str</td></tr><tr><td>client_id</td><td port="client_id">UUID</td></tr><tr><td>timestamp</td><td port="timestamp">float</td></tr></table>>,
      tooltip="libs.sdk.src.destiny_sdk.auth.HMACAuthorizationHeaders&#xA;&#xA;The HTTP authorization headers required for HMAC authentication.&#\
xA;&#xA;Expects the following headers to be present in the request&#xA;&#xA;- Authorization: Signature [request signature]&#xA;- \
X-Client-Id: [UUID]&#xA;- X-Request-Timestamp: [float]&#xA;"];
}

Show JSON schema
{
   "title": "HMACAuthorizationHeaders",
   "description": "The HTTP authorization headers required for HMAC authentication.\n\nExpects the following headers to be present in the request\n\n- Authorization: Signature [request signature]\n- X-Client-Id: [UUID]\n- X-Request-Timestamp: [float]",
   "type": "object",
   "properties": {
      "signature": {
         "title": "Signature",
         "type": "string"
      },
      "client_id": {
         "format": "uuid4",
         "title": "Client Id",
         "type": "string"
      },
      "timestamp": {
         "title": "Timestamp",
         "type": "number"
      }
   },
   "required": [
      "signature",
      "client_id",
      "timestamp"
   ]
}

Fields:
field client_id: Annotated[UUID, UuidVersion(uuid_version=4)] [Required][source]#
Constraints:
  • uuid_version = 4

field signature: str [Required][source]#
field timestamp: float [Required][source]#
classmethod from_request(request: Request) Self[source]#

Get the required headers for HMAC authentication.

Parameters:

request (Request) – The incoming request

Raises:
Returns:

Header values necessary for authenticating the request

Return type:

HMACAuthorizationHeaders

libs.sdk.src.destiny_sdk.auth.create_signature(secret_key: str, request_body: bytes, client_id: Annotated[UUID, UuidVersion(uuid_version=4)], timestamp: float) str[source]#

Create an HMAC signature using SHA256.

Parameters:
  • secret_key (bytes) – secret key with which to encrypt message

  • request_body (bytes) – request body to be encrypted

  • client_id – client id to include in hmac

  • timestamp – timestamp for when the request is sent

Type:

UUID4

Type:

float

Returns:

encrypted hexdigest of the request body with the secret key

Return type:

str

Client Auth#

Send authenticated requests to Destiny Repository.

class libs.sdk.src.destiny_sdk.client.Client(base_url: HttpUrl, secret_key: str, client_id: Annotated[UUID, UuidVersion(uuid_version=4)])[source]#

Client for interaction with the Destiny API.

Current implementation only supports robot results.

send_batch_robot_result(batch_robot_result: BatchRobotResult) BatchEnhancementRequestRead[source]#

Send a BatchRobotResult to destiny repository.

Signs the request with the client’s secret key.

Parameters:

batch_robot_result (BatchRobotResult) – The Batch Robot Result to send

Returns:

The BatchEnhancementRequestRead object from the response.

Return type:

BatchEnhancementRequestRead

send_robot_result(robot_result: RobotResult) EnhancementRequestRead[source]#

Send a RobotResult to destiny repository.

Signs the request with the client’s secret key.

Parameters:

robot_result (RobotResult) – The Robot Result to send

Returns:

The EnhancementRequestRead object from the response.

Return type:

EnhancementRequestRead

class libs.sdk.src.destiny_sdk.client.HMACSigningAuth(secret_key: str, client_id: Annotated[UUID, UuidVersion(uuid_version=4)])[source]#

Client that adds an HMAC signature to a request.

async async_auth_flow(request: Request) AsyncGenerator[Request, Response][source]#

Execute the authentication flow asynchronously.

By default, this defers to .auth_flow(). You should override this method when the authentication scheme does I/O and/or uses concurrency primitives.

auth_flow(request: Request) Generator[Request, Response][source]#

Add a signature to the given request.

Parameters:

request (httpx.Request) – request to be sent with signature

Yield:

Generator for Request with signature headers set

Return type:

Generator[httpx.Request, httpx.Response]

requires_request_body = True[source]#
requires_response_body = False[source]#
sync_auth_flow(request: Request) Generator[Request, Response, None][source]#

Execute the authentication flow synchronously.

By default, this defers to .auth_flow(). You should override this method when the authentication scheme does I/O and/or uses concurrency primitives.