pip_services3_components.connect.ConnectionParams module

pip_services3_components.connect.ConnectionParams

Connection parameters implementation

copyright

Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.

license

MIT, see LICENSE for more details.

class pip_services3_components.connect.ConnectionParams.ConnectionParams(map: Any = None)

Bases: pip_services3_commons.config.ConfigParams.ConfigParams

Contains connection parameters to connect to external services.

They are used together with credential parameters, but usually stored separately from more protected sensitive values.

### Configuration parameters ###
  • discovery_key: key to retrieve parameters from discovery service

  • protocol: connection protocol like http, https, tcp, udp

  • host: host name or IP address

  • port: port number

  • uri: resource URI or connection string with all parameters in it

In addition to standard parameters ConnectionParams may contain any number of custom parameters

Example:

connection = ConnectionParams.from_tuples("protocol", "http",
                                          "host", "10.1.1.100",
                                          "port", "8080",
                                          "cluster", "mycluster")

host = connection.get_host()                              # Result: "10.1.1.100"
port = connection.get_port()                              # Result: 8080
cluster = connection.get_as_nullable_string("cluster")    # Result: "mycluster"
static from_config(config: pip_services3_commons.config.ConfigParams.ConfigParams)pip_services3_components.connect.ConnectionParams.ConnectionParams

Retrieves a single ConnectionParams from configuration parameters from “connection” section. If “connections” section is present instead, then is returns only the first connection element.

Parameters

config – ConnectionParams, containing a section named “connection(s)”.

Returns

the generated ConnectionParams object.

static from_string(line: str)pip_services3_components.connect.ConnectionParams.ConnectionParams

Creates a new ConnectionParams object filled with key-value pairs serialized as a string.

Parameters

line – a string with serialized key-value pairs as “key1=value1;key2=value2;…” Example: “Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z”

Returns

a new ConnectionParams object.

static from_tuples(*tuples: Any)pip_services3_components.connect.ConnectionParams.ConnectionParams

Creates a new ConnectionParams object filled with provided key-value pairs called tuples. Tuples parameters contain a sequence of key1, value1, key2, value2, … pairs.

Parameters

tuples – the tuples to fill a new ConnectionParams object.

Returns

a new ConnectionParams object.

get_discovery_key()str

Gets the key to retrieve this connection from DiscoveryService. If this key is null, than all parameters are already present.

Returns

the discovery key to retrieve connection.

get_host()str

Gets the host name or IP address.

Returns

the host name or IP address.

get_port()int

Gets the port number.

Returns

the port number.

get_port_with_default(default_port: int)int

Gets the port number with default value.

Parameters

default_port – a default port number.

Returns

the port number.

get_protocol()str

Gets the connection protocol.

Returns

the connection protocol or the default value if it’s not set.

get_protocol_with_default(default_value: str = None)str

Gets the connection protocol with default value.

Parameters

default_value – (optional) the default protocol

Returns

the connection protocol or the default value if it’s not set.

get_uri()str

Gets the resource URI or connection string. Usually it includes all connection parameters in it.

Returns

the resource URI or connection string.

static many_from_config(config: pip_services3_commons.config.ConfigParams.ConfigParams) → List[pip_services3_components.connect.ConnectionParams.ConnectionParams]

Retrieves all ConnectionParams from configuration parameters from “connections” section. If “connection” section is present instead, than it returns a list with only one ConnectionParams.

Parameters

config – a configuration parameters to retrieve connections

Returns

a list of retrieved ConnectionParams

set_discovery_key(value: str)

Sets the key to retrieve these parameters from DiscoveryService.

Parameters

value – a new key to retrieve connection.

set_host(value: str)

Sets the host name or IP address.

Parameters

value – a new host name or IP address.

set_port(value: int)

Sets the port number.

Parameters

value – a new port number.

set_protocol(value: str)

Sets the connection protocol.

Parameters

value – a new connection protocol.

set_uri(value: str)

Sets the resource URI or connection string.

Parameters

value – a new resource URI or connection string.

use_discovery()bool

Checks if these connection parameters shall be retrieved from DiscoveryService. The connection parameters are redirected to DiscoveryService when discovery_key parameter is set.

Returns

true if connection shall be retrieved from DiscoveryService