Alternera.Plugins.Sqs.Client (alternera_plugin_sqs v0.9.0)

Copy Markdown View Source

The calls an SQS step makes, for Alternera.Plugins.Sqs. SQS's JSON protocol: every call is a POST / to the queue URL's origin with Content-Type: application/x-amz-json-1.0, the action in X-Amz-Target: AmazonSQS.<Action> and the queue URL in the JSON body:

  • send: SendMessage with MessageBody, MessageAttributes, MessageGroupId, MessageDeduplicationId and DelaySeconds, answered with its MessageId;
  • receive: ReceiveMessage with MaxNumberOfMessages, WaitTimeSeconds and VisibilityTimeout, answered with {"Messages": [...]}, empty or left out when none came; with immediate deletes, DeleteMessageBatch with an entry per message;
  • delete: DeleteMessage with the ReceiptHandle;
  • release: ChangeMessageVisibility with the ReceiptHandle and its VisibilityTimeout;
  • counts: GetQueueAttributes with the three ApproximateNumberOf… names, answered with an Attributes object of strings.

Each call is signed with AWS Signature Version 4 (Sqs.SigV4) over its content-type, host, x-amz-date and x-amz-target headers and its body, with the access key id and the secret the step reveals (Plugin.Secret.reveal/3), and goes out through Plugin.Provisional.Outbound as the step's proxy user, its recording redacted. A forward pipeline of that proxy user that changes one of those headers or the body breaks the signature, and SQS answers 403. The calls end call_reserve_ms/1 before the step's own time, so a slow queue fails the step timeout with its call recorded rather than the runner stopping it.

Summary

Functions

An outbound call's result for action, read: {:ok, answer}, the answer's decoded JSON (nil when empty), or the call's failure, a status outside 2xx (http_status, with SQS's error) or an answer that is not JSON (invalid_response).

The entries a batch call's answer (its decoded JSON) says SQS refused, by their Id, each as "<code>: <message>"; none when it names none.

The Ids of the entries a batch call's answer (its decoded JSON) says SQS settled; none when it names none.

How long before the step's time is up its calls must be done.

url as a queue URL: http or https, a host, a path naming the queue, no query or fragment; {:error, message} otherwise.

A release's delay as whole seconds within visibility_timeout_s's range: {:ok, seconds} or {:error, message}, a message that names the editor's box and not the value. Sqs.init/1 checks a literal one with it, the run one a template resolved to.

Whether queue_url names a FIFO queue: its name ends in .fifo, as SQS requires of one.

The fingerprint of a resolved call: the operation, action, endpoint, body (a receive's wait time, which is cut to the time left, left out) and proxy user, so a dry run and the real run of the same call agree. The date and the signature are not part of it.

value, a whole number SQS sent as a number or as digits, or nil.

The queue's name: the last segment of its URL, or the URL as it is.

The messages of a ReceiveMessage answer (its decoded JSON, nil when empty), as SQS sent them: none when it carries none, {:error, message} (a fragment after "SQS's answer to a receive") when it is not a list of messages each with an id and a receipt handle.

The region an AWS queue URL's host names, or nil.

The secret access key reference names, revealed for context (whose reveal_keys hold secret_access_key), or auth_failed.

Runs the step's operation: call/3's result.

The region a call to queue_url is signed for: given when it is set, else the one an AWS queue URL's host names; invalid_config when neither names one.

The request for action with the JSON fields on target's queue (%{queue_url:, region:, access_key_id:, secret:}, the secret revealed), signed now, as Plugin.Provisional.Outbound.call/3 takes it. The queue URL goes into the body as every call's does. Sqs.Source calls it; a step builds its calls from its inputs (run/3).

What a preview says the step would do: the call, as whom and its fingerprint, with nothing sent and no secret revealed. A setting that does not resolve is named in place of the call.

Functions

answer(arg, action)

@spec answer(tuple(), String.t()) :: {:ok, term()} | {:error, String.t(), String.t()}

An outbound call's result for action, read: {:ok, answer}, the answer's decoded JSON (nil when empty), or the call's failure, a status outside 2xx (http_status, with SQS's error) or an answer that is not JSON (invalid_response).

