Ejemplo n.º 1
0
def get_delegation_config():
    """Returns imported config_pb2.DelegationConfig (or empty one if missing)."""
    text = _get_service_config('delegation.cfg')
    if not text:
        return config_pb2.DelegationConfig()
    # The config MUST be valid, since we do validation before storing it.
    # Nevertheless, handle the unexpected.
    try:
        msg = config_pb2.DelegationConfig()
        protobuf.text_format.Merge(text, msg)
    except protobuf.text_format.ParseError as ex:
        logging.error('Invalid delegation.cfg: %s', ex)
        return config_pb2.DelegationConfig()
    ctx = validation_context.Context.logging()
    validate_delegation_config(msg, ctx)
    if ctx.result().has_errors:
        return config_pb2.DelegationConfig()
    return msg
Ejemplo n.º 2
0
 def call_validate_delegation_config(r):
     ctx = validation_context.Context()
     conf = config_pb2.DelegationConfig(rules=[r])
     config.validate_delegation_config(conf, ctx)
     return [m.text for m in ctx.messages]
Ejemplo n.º 3
0
 def setUp(self):
   super(CheckCanCreateTokenTest, self).setUp()
   self.rules = []
   self.mock(
       config, 'get_delegation_config',
       lambda: config_pb2.DelegationConfig(rules=self.rules))