コード例 #1
0
ファイル: __init__.py プロジェクト: robertabbott/brkt-cli
def parse_brkt_env(brkt_env_string):
    """ Parse the --brkt-env value.  The value is in the following format:

    api_host:port,hsmproxy_host:port,network_host:port

    :return: a BracketEnvironment object
    :raise: ValidationError if brkt_env is malformed
    """
    error_msg = (
        '--brkt-env value must be in the following format: '
        '<api-host>:<api-port>,<hsm-proxy-host>:<hsm-proxy-port>,'
        '<network-host>:<network-port>'
    )
    endpoints = brkt_env_string.split(',')
    if len(endpoints) != 3:
        raise ValidationError(error_msg)

    be = BracketEnvironment()
    names = ('api', 'hsmproxy', 'network')
    for name, endpoint in zip(names, endpoints):
        try:
            parts = util.parse_endpoint(endpoint)
            if 'port' not in parts:
                raise ValidationError(error_msg)
            setattr(be, name + '_host', parts['host'])
            setattr(be, name + '_port', parts['port'])
            if name == 'api':
                # set public api host based on the same prefix assumption
                # service-domain makes. Hopefully we'll remove brkt-env
                # soon and we can get rid of it
                be.public_api_host = be.api_host.replace('yetiapi', 'api')
        except ValueError:
            raise ValidationError(error_msg)

    return be
コード例 #2
0
ファイル: __init__.py プロジェクト: robertabbott/brkt-cli
 def _set_env(self, values):
     """Update attributes for the named environment"""
     if values.env_name == BRKT_HOSTED_ENV_NAME:
         raise ValidationError(
             'Error: cannot modify environment ' + values.env_name)
     try:
         env = self.parsed_config.get_env(values.env_name)
     except UnknownEnvironmentError:
         env = brkt_cli.BracketEnvironment()
     opt_attr = {
         'api': 'api',
         'key': 'hsmproxy',
         'public_api': 'public_api',
         'network': 'network',
     }
     for k in opt_attr.iterkeys():
         endpoint = k + '_server'
         endpoint = getattr(values, endpoint)
         if endpoint is None:
             continue
         try:
             parts = parse_endpoint(endpoint)
         except ValueError:
             raise ValidationError('Error: Invalid value for option --' + k + '-server')
         setattr(env, opt_attr[k] + '_host', parts['host'])
         setattr(env, opt_attr[k] + '_port', parts.get('port', 443))
     if values.service_domain is not None:
         env = brkt_cli.brkt_env_from_domain(values.service_domain)
     self.parsed_config.set_env(values.env_name, env)
     self._write_config()
     return 0