# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
# Definition source cue file: vela-templates/definitions/internal/config-image-registry.cue
apiVersion: core.oam.dev/v1beta1
kind: ComponentDefinition
metadata:
  annotations:
    custom.definition.oam.dev/alias.config.oam.dev: Image Registry
    definition.oam.dev/description: Config information to authenticate image registry
  labels:
    custom.definition.oam.dev/catalog.config.oam.dev: velacore-config
    custom.definition.oam.dev/multi-cluster.config.oam.dev: "true"
    custom.definition.oam.dev/type.config.oam.dev: image-registry
    custom.definition.oam.dev/ui-hidden: "true"
  name: config-image-registry
  namespace: {{ include "systemDefinitionNamespace" . }}
spec:
  schematic:
    cue:
      template: |
        import (
        	"encoding/base64"
        	"encoding/json"
        )

        output: {
        	apiVersion: "v1"
        	kind:       "Secret"
        	metadata: {
        		name:      context.name
        		namespace: context.namespace
        		labels: {
        			"config.oam.dev/catalog":       "velacore-config"
        			"config.oam.dev/type":          "image-registry"
        			"config.oam.dev/multi-cluster": "true"
        			"config.oam.dev/identifier":    parameter.registry
        			"config.oam.dev/sub-type":      "auth"
        		}
        	}
        	if parameter.auth != _|_ {
        		type: "kubernetes.io/dockerconfigjson"
        	}
        	if parameter.auth == _|_ {
        		type: "Opaque"
        	}
        	if parameter.auth != _|_ {
        		stringData: ".dockerconfigjson": json.Marshal({
        			auths: "\(parameter.registry)": {
        				username: parameter.auth.username
        				password: parameter.auth.password
        				if parameter.auth.email != _|_ {
        					email: parameter.auth.email
        				}
        				auth: base64.Encode(null, (parameter.auth.username + ":" + parameter.auth.password))
        			}
        		})
        	}
        }
        parameter: {
        	// +usage=Image registry FQDN
        	registry: string
        	// +usage=Authenticate the image registry
        	auth?: {
        		// +usage=Private Image registry username
        		username: string
        		// +usage=Private Image registry password
        		password: string
        		// +usage=Private Image registry email
        		email?: string
        	}
        }
  workload:
    type: autodetects.core.oam.dev

