/
update-connection-credential.go
94 lines (60 loc) · 2.95 KB
/
update-connection-credential.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Code generated. DO NOT EDIT.
package main
import (
"github.com/spf13/cobra"
connectionpb "google.golang.org/genproto/googleapis/cloud/bigquery/connection/v1beta1"
"fmt"
"github.com/golang/protobuf/jsonpb"
"os"
)
var UpdateConnectionCredentialInput connectionpb.UpdateConnectionCredentialRequest
var UpdateConnectionCredentialFromFile string
var UpdateConnectionCredentialInputCredentialCredential string
var UpdateConnectionCredentialInputCredentialCredentialCloudSql connectionpb.ConnectionCredential_CloudSql
func init() {
ConnectionServiceCmd.AddCommand(UpdateConnectionCredentialCmd)
UpdateConnectionCredentialInput.Credential = new(connectionpb.ConnectionCredential)
UpdateConnectionCredentialInputCredentialCredentialCloudSql.CloudSql = new(connectionpb.CloudSqlCredential)
UpdateConnectionCredentialCmd.Flags().StringVar(&UpdateConnectionCredentialInput.Name, "name", "", "Required. Required. Name of the connection, for example: ...")
UpdateConnectionCredentialCmd.Flags().StringVar(&UpdateConnectionCredentialInputCredentialCredentialCloudSql.CloudSql.Username, "credential.credential.cloud_sql.username", "", "The username for the credential.")
UpdateConnectionCredentialCmd.Flags().StringVar(&UpdateConnectionCredentialInputCredentialCredentialCloudSql.CloudSql.Password, "credential.credential.cloud_sql.password", "", "The password for the credential.")
UpdateConnectionCredentialCmd.Flags().StringVar(&UpdateConnectionCredentialInputCredentialCredential, "credential.credential", "", "Choices: cloud_sql")
UpdateConnectionCredentialCmd.Flags().StringVar(&UpdateConnectionCredentialFromFile, "from_file", "", "Absolute path to JSON file containing request payload")
}
var UpdateConnectionCredentialCmd = &cobra.Command{
Use: "update-connection-credential",
Short: "Sets the credential for the specified connection.",
Long: "Sets the credential for the specified connection.",
PreRun: func(cmd *cobra.Command, args []string) {
if UpdateConnectionCredentialFromFile == "" {
cmd.MarkFlagRequired("name")
cmd.MarkFlagRequired("credential.credential")
}
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
in := os.Stdin
if UpdateConnectionCredentialFromFile != "" {
in, err = os.Open(UpdateConnectionCredentialFromFile)
if err != nil {
return err
}
defer in.Close()
err = jsonpb.Unmarshal(in, &UpdateConnectionCredentialInput)
if err != nil {
return err
}
} else {
switch UpdateConnectionCredentialInputCredentialCredential {
case "cloud_sql":
UpdateConnectionCredentialInput.Credential.Credential = &UpdateConnectionCredentialInputCredentialCredentialCloudSql
default:
return fmt.Errorf("Missing oneof choice for credential.credential")
}
}
if Verbose {
printVerboseInput("Connection", "UpdateConnectionCredential", &UpdateConnectionCredentialInput)
}
err = ConnectionClient.UpdateConnectionCredential(ctx, &UpdateConnectionCredentialInput)
return err
},
}