コード例 #1
0
    def test_config_sections(self):
        config = ConfigParams.from_tuples("Section1.Key1", "Value1",
                                          "Section1.Key2", "Value2",
                                          "Section1.Key3", "Value3")
        assert 3 == len(config)
        assert "Value1" == config.get("Section1.Key1")
        assert "Value2" == config.get("Section1.Key2")
        assert "Value3" == config.get("Section1.Key3")
        assert None == config.get("Section1.Key4")

        section2 = ConfigParams.from_tuples("Key1", "ValueA", "Key2", "ValueB")
        config.add_section("Section2", section2)
        assert 5 == len(config)
        assert "ValueA" == config.get("Section2.Key1")
        assert "ValueB" == config.get("Section2.Key2")

        sections = config.get_section_names()
        assert 2 == len(sections)
        assert "Section1" in sections
        assert "Section2" in sections

        section1 = config.get_section("Section1")
        assert 3 == len(section1)
        assert "Value1" == section1.get("Key1")
        assert "Value2" == section1.get("Key2")
        assert "Value3" == section1.get("Key3")
    def test_read_config(self):
        config = ConfigParams.from_tuples("id", "ABC")
        name = NameResolver.resolve(config)
        assert "ABC" == name

        config = ConfigParams.from_tuples("name", "ABC")
        name = NameResolver.resolve(config)
        assert "ABC" == name
    def test_concat_options(self):
        options1 = ConfigParams.from_tuples("host", "server1", "port", "8080",
                                            "param1", "ABC")

        options2 = ConfigParams.from_tuples("host", "server2", "port", "8080",
                                            "param2", "XYZ")

        options = ConnectionUtils.concat(options1, options2)

        assert len(options) == 4
        assert "server1,server2" == options.get_as_nullable_string("host")
        assert "8080,8080" == options.get_as_nullable_string("port")
        assert "ABC" == options.get_as_nullable_string("param1")
        assert "XYZ" == options.get_as_nullable_string("param2")
 def test_lookup(self):
     credential_resolver = CredentialResolver()
     credential = credential_resolver.lookup("correlation_id")
     assert None == credential
     
     RestConfigWithoutStoreKey = ConfigParams.from_tuples(
         "credential.username", "Negrienko",
         "credential.password", "qwerty",
         "credential.access_key", "key"
     )
     credential_resolver = CredentialResolver(RestConfigWithoutStoreKey)
     credential = credential_resolver.lookup("correlation_id")
     assert "Negrienko"  == credential.get("username")
     assert "qwerty" == credential.get("password")
     assert "key" == credential.get("access_key")
     assert None == credential.get("store_key")
     
     credential_resolver = CredentialResolver(RestConfig)
     credential = credential_resolver.lookup("correlation_id")
     assert None == credential
     
     credential_resolver.set_references(References())
     try:
         credential = credential_resolver.lookup("correlation_id")
     except Exception as ex:
         assert "Cannot locate reference: Credential store wasn't found to make lookup" == ex.message
    def test_get_open_api_override(self):
        open_api_content = "swagger yaml content"

        # recreate service with new configuration
        self.service.close(None)

        config = rest_config.set_defaults(
            ConfigParams.from_tuples("swagger.auto", False))

        ctrl = DummyController()

        self.service = DummyCommandableHttpService()
        self.service.configure(config)

        references = References.from_tuples(
            Descriptor('pip-services-dummies', 'controller', 'default',
                       'default', '1.0'), ctrl,
            Descriptor('pip-services-dummies', 'service', 'http', 'default',
                       '1.0'), self.service)
        self.service.set_references(references)

        try:
            self.service.open(None)

            response = requests.request('GET',
                                        'http://localhost:3005/dummy/swagger')
            assert response.text == open_api_content
        finally:
            self.service.close(None)
    def test_lookup_and_store(self):
        config = ConfigParams.from_tuples('key1.user', 'user1', 'key1.pass',
                                          'pass1', 'key2.user', 'user2',
                                          'key2.pass', 'pass2')

        credential_store = MemoryCredentialStore()
        credential_store.read_credentials(config)

        cred1 = credential_store.lookup('123', 'key1')
        cred2 = credential_store.lookup('123', 'key2')

        assert cred1.get_username() == 'user1'
        assert cred1.get_password() == 'pass1'
        assert cred2.get_username() == 'user2'
        assert cred2.get_password() == 'pass2'

        cred_config = CredentialParams.from_tuples('user', 'user3', 'pass',
                                                   'pass3', 'access_id', '123')

        credential_store.store(None, 'key3', cred_config)

        cred3 = credential_store.lookup('123', 'key3')

        assert cred3.get_username() == 'user3'
        assert cred3.get_password() == 'pass3'
        assert cred3.get_access_id() == '123'
