/
sora_cam_license_packs_update_quantity.go
185 lines (143 loc) · 5.38 KB
/
sora_cam_license_packs_update_quantity.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Code generated by soracom-cli generate-cmd. DO NOT EDIT.
package cmd
import (
"encoding/json"
"fmt"
"io"
"net/url"
"os"
"strings"
"github.com/spf13/cobra"
)
// SoraCamLicensePacksUpdateQuantityCmdLicensePackId holds value of 'license_pack_id' option
var SoraCamLicensePacksUpdateQuantityCmdLicensePackId string
// SoraCamLicensePacksUpdateQuantityCmdCurrentQuantity holds value of 'currentQuantity' option
var SoraCamLicensePacksUpdateQuantityCmdCurrentQuantity int64
// SoraCamLicensePacksUpdateQuantityCmdDesiredQuantity holds value of 'desiredQuantity' option
var SoraCamLicensePacksUpdateQuantityCmdDesiredQuantity int64
// SoraCamLicensePacksUpdateQuantityCmdBody holds contents of request body to be sent
var SoraCamLicensePacksUpdateQuantityCmdBody string
func InitSoraCamLicensePacksUpdateQuantityCmd() {
SoraCamLicensePacksUpdateQuantityCmd.Flags().StringVar(&SoraCamLicensePacksUpdateQuantityCmdLicensePackId, "license-pack-id", "", TRAPI("ID of the license pack."))
SoraCamLicensePacksUpdateQuantityCmd.Flags().Int64Var(&SoraCamLicensePacksUpdateQuantityCmdCurrentQuantity, "current-quantity", 0, TRAPI("Current license quantity of the license pack."))
SoraCamLicensePacksUpdateQuantityCmd.Flags().Int64Var(&SoraCamLicensePacksUpdateQuantityCmdDesiredQuantity, "desired-quantity", 0, TRAPI("Desired license quantity of the license pack."))
SoraCamLicensePacksUpdateQuantityCmd.Flags().StringVar(&SoraCamLicensePacksUpdateQuantityCmdBody, "body", "", TRCLI("cli.common_params.body.short_help"))
SoraCamLicensePacksUpdateQuantityCmd.RunE = SoraCamLicensePacksUpdateQuantityCmdRunE
SoraCamLicensePacksCmd.AddCommand(SoraCamLicensePacksUpdateQuantityCmd)
}
// SoraCamLicensePacksUpdateQuantityCmd defines 'update-quantity' subcommand
var SoraCamLicensePacksUpdateQuantityCmd = &cobra.Command{
Use: "update-quantity",
Short: TRAPI("/sora_cam/license_packs/{license_pack_id}/quantity:put:summary"),
Long: TRAPI(`/sora_cam/license_packs/{license_pack_id}/quantity:put:description`) + "\n\n" + createLinkToAPIReference("SoraCam", "updateSoraCamLicensePackQuantity"),
}
func SoraCamLicensePacksUpdateQuantityCmdRunE(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
return fmt.Errorf("unexpected arguments passed => %v", args)
}
opt := &apiClientOptions{
BasePath: "/v1",
Language: getSelectedLanguage(),
}
ac := newAPIClient(opt)
if v := os.Getenv("SORACOM_VERBOSE"); v != "" {
ac.SetVerbose(true)
}
err := ac.getAPICredentials()
if err != nil {
cmd.SilenceUsage = true
return err
}
param, err := collectSoraCamLicensePacksUpdateQuantityCmdParams(ac)
if err != nil {
return err
}
body, err := ac.callAPI(param)
if err != nil {
cmd.SilenceUsage = true
return err
}
if body == "" {
return nil
}
if rawOutput {
_, err = os.Stdout.Write([]byte(body))
} else {
return prettyPrintStringAsJSON(body)
}
return err
}
func collectSoraCamLicensePacksUpdateQuantityCmdParams(ac *apiClient) (*apiParams, error) {
var body string
var parsedBody interface{}
var err error
body, err = buildBodyForSoraCamLicensePacksUpdateQuantityCmd()
if err != nil {
return nil, err
}
contentType := "application/json"
if contentType == "application/json" {
err = json.Unmarshal([]byte(body), &parsedBody)
if err != nil {
return nil, fmt.Errorf("invalid json format specified for `--body` parameter: %s", err)
}
}
err = checkIfRequiredStringParameterIsSupplied("license_pack_id", "license-pack-id", "path", parsedBody, SoraCamLicensePacksUpdateQuantityCmdLicensePackId)
if err != nil {
return nil, err
}
return &apiParams{
method: "PUT",
path: buildPathForSoraCamLicensePacksUpdateQuantityCmd("/sora_cam/license_packs/{license_pack_id}/quantity"),
query: buildQueryForSoraCamLicensePacksUpdateQuantityCmd(),
contentType: contentType,
body: body,
noRetryOnError: noRetryOnError,
}, nil
}
func buildPathForSoraCamLicensePacksUpdateQuantityCmd(path string) string {
escapedLicensePackId := url.PathEscape(SoraCamLicensePacksUpdateQuantityCmdLicensePackId)
path = strReplace(path, "{"+"license_pack_id"+"}", escapedLicensePackId, -1)
return path
}
func buildQueryForSoraCamLicensePacksUpdateQuantityCmd() url.Values {
result := url.Values{}
return result
}
func buildBodyForSoraCamLicensePacksUpdateQuantityCmd() (string, error) {
var result map[string]interface{}
if SoraCamLicensePacksUpdateQuantityCmdBody != "" {
var b []byte
var err error
if strings.HasPrefix(SoraCamLicensePacksUpdateQuantityCmdBody, "@") {
fname := strings.TrimPrefix(SoraCamLicensePacksUpdateQuantityCmdBody, "@")
// #nosec
b, err = os.ReadFile(fname)
} else if SoraCamLicensePacksUpdateQuantityCmdBody == "-" {
b, err = io.ReadAll(os.Stdin)
} else {
b = []byte(SoraCamLicensePacksUpdateQuantityCmdBody)
}
if err != nil {
return "", err
}
err = json.Unmarshal(b, &result)
if err != nil {
return "", err
}
}
if result == nil {
result = make(map[string]interface{})
}
if SoraCamLicensePacksUpdateQuantityCmd.Flags().Lookup("current-quantity").Changed {
result["currentQuantity"] = SoraCamLicensePacksUpdateQuantityCmdCurrentQuantity
}
if SoraCamLicensePacksUpdateQuantityCmd.Flags().Lookup("desired-quantity").Changed {
result["desiredQuantity"] = SoraCamLicensePacksUpdateQuantityCmdDesiredQuantity
}
resultBytes, err := json.Marshal(result)
if err != nil {
return "", err
}
return string(resultBytes), nil
}