batch_failures(answer)

@spec batch_failures(term()) :: %{required(String.t()) => String.t()}

The entries a batch call's answer (its decoded JSON) says SQS refused, by their Id, each as "<code>: <message>"; none when it names none.

batch_successes(answer)

@spec batch_successes(term()) :: MapSet.t(String.t())

The Ids of the entries a batch call's answer (its decoded JSON) says SQS settled; none when it names none.

call_reserve_ms(time_left_ms)

@spec call_reserve_ms(non_neg_integer()) :: non_neg_integer()

How long before the step's time is up its calls must be done.

check_queue_url(url)

@spec check_queue_url(String.t()) :: {:ok, String.t()} | {:error, String.t()}

url as a queue URL: http or https, a host, a path naming the queue, no query or fragment; {:error, message} otherwise.

delay_seconds(text)

@spec delay_seconds(String.t()) :: {:ok, non_neg_integer()} | {:error, String.t()}

A release's delay as whole seconds within visibility_timeout_s's range: {:ok, seconds} or {:error, message}, a message that names the editor's box and not the value. Sqs.init/1 checks a literal one with it, the run one a template resolved to.

fifo?(queue_url)

@spec fifo?(String.t()) :: boolean()

Whether queue_url names a FIFO queue: its name ends in .fifo, as SQS requires of one.

fingerprint(call, opts)

@spec fingerprint(map(), map()) :: String.t()

The fingerprint of a resolved call: the operation, action, endpoint, body (a receive's wait time, which is cut to the time left, left out) and proxy user, so a dry run and the real run of the same call agree. The date and the signature are not part of it.

integer(value)

@spec integer(term()) :: integer() | nil

value, a whole number SQS sent as a number or as digits, or nil.

queue_name(url)

@spec queue_name(String.t()) :: String.t()

The queue's name: the last segment of its URL, or the URL as it is.

raw_messages(answer)

@spec raw_messages(term()) :: {:ok, [map()]} | {:error, String.t()}

The messages of a ReceiveMessage answer (its decoded JSON, nil when empty), as SQS sent them: none when it carries none, {:error, message} (a fragment after "SQS's answer to a receive") when it is not a list of messages each with an id and a receipt handle.

region_of(url)

@spec region_of(String.t()) :: String.t() | nil

The region an AWS queue URL's host names, or nil.

reveal_secret(context, reference)

@spec reveal_secret(map(), String.t()) ::
  {:ok, Alternera.Plugin.Secret.t()} | {:error, String.t(), String.t()}

The secret access key reference names, revealed for context (whose reveal_keys hold secret_access_key), or auth_failed.

run(inputs, opts, context)

@spec run(Alternera.Plugin.Inputs.t(), map(), map()) :: tuple()

Runs the step's operation: call/3's result.

settle_region(given, queue_url)

@spec settle_region(String.t() | nil, String.t()) ::
  {:ok, String.t()} | {:error, String.t(), String.t()}

The region a call to queue_url is signed for: given when it is set, else the one an AWS queue URL's host names; invalid_config when neither names one.

signed_request(action, fields, target)

@spec signed_request(String.t(), map(), map()) :: map()

The request for action with the JSON fields on target's queue (%{queue_url:, region:, access_key_id:, secret:}, the secret revealed), signed now, as Plugin.Provisional.Outbound.call/3 takes it. The queue URL goes into the body as every call's does. Sqs.Source calls it; a step builds its calls from its inputs (run/3).

would_call(inputs, opts, context)

@spec would_call(Alternera.Plugin.Inputs.t(), map(), map()) :: map()

What a preview says the step would do: the call, as whom and its fingerprint, with nothing sent and no secret revealed. A setting that does not resolve is named in place of the call.