コード例 #7
0
    def test_read_connections(self):
        config = ConfigParams.from_tuples("connections.key1.host",
                                          "10.1.1.100",
                                          "connections.key1.port", "8080",
                                          "connections.key2.host",
                                          "10.1.1.101",
                                          "connections.key2.port", "8082")

        discovery = MemoryDiscovery()
        discovery.configure(config)

        # Resolve one
        connection = discovery.resolve_one("123", "key1")
        assert "10.1.1.100" == connection.get_host()
        assert 8080 == connection.get_port()

        connection = discovery.resolve_one("123", "key2")
        assert "10.1.1.101" == connection.get_host()
        assert 8082 == connection.get_port()

        # Resolve all
        discovery.register(None, "key1",
                           ConnectionParams.from_tuples("host", "10.3.3.151"))

        connections = discovery.resolve_all("123", "key1")

        assert len(connections) > 1
コード例 #8
0
    def setup_method(self, method):
        config = ConfigParams.from_tuples("options.timeout", 500)

        self.cache = MemoryCache()
        self.cache.configure(config)

        self.fixture = CacheFixture(self.cache)
 def test_resolve_parameters(self):
     connection_resolver = HttpConnectionResolver()
     connection_resolver.configure(
         ConfigParams.from_tuples("connection.protocol", "http",
                                  "connection.host", "somewhere.com",
                                  "connection.port", 777))
     connection = connection_resolver.resolve(None)
     assert connection.get_as_string('uri') == "http://somewhere.com:777"
コード例 #10
0
 def __init__(self):
     self._default_config = ConfigParams.from_tuples(
         "base_route", None, "dependencies.endpoint",
         "*:endpoint:http:*:1.0")
     # self._registered = False
     self._dependency_resolver = DependencyResolver()
     self._logger = CompositeLogger()
     self._counters = CompositeCounters()
コード例 #11
0
 def test_from_config(self):
     config = ConfigParams.from_tuples("name", "new name", "description",
                                       "new description",
                                       "properties.access_key", "key",
                                       "properties.store_key", "store key")
     context_info = ContextInfo.from_config(config)
     assert context_info.name == "new name"
     assert context_info.description == "new description"
    def test_config_params(self):
        component_config = ComponentConfig()
        assert None == component_config.descriptor

        config = ConfigParams.from_tuples("config.key", "key", "config.key2",
                                          "key2")
        component_config.config = config
        assert component_config.config == config
コード例 #13
0
    def test_connection_uri(self):
        connection_resolver = HttpConnectionResolver()
        connection_resolver.configure(ConfigParams.from_tuples("connection.uri", "https://somewhere.com:123"))

        connection = connection_resolver.resolve(None)

        assert connection.get_protocol() == "https"
        assert connection.get_host() == "somewhere.com"
        assert connection.get_port() == 123
        assert connection.get_uri() == "https://somewhere.com:123"
    def test_exclude_keys(self):
        options1 = ConfigParams.from_tuples("host", "server1", "port", "8080",
                                            "param1", "ABC")

        options = ConnectionUtils.exclude(options1, "host", "port")

        assert len(options) == 1
        assert options.get_as_nullable_string("host") is None
        assert options.get_as_nullable_string("port") is None
        assert "ABC" == options.get_as_nullable_string("param1")
