Exemplo n.º 1
0
 def get_metadata_async(service_id):
   if service_id == 'a':
     raise ndb.Return(service_config_pb2.ServiceDynamicMetadata(
         validation=service_config_pb2.Validator(
             patterns=[service_config_pb2.ConfigPattern(
                 config_set='services/foo',
                 path='bar.cfg',
             )],
             url='https://bar.verifier',
         )
     ))
   if service_id == 'b':
     raise ndb.Return(service_config_pb2.ServiceDynamicMetadata(
         validation=service_config_pb2.Validator(
             patterns=[service_config_pb2.ConfigPattern(
                 config_set=r'regex:projects/[^/]+',
                 path=r'regex:.+\.cfg',
             )],
             url='https://bar2.verifier',
           )))
   if service_id == 'c':
     raise ndb.Return(service_config_pb2.ServiceDynamicMetadata(
         validation=service_config_pb2.Validator(
             patterns=[service_config_pb2.ConfigPattern(
                 config_set=r'regex:.+',
                 path=r'regex:.+',
             )],
             url='https://ultimate.verifier',
           )))
   return None
Exemplo n.º 2
0
    def test_dict_to_dynamic_metadata(self):
        with self.assertRaises(services.DynamicMetadataError):
            services._dict_to_dynamic_metadata([])

        self.assertEqual(
            services._dict_to_dynamic_metadata({
                'version': '1.0',
                'validation': {
                    'url':
                    'https://a.com/validate',
                    'patterns': [
                        {
                            'config_set': 'projects/foo',
                            'path': 'bar.cfg'
                        },
                        {
                            'config_set': 'regex:services/.+',
                            'path': 'regex:.+'
                        },
                    ]
                }
            }),
            service_config_pb2.ServiceDynamicMetadata(
                validation=service_config_pb2.Validator(
                    url='https://a.com/validate',
                    patterns=[
                        service_config_pb2.ConfigPattern(
                            config_set='projects/foo', path='bar.cfg'),
                        service_config_pb2.ConfigPattern(
                            config_set='regex:services/.+', path='regex:.+'),
                    ])))
Exemplo n.º 3
0
    def test_get_metadata_async(self):
        self.mock(storage, 'get_self_config_async', mock.Mock())
        storage.get_self_config_async.return_value = future(
            service_config_pb2.ServicesCfg(services=[
                service_config_pb2.Service(
                    id='foo', metadata_url='https://foo.com/metadata')
            ]))

        self.mock(net, 'json_request_async', mock.Mock())
        net.json_request_async.return_value = future({
            'version': '1.0',
            'validation': {
                'url':
                'https://a.com/validate',
                'patterns': [
                    {
                        'config_set': 'projects/foo',
                        'path': 'bar.cfg'
                    },
                    {
                        'config_set': 'regex:services/.+',
                        'path': 'regex:.+'
                    },
                ]
            }
        })

        metadata = services.get_metadata_async('foo').get_result()
        self.assertEqual(
            metadata,
            service_config_pb2.ServiceDynamicMetadata(
                validation=service_config_pb2.Validator(
                    url='https://a.com/validate',
                    patterns=[
                        service_config_pb2.ConfigPattern(
                            config_set='projects/foo', path='bar.cfg'),
                        service_config_pb2.ConfigPattern(
                            config_set='regex:services/.+', path='regex:.+'),
                    ])))

        net.json_request_async.assert_called_once_with(
            'https://foo.com/metadata', scopes=net.EMAIL_SCOPE)

        storage.get_self_config_async.assert_called_once_with(
            common.SERVICES_REGISTRY_FILENAME, service_config_pb2.ServicesCfg)