# Code generated by KubeVela templates. DO NOT EDIT. Please edit the original cue file.
# Definition source cue file: vela-templates/definitions/internal/generate-jdbc-connection.cue
apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
  annotations:
    definition.oam.dev/description: Generate a JDBC connection based on Component of alibaba-rds
  labels:
    custom.definition.oam.dev/ui-hidden: "true"
  name: generate-jdbc-connection
  namespace: {{ include "systemDefinitionNamespace" . }}
spec:
  schematic:
    cue:
      template: |
        import (
        	"vela/op"
        	"encoding/base64"
        )

        output: op.#Read & {
        	value: {
        		apiVersion: "v1"
        		kind:       "Secret"
        		metadata: {
        			name: parameter.name
        			if parameter.namespace != _|_ {
        				namespace: parameter.namespace
        			}
        		}
        	}
        }
        dbHost:   op.#ConvertString & {bt: base64.Decode(null, output.value.data["DB_HOST"])}
        dbPort:   op.#ConvertString & {bt: base64.Decode(null, output.value.data["DB_PORT"])}
        dbName:   op.#ConvertString & {bt: base64.Decode(null, output.value.data["DB_NAME"])}
        username: op.#ConvertString & {bt: base64.Decode(null, output.value.data["DB_USER"])}
        password: op.#ConvertString & {bt: base64.Decode(null, output.value.data["DB_PASSWORD"])}
        env: [
        	{name: "url", value:      "jdbc://" + dbHost.str + ":" + dbPort.str + "/" + dbName.str + "?characterEncoding=utf8&useSSL=false"},
        	{name: "username", value: username.str},
        	{name: "password", value: password.str},
        ]
        parameter: {
        	// +usage=Specify the name of the secret generated by database component
        	name: string
        	// +usage=Specify the namespace of the secret generated by database component
        	namespace?: string
        }