コード例 #15
0
    def test_from_config(self):
        config = ConfigParams.from_tuples("field1.field11", 123, "field2",
                                          "ABC", "field1.field12", "XYZ")

        params = Parameters.from_config(config)
        assert 2 == len(params)
        assert "ABC" == params.get("field2")
        value = params.get_as_map("field1")
        assert 2 == len(value)
        assert "123" == value.get("field11")
        assert "XYZ" == value.get("field12")
    def test_resolve_uri(self):
        connection_resolver = HttpConnectionResolver()
        connection_resolver.configure(
            ConfigParams.from_tuples("connection.uri",
                                     "http://somewhere.com:777"))
        connection = connection_resolver.resolve(None)

        assert connection.get_as_string('protocol') == "http"
        assert connection.get_as_string('host') == "somewhere.com"
        assert connection.get_as_integer('port') == 777
        assert connection.get_as_string('uri') == "http://somewhere.com:777"
    def setup_class(cls):
        if cls.mongoUri is None and cls.mongoHost is None:
            return

        db_config = ConfigParams.from_tuples('connection.uri', cls.mongoUri,
                                             'connection.host', cls.mongoHost,
                                             'connection.port', cls.mongoPort,
                                             'connection.database',
                                             cls.mongoDatabase)
        cls.connection = MongoDbConnection()
        cls.connection.configure(db_config)
        cls.connection.open(None)
コード例 #18
0
    def __init__(self):
        """
        Creates a new instance of the connection component.
        """
        self.__default_config = ConfigParams.from_tuples(
            'options.max_pool_size', 2, 'options.keep_alive', 1,
            'options.connect_timeout', 5000, 'options.auto_reconnect', True,
            'options.max_page_size', 100, 'options.debug', True)

        self._logger = CompositeLogger()
        self._connection_resolver = MongoDbConnectionResolver()
        self._options = ConfigParams()
    def test_parse_uri_2(self):
        options = ConfigParams.from_tuples("host", "broker1,broker2", "port",
                                           ",8082", "username", "user",
                                           "password", "pass123", "param1",
                                           "ABC", "param2", "XYZ", "param3",
                                           None)

        uri = ConnectionUtils.compose_uri(options, "tcp", 9092)
        assert uri == "tcp://*****:*****@broker1:9092,broker2:8082?param1=ABC&param2=XYZ&param3"

        uri = ConnectionUtils.compose_uri(options, None, None)
        assert uri == "user:pass123@broker1,broker2:8082?param1=ABC&param2=XYZ&param3"
    def setup_method(self, method=None):
        host = os.environ.get('PUSHGATEWAY_SERVICE_HOST') or 'localhost'
        port = os.environ.get('PUSHGATEWAY_SERVICE_PORT') or 9091

        self.__counters = PrometheusCounters()
        self.__fixture = CountersFixture(self.__counters)

        config = ConfigParams.from_tuples('source', 'test', 'connection.host',
                                          host, 'connection.port', port)

        self.__counters.configure(config)

        self.__counters.open(None)
    def setup_class(cls):
        if cls.mysql_uri is None and cls.mysql_host is None:
            return
        db_config = ConfigParams.from_tuples(
            'connection.uri', cls.mysql_uri, 'connection.host', cls.mysql_host,
            'connection.port', cls.mysql_port, 'connection.database',
            cls.mysql_database, 'credential.username', cls.mysql_user,
            'credential.password', cls.mysql_password)
        cls.persistence = DummyMySqlPersistence()
        cls.fixture = DummyPersistenceFixture(cls.persistence)

        cls.persistence.configure(db_config)
        cls.persistence.open(None)
    def setup_class(cls):
        if cls.mongoUri is None and cls.mongoHost is None:
            return

        db_config = ConfigParams.from_tuples('connection.uri', cls.mongoUri,
                                             'connection.host', cls.mongoHost,
                                             'connection.port', cls.mongoPort,
                                             'connection.database', cls.mongoDatabase)
        cls.persistence = BeaconsMongoDbPersistence()
        cls.fixture = BeaconsPersistenceFixture(cls.persistence)

        cls.persistence.configure(db_config)
        cls.persistence.open(None)
    def setup_class(cls):
        if cls.mysql_uri is None and cls.mysql_host is None:
            return

        db_config = ConfigParams.from_tuples(
            'connection.uri', cls.mysql_uri, 'connection.host', cls.mysql_host,
            'connection.port', cls.mysql_port, 'connection.database',
            cls.mysql_database, 'credential.username', cls.mysql_user,
            'credential.password', cls.mysql_password)
        cls.connection = MySqlConnection()
        cls.connection.configure(db_config)

        cls.connection.open(None)
