MCPcopy Create free account
hub / github.com/temporalio/temporal / parseConnectConfig

Function parseConnectConfig

tools/sql/handler.go:117–162  ·  view source on GitHub ↗
(cli *cli.Context)

Source from the content-addressed store, hash-verified

115}
116
117func parseConnectConfig(cli *cli.Context) (*config.SQL, error) {
118 cfg := new(config.SQL)
119
120 host := cli.GlobalString(schema.CLIOptEndpoint)
121 port := cli.GlobalInt(schema.CLIOptPort)
122 cfg.ConnectAddr = fmt.Sprintf("%s:%v", host, port)
123 cfg.User = cli.GlobalString(schema.CLIOptUser)
124 cfg.Password = cli.GlobalString(schema.CLIOptPassword)
125 cfg.DatabaseName = cli.GlobalString(schema.CLIOptDatabase)
126 cfg.PluginName = cli.GlobalString(schema.CLIOptPluginName)
127
128 if cfg.ConnectAttributes == nil {
129 cfg.ConnectAttributes = map[string]string{}
130 }
131 connectAttributesQueryString := cli.GlobalString(schema.CLIOptConnectAttributes)
132 if connectAttributesQueryString != "" {
133 values, err := url.ParseQuery(connectAttributesQueryString)
134 if err != nil {
135 return nil, fmt.Errorf("invalid connect attributes: %v", err)
136 }
137 for key, vals := range values {
138 // check to ensure only one value is provider per key
139 if len(vals) > 1 {
140 return nil, fmt.Errorf("invalid connect attribute %v, only 1 value allowed: %v", key, vals)
141 }
142 cfg.ConnectAttributes[key] = vals[0]
143 }
144 }
145
146 if cli.GlobalBool(schema.CLIFlagEnableTLS) {
147 cfg.TLS = &auth.TLS{
148 Enabled: true,
149 CertFile: cli.GlobalString(schema.CLIFlagTLSCertFile),
150 KeyFile: cli.GlobalString(schema.CLIFlagTLSKeyFile),
151 CaFile: cli.GlobalString(schema.CLIFlagTLSCaFile),
152 ServerName: cli.GlobalString(schema.CLIFlagTLSHostName),
153 EnableHostVerification: !cli.GlobalBool(schema.CLIFlagTLSDisableHostVerification),
154 }
155 }
156
157 if err := ValidateConnectConfig(cfg); err != nil {
158 return nil, err
159 }
160
161 return cfg, nil
162}
163
164// ValidateConnectConfig validates params
165func ValidateConnectConfig(cfg *config.SQL) error {

Callers 4

setupSchemaFunction · 0.85
updateSchemaFunction · 0.85
createDatabaseFunction · 0.85
dropDatabaseFunction · 0.85

Calls 2

ValidateConnectConfigFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected