def expand()

in marketplace/deployer_util/expand_config.py [0:0]


def expand(values_dict, schema, app_uid=''):
  """Returns the expanded values according to schema."""
  schema.validate()

  valid_property_names = set(schema.properties.keys())
  valid_property_names.add(_IMAGE_REPO_PREFIX_PROPERTY_NAME)

  for k in values_dict:
    if k not in valid_property_names:
      raise InvalidProperty('No such property defined in schema: {}'.format(k))

  # Captures the final property name-value mappings.
  # This has both properties directly specified under schema's `properties` and
  # generated properties. See below for details about generated properties.
  result = {}
  # Captures only the generated properties. These are not directly specified in
  # the schema under `properties`. Rather, their name are specified in special
  # `generatedProperties` fields under each property's `x-google-marketplace`.
  # Note that properties with generated values are NOT generated properties.
  generated = {}

  if schema.is_v2():
    # Handles the images section of the schema.
    generate_v2_image_properties(schema, values_dict, generated)

  # Copy explicitly specified values and generate values into result.
  for k, prop in schema.properties.items():
    v = values_dict.get(k, None)

    # The value is not explicitly specified and
    # thus is eligible for auto-generation.
    if v is None:
      if prop.password:
        v = property_generator.generate_password(prop.password)
      elif prop.application_uid:
        v = app_uid or ''
      elif prop.tls_certificate:
        v = property_generator.generate_tls_certificate()
      elif prop.xtype == config_helper.XTYPE_ISTIO_ENABLED:
        # For backward compatibility.
        v = False
      elif prop.xtype == config_helper.XTYPE_INGRESS_AVAILABLE:
        # For backward compatibility.
        v = True
      elif prop.xtype == config_helper.XTYPE_DEPLOYER_IMAGE:
        v = maybe_derive_deployer_image(schema, values_dict)
      elif prop.default is not None:
        v = prop.default

    # Generate additional properties from this property.
    if v is not None:
      if prop.image:
        if not isinstance(v, str):
          raise InvalidProperty(
              'Invalid value for IMAGE property {}: {}'.format(k, v))
        generate_v1_properties_for_image(prop, v, generated)
      elif prop.string:
        if not isinstance(v, str):
          raise InvalidProperty(
              'Invalid value for STRING property {}: {}'.format(k, v))
        generate_properties_for_string(prop, v, generated)
      elif prop.tls_certificate:
        if not isinstance(v, str):
          raise InvalidProperty(
              'Invalid value for TLS_CERTIFICATE property {}: {}'.format(k, v))
        generate_properties_for_tls_certificate(prop, v, generated)
      elif prop.application_uid:
        generate_properties_for_appuid(prop, v, generated)

    if v is not None:
      result[k] = v

  validate_value_types(result, schema)
  validate_required_props(result, schema)

  # Copy generated properties into result, validating no collisions.
  for k, v in generated.items():
    if k in result:
      raise InvalidProperty(
          'The property is to be generated, but already has a value: {}'.format(
              k))
    result[k] = v
  return result