コード例 #24
0
 def __init__(self):
     """
     Creates a new instance of the client.
     """
     self._connection_resolver = HttpConnectionResolver()
     self._default_config = ConfigParams.from_tuples(
         "connection.protocol", "http", "connection.host", "0.0.0.0",
         "connection.port", 3000, "options.timeout", 10000,
         "options.request_max_size", 1024 * 1024, "options.connect_timeout",
         10000, "options.retries", 3, "options.debug", True)
     self._logger = CompositeLogger()
     self._counters = CompositeCounters()
     self._options = ConfigParams()
     self._headers = {}
    def setup_method(self):
        host = os.environ.get('MEMCACHED_SERVICE_HOST') or 'localhost'
        port = os.environ.get('MEMCACHED_SERVICE_PORT') or 11211

        self._cache = MemcachedCache()

        config = ConfigParams.from_tuples('connection.host', host,
                                          'connection.port', port)

        self._cache.configure(config)

        self._fixture = CacheFixture(self._cache)

        self._cache.open(None)
コード例 #26
0
    def setup_method(self):
        host = os.environ.get('REDIS_SERVICE_HOST') or 'localhost'
        port = os.environ.get('REDIS_SERVICE_PORT') or 6379

        self._lock = RedisLock()

        config = ConfigParams.from_tuples('connection.host', host,
                                          'connection.port', port)

        self._lock.configure(config)

        self._fixture = LockFixture(self._lock)

        self._lock.open(None)
コード例 #27
0
    def test_https_with_no_credentials_connection_params(self):
        connection_resolver = HttpConnectionResolver()
        connection_resolver.configure(ConfigParams.from_tuples(
            "connection.host", "somewhere.com",
            "connection.port", 123,
            "connection.protocol", "https",
            "credential.internal_network", "internal_network"
        ))
        connection = connection_resolver.resolve(None)

        assert 'https' == connection.get_protocol()
        assert 'somewhere.com' == connection.get_host()
        assert 123 == connection.get_port()
        assert 'https://somewhere.com:123' == connection.get_uri()
        assert connection.get('credential.internal_network')
    def test_from_config(self):
        config = ConfigParams.from_tuples()
        try:
            component_config = ComponentConfig.from_config(config)
        except ConfigException as e:
            assert e.message == "Component configuration must have descriptor or type"

        config = ConfigParams.from_tuples("descriptor", "descriptor_name",
                                          "type", "type", "config.key", "key",
                                          "config.key2", "key2")
        try:
            component_config = ComponentConfig.from_config(config)
        except ConfigException as e:
            assert e.message == "Descriptor descriptor_name is in wrong format"

        descriptor = Descriptor("group", "type", "kind", "name", "version")
        tipe = TypeDescriptor("type", None)
        config = ConfigParams.from_tuples("descriptor",
                                          "group:type:kind:name:version",
                                          "type", "type", "config.key", "key",
                                          "config.key2", "key2")
        component_config = ComponentConfig.from_config(config)
        assert component_config.descriptor == descriptor
        assert component_config.type == tipe
コード例 #29
0
 def __init__(self):
     """
     Creates HttpEndpoint
     """
     self._default_config = ConfigParams.from_tuples(
         "connection.protocol", "http", "connection.host", "0.0.0.0",
         "connection.port", 3000, "credential.ssl_key_file", None,
         "credential.ssl_crt_file", None, "credential.ssl_ca_file", None,
         "options.maintenance_enabled", False, "options.request_max_size",
         1024 * 1024, "options.file_max_size", 200 * 1024 * 1024,
         "connection.connect_timeout", 60000, "connection.debug", True)
     self._connection_resolver = HttpConnectionResolver()
     self._logger = CompositeLogger()
     self._counters = CompositeCounters()
     self._registrations = []
    def test_https_with_no_credentials_connection_params(self):
        connection_resolver = HttpConnectionResolver()
        connection_resolver.configure(
            ConfigParams.from_tuples("connection.host", "somewhere.com",
                                     "connection.port", 123,
                                     "connection.protocol", "https",
                                     "credential.internal_network",
                                     "internal_network"))
        connection = connection_resolver.resolve(None)

        assert 'https' == connection.get_as_string('protocol')
        assert 'somewhere.com' == connection.get_as_string('host')
        assert 123 == connection.get_as_integer('port')
        assert 'https://somewhere.com:123' == connection.get_as_string('uri')
        assert connection.get_as_nullable_string('internal_network') is None