pip_services3_azure.clients package

Submodules

Module contents

class pip_services3_azure.clients.AzureFunctionClient

Bases: pip_services3_commons.run.IOpenable.IOpenable, pip_services3_commons.config.IConfigurable.IConfigurable, pip_services3_commons.refer.IReferenceable.IReferenceable

Abstract client that calls Azure Functions.

When making calls “cmd” parameter determines which what action shall be called, while other parameters are passed to the action itself.

### Configuration parameters ###
  • connections:
    • uri: (optional) full connection string or use protocol, app_name and function_name to build

    • protocol: (optional) connection protocol

    • app_name: (optional) Azure Function application name

    • function_name: (optional) Azure Function name

  • credentials:
    • auth_code: Azure Function auth code if use custom authorization provide empty string

### References ###
  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages

  • *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements

  • *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection

  • *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials

See AzureFunction (in the Pip.Services components package), CommandableAzureClient (in the Pip.Services components package)

class MyAzureFunctionClient(AzureFunctionClient, IMyClient):
    ...

    def get_data(self, correlation_id: Optional[str], id: str) -> MyData:

        timing = self._instrument(correlation_id, 'myclient.get_data')
        result = self._call('get_data', correlation_id, {'id': id}
        timing.end_timing()
        return result

    ...

client = MyAzureFunctionClient()
client.configure(ConfigParams.from_tuples(
    "connection.uri", "http://myapp.azurewebsites.net/api/myfunction",
    "connection.protocol", "http",
    "connection.app_name", "myapp",
    "connection.function_name", "myfunction"
    "credential.auth_code", "XXXX"
))

result = client.get_data('123', '1')
close(correlation_id: Optional[str])

Closes component and frees used resources.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)

Configures component by passing configuration parameters.

Parameters

config – configuration parameters to be set.

is_open() bool

Checks if the component is opened.

Returns

true if the component has been opened and false otherwise.

open(correlation_id: Optional[str])

Opens the component.

Parameters

correlation_id – (optional) transaction id to trace execution through call chain.

set_references(references: pip_services3_commons.refer.IReferences.IReferences)

Sets references to dependent components.

Parameters

references – references to locate the component dependencies.

class pip_services3_azure.clients.CommandableAzureFunctionClient(name: str)

Bases: pip_services3_azure.clients.AzureFunctionClient.AzureFunctionClient

Abstract client that calls commandable Azure Functions.

Commandable services are generated automatically for ICommandable objects. Each command is exposed as action determined by “cmd” parameter.

### Configuration parameters ###
  • connections:
    • uri: (optional) full connection string or use protocol, app_name and function_name to build

    • protocol: (optional) connection protocol

    • app_name: (optional) Azure Function application name

    • function_name: (optional) Azure Function name

  • credentials:
    • auth_code: Azure Function auth code if use custom authorization provide empty string

### References ###
  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages

  • *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements

  • *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connection

  • *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials

class MyCommandableAzureClient(CommandableAzureFunctionClient, IMyClient):
    ...

    def get_data(self, correlation_id: Optional[str], id: str) -> Any:
        return self.call_command('get_data', correlation_id, {'id': id})

    ...

client = MyCommandableAzureClient('client_name')
client.configure(ConfigParams.from_еuples(
    "connection.uri", "http://myapp.azurewebsites.net/api/myfunction",
    "connection.protocol", "http",
    "connection.app_name", "myapp",
    "connection.function_name", "myfunction"
    "credential.auth_code", "XXXX"
))

result = client.get_data("123", "1")
call_command(cmd: str, correlation_id: Optional[str], params: dict) Any

Calls a remote action in Azure Function. The name of the action is added as “cmd” parameter to the action parameters.

Parameters
  • cmd – an action name

  • correlation_id – (optional) transaction id to trace execution through call chain.

  • params – command parameters.

Returns

action result.