コード例 #1
0
def ParseDnssecConfigArgs(args, messages):
  """Parse all relevant command line arguments and generate a DNSSEC config.

  Args:
    args: (dict{str,(str|int)}) Dict of command line arguments; value type
        dependent on particular command line argument.
    messages: (module) Module (generally auto-generated by the API build rules)
        containing the API client's message classes.

  Returns:
    A messages.ManagedZoneDnsSecConfig instance populated from the given
    command line arguments.
  """

  dnssec_config = None
  key_specs = []

  ksk_key = ParseKey(
      args.ksk_algorithm,
      args.ksk_key_length,
      messages.DnsKeySpec.KeyTypeValueValuesEnum.keySigning,
      messages)
  if ksk_key is not None:
    key_specs.append(ksk_key)

  zsk_key = ParseKey(
      args.zsk_algorithm,
      args.zsk_key_length,
      messages.DnsKeySpec.KeyTypeValueValuesEnum.zoneSigning,
      messages)
  if zsk_key is not None:
    key_specs.append(zsk_key)

  dnssec_config_args = {}
  if key_specs:
    dnssec_config_args['defaultKeySpecs'] = key_specs
  if getattr(args, 'denial_of_existence', None) is not None:
    dnssec_config_args['nonExistence'] = (
        flags.GetDoeFlagMapper(messages).GetEnumForChoice(
            args.denial_of_existence))
  if args.dnssec_state is not None:
    dnssec_config_args['state'] = (
        flags.GetDnsSecStateFlagMapper(messages)
        .GetEnumForChoice(args.dnssec_state))

  if dnssec_config_args:
    dnssec_config = messages.ManagedZoneDnsSecConfig(**dnssec_config_args)

  return dnssec_config
コード例 #2
0
def ParseDnssecConfigArgs(args, messages, api_version='v1'):
    # TODO(b/215745011) Clean up this function once move to v2
    """Parse all relevant command line arguments and generate a DNSSEC config.

  Args:
    args: (dict{str,(str|int)}) Dict of command line arguments; value type
      dependent on particular command line argument.
    messages: (module) Module (generally auto-generated by the API build rules)
      containing the API client's message classes.
    api_version: api_version that this function should use.

  Returns:
    A messages.ManagedZoneDnsSecConfig instance populated from the given
    command line arguments.
  """

    dnssec_config = None
    key_specs = []

    key_enum = messages.DnsKeySpec.KeyTypeValueValuesEnum.KEY_SIGNING if api_version == 'v2' else messages.DnsKeySpec.KeyTypeValueValuesEnum.keySigning
    ksk_key = ParseKey(args.ksk_algorithm, args.ksk_key_length, key_enum,
                       messages)
    if ksk_key is not None:
        key_specs.append(ksk_key)

    key_enum = messages.DnsKeySpec.KeyTypeValueValuesEnum.ZONE_SIGNING if api_version == 'v2' else messages.DnsKeySpec.KeyTypeValueValuesEnum.zoneSigning

    zsk_key = ParseKey(args.zsk_algorithm, args.zsk_key_length, key_enum,
                       messages)
    if zsk_key is not None:
        key_specs.append(zsk_key)

    dnssec_config_args = {}
    if key_specs:
        dnssec_config_args['defaultKeySpecs'] = key_specs
    if getattr(args, 'denial_of_existence', None) is not None:
        dnssec_config_args['nonExistence'] = (
            flags.GetDoeFlagMapper(messages).GetEnumForChoice(
                args.denial_of_existence))
    if args.dnssec_state is not None:
        dnssec_config_args['state'] = (
            flags.GetDnsSecStateFlagMapper(messages).GetEnumForChoice(
                args.dnssec_state))

    if dnssec_config_args:
        dnssec_config = messages.ManagedZoneDnsSecConfig(**dnssec_config_args)

    return dnssec_config