-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathunset.go
More file actions
349 lines (327 loc) · 17.1 KB
/
unset.go
File metadata and controls
349 lines (327 loc) · 17.1 KB
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
package unset
import (
"fmt"
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/config"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
const (
asyncFlag = globalflags.AsyncFlag
outputFormatFlag = globalflags.OutputFormatFlag
projectIdFlag = globalflags.ProjectIdFlag
regionFlag = globalflags.RegionFlag
verbosityFlag = globalflags.VerbosityFlag
assumeYesFlag = globalflags.AssumeYesFlag
sessionTimeLimitFlag = "session-time-limit"
identityProviderCustomWellKnownConfigurationFlag = "identity-provider-custom-well-known-configuration"
identityProviderCustomClientIdFlag = "identity-provider-custom-client-id"
allowedUrlDomainFlag = "allowed-url-domain"
authorizationCustomEndpointFlag = "authorization-custom-endpoint"
dnsCustomEndpointFlag = "dns-custom-endpoint"
edgeCustomEndpointFlag = "edge-custom-endpoint"
loadBalancerCustomEndpointFlag = "load-balancer-custom-endpoint"
logMeCustomEndpointFlag = "logme-custom-endpoint"
mariaDBCustomEndpointFlag = "mariadb-custom-endpoint"
mongoDBFlexCustomEndpointFlag = "mongodbflex-custom-endpoint"
objectStorageCustomEndpointFlag = "object-storage-custom-endpoint"
observabilityCustomEndpointFlag = "observability-custom-endpoint"
openSearchCustomEndpointFlag = "opensearch-custom-endpoint"
postgresFlexCustomEndpointFlag = "postgresflex-custom-endpoint"
rabbitMQCustomEndpointFlag = "rabbitmq-custom-endpoint"
redisCustomEndpointFlag = "redis-custom-endpoint"
resourceManagerCustomEndpointFlag = "resource-manager-custom-endpoint"
secretsManagerCustomEndpointFlag = "secrets-manager-custom-endpoint"
kmsCustomEndpointFlag = "kms-custom-endpoint"
serviceAccountCustomEndpointFlag = "service-account-custom-endpoint"
serviceEnablementCustomEndpointFlag = "service-enablement-custom-endpoint"
serverBackupCustomEndpointFlag = "serverbackup-custom-endpoint"
serverOsUpdateCustomEndpointFlag = "server-osupdate-custom-endpoint"
runCommandCustomEndpointFlag = "runcommand-custom-endpoint"
sfsCustomEndpointFlag = "sfs-custom-endpoint"
skeCustomEndpointFlag = "ske-custom-endpoint"
sqlServerFlexCustomEndpointFlag = "sqlserverflex-custom-endpoint"
iaasCustomEndpointFlag = "iaas-custom-endpoint"
tokenCustomEndpointFlag = "token-custom-endpoint"
intakeCustomEndpointFlag = "intake-custom-endpoint"
logsCustomEndpointFlag = "logs-custom-endpoint"
cdnCustomEndpointFlag = "cdn-custom-endpoint"
)
type inputModel struct {
Async bool
OutputFormat bool
ProjectId bool
Region bool
Verbosity bool
AssumeYes bool
SessionTimeLimit bool
IdentityProviderCustomEndpoint bool
IdentityProviderCustomClientID bool
AllowedUrlDomain bool
AuthorizationCustomEndpoint bool
DNSCustomEndpoint bool
EdgeCustomEndpoint bool
LoadBalancerCustomEndpoint bool
LogMeCustomEndpoint bool
MariaDBCustomEndpoint bool
MongoDBFlexCustomEndpoint bool
ObjectStorageCustomEndpoint bool
ObservabilityCustomEndpoint bool
OpenSearchCustomEndpoint bool
PostgresFlexCustomEndpoint bool
RabbitMQCustomEndpoint bool
RedisCustomEndpoint bool
ResourceManagerCustomEndpoint bool
SecretsManagerCustomEndpoint bool
KMSCustomEndpoint bool
ServerBackupCustomEndpoint bool
ServerOsUpdateCustomEndpoint bool
RunCommandCustomEndpoint bool
ServiceAccountCustomEndpoint bool
ServiceEnablementCustomEndpoint bool
SfsCustomEndpoint bool
SKECustomEndpoint bool
SQLServerFlexCustomEndpoint bool
IaaSCustomEndpoint bool
TokenCustomEndpoint bool
IntakeCustomEndpoint bool
LogsCustomEndpoint bool
CDNCustomEndpoint bool
}
func NewCmd(params *types.CmdParams) *cobra.Command {
cmd := &cobra.Command{
Use: "unset",
Short: "Unsets CLI configuration options",
Long: "Unsets CLI configuration options, undoing past usages of the `stackit config set` command.",
Args: args.NoArgs,
Example: examples.Build(
examples.NewExample(
`Unset the project ID stored in your configuration`,
"$ stackit config unset --project-id"),
examples.NewExample(
`Unset the session time limit stored in your configuration`,
"$ stackit config unset --session-time-limit"),
examples.NewExample(
`Unset the DNS custom endpoint stored in your configuration`,
"$ stackit config unset --dns-custom-endpoint"),
),
RunE: func(cmd *cobra.Command, _ []string) error {
model := parseInput(params.Printer, cmd)
if model.Async {
viper.Set(config.AsyncKey, config.AsyncDefault)
}
if model.OutputFormat {
viper.Set(config.OutputFormatKey, "")
}
if model.ProjectId {
viper.Set(config.ProjectIdKey, "")
}
if model.Region {
viper.Set(config.RegionKey, config.RegionDefault)
}
if model.Verbosity {
viper.Set(config.VerbosityKey, globalflags.VerbosityDefault)
}
if model.AssumeYes {
viper.Set(config.AssumeYesKey, config.AssumeYesDefault)
}
if model.SessionTimeLimit {
viper.Set(config.SessionTimeLimitKey, config.SessionTimeLimitDefault)
}
if model.IdentityProviderCustomEndpoint {
viper.Set(config.IdentityProviderCustomWellKnownConfigurationKey, "")
}
if model.IdentityProviderCustomClientID {
viper.Set(config.IdentityProviderCustomClientIdKey, "")
}
if model.AllowedUrlDomain {
viper.Set(config.AllowedUrlDomainKey, config.AllowedUrlDomainDefault)
}
if model.ObservabilityCustomEndpoint {
viper.Set(config.ObservabilityCustomEndpointKey, "")
}
if model.AuthorizationCustomEndpoint {
viper.Set(config.AuthorizationCustomEndpointKey, "")
}
if model.DNSCustomEndpoint {
viper.Set(config.DNSCustomEndpointKey, "")
}
if model.EdgeCustomEndpoint {
viper.Set(config.EdgeCustomEndpointKey, "")
}
if model.LoadBalancerCustomEndpoint {
viper.Set(config.LoadBalancerCustomEndpointKey, "")
}
if model.LogMeCustomEndpoint {
viper.Set(config.LogMeCustomEndpointKey, "")
}
if model.MariaDBCustomEndpoint {
viper.Set(config.MariaDBCustomEndpointKey, "")
}
if model.MongoDBFlexCustomEndpoint {
viper.Set(config.MongoDBFlexCustomEndpointKey, "")
}
if model.ObjectStorageCustomEndpoint {
viper.Set(config.ObjectStorageCustomEndpointKey, "")
}
if model.OpenSearchCustomEndpoint {
viper.Set(config.OpenSearchCustomEndpointKey, "")
}
if model.PostgresFlexCustomEndpoint {
viper.Set(config.PostgresFlexCustomEndpointKey, "")
}
if model.RabbitMQCustomEndpoint {
viper.Set(config.RabbitMQCustomEndpointKey, "")
}
if model.RedisCustomEndpoint {
viper.Set(config.RedisCustomEndpointKey, "")
}
if model.ResourceManagerCustomEndpoint {
viper.Set(config.ResourceManagerEndpointKey, "")
}
if model.SecretsManagerCustomEndpoint {
viper.Set(config.SecretsManagerCustomEndpointKey, "")
}
if model.KMSCustomEndpoint {
viper.Set(config.KMSCustomEndpointKey, "")
}
if model.ServiceAccountCustomEndpoint {
viper.Set(config.ServiceAccountCustomEndpointKey, "")
}
if model.ServiceEnablementCustomEndpoint {
viper.Set(config.ServiceEnablementCustomEndpointKey, "")
}
if model.ServerBackupCustomEndpoint {
viper.Set(config.ServerBackupCustomEndpointKey, "")
}
if model.ServerOsUpdateCustomEndpoint {
viper.Set(config.ServerOsUpdateCustomEndpointKey, "")
}
if model.RunCommandCustomEndpoint {
viper.Set(config.RunCommandCustomEndpointKey, "")
}
if model.SKECustomEndpoint {
viper.Set(config.SKECustomEndpointKey, "")
}
if model.SQLServerFlexCustomEndpoint {
viper.Set(config.SQLServerFlexCustomEndpointKey, "")
}
if model.IaaSCustomEndpoint {
viper.Set(config.IaaSCustomEndpointKey, "")
}
if model.TokenCustomEndpoint {
viper.Set(config.TokenCustomEndpointKey, "")
}
if model.IntakeCustomEndpoint {
viper.Set(config.IntakeCustomEndpointKey, "")
}
if model.LogsCustomEndpoint {
viper.Set(config.LogsCustomEndpointKey, "")
}
if model.SfsCustomEndpoint {
viper.Set(config.SfsCustomEndpointKey, "")
}
if model.CDNCustomEndpoint {
viper.Set(config.CDNCustomEndpointKey, "")
}
err := config.Write()
if err != nil {
return fmt.Errorf("write config to file: %w", err)
}
return nil
},
}
configureFlags(cmd)
return cmd
}
func configureFlags(cmd *cobra.Command) {
cmd.Flags().Bool(asyncFlag, false, "Configuration option to run commands asynchronously")
cmd.Flags().Bool(projectIdFlag, false, "Project ID")
cmd.Flags().Bool(regionFlag, false, "Region")
cmd.Flags().Bool(outputFormatFlag, false, "Output format")
cmd.Flags().Bool(verbosityFlag, false, "Verbosity of the CLI")
cmd.Flags().Bool(assumeYesFlag, false, "If set, skips all confirmation prompts")
cmd.Flags().Bool(sessionTimeLimitFlag, false, fmt.Sprintf("Maximum time before authentication is required again. If unset, defaults to %s", config.SessionTimeLimitDefault))
cmd.Flags().Bool(identityProviderCustomWellKnownConfigurationFlag, false, "Identity Provider well-known OpenID configuration URL. If unset, uses the default identity provider")
cmd.Flags().Bool(identityProviderCustomClientIdFlag, false, "Identity Provider client ID, used for user authentication")
cmd.Flags().Bool(allowedUrlDomainFlag, false, fmt.Sprintf("Domain name, used for the verification of the URLs that are given in the IDP endpoint and curl commands. If unset, defaults to %s", config.AllowedUrlDomainDefault))
cmd.Flags().Bool(observabilityCustomEndpointFlag, false, "Observability API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(authorizationCustomEndpointFlag, false, "Authorization API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(dnsCustomEndpointFlag, false, "DNS API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(edgeCustomEndpointFlag, false, "Edge API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(loadBalancerCustomEndpointFlag, false, "Load Balancer API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(logMeCustomEndpointFlag, false, "LogMe API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(mariaDBCustomEndpointFlag, false, "MariaDB API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(mongoDBFlexCustomEndpointFlag, false, "MongoDB Flex API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(objectStorageCustomEndpointFlag, false, "Object Storage API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(openSearchCustomEndpointFlag, false, "OpenSearch API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(postgresFlexCustomEndpointFlag, false, "PostgreSQL Flex API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(rabbitMQCustomEndpointFlag, false, "RabbitMQ API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(redisCustomEndpointFlag, false, "Redis API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(resourceManagerCustomEndpointFlag, false, "Resource Manager API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(secretsManagerCustomEndpointFlag, false, "Secrets Manager API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(kmsCustomEndpointFlag, false, "KMS API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(serviceAccountCustomEndpointFlag, false, "Service Account API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(serviceEnablementCustomEndpointFlag, false, "Service Enablement API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(serverBackupCustomEndpointFlag, false, "Server Backup base URL. If unset, uses the default base URL")
cmd.Flags().Bool(serverOsUpdateCustomEndpointFlag, false, "Server Update Management base URL. If unset, uses the default base URL")
cmd.Flags().Bool(runCommandCustomEndpointFlag, false, "Server Command base URL. If unset, uses the default base URL")
cmd.Flags().Bool(skeCustomEndpointFlag, false, "SKE API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(sqlServerFlexCustomEndpointFlag, false, "SQLServer Flex API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(iaasCustomEndpointFlag, false, "IaaS API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(tokenCustomEndpointFlag, false, "Custom token endpoint of the Service Account API, which is used to request access tokens when the service account authentication is activated. Not relevant for user authentication.")
cmd.Flags().Bool(intakeCustomEndpointFlag, false, "Intake API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(logsCustomEndpointFlag, false, "Logs API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(sfsCustomEndpointFlag, false, "SFS API base URL. If unset, uses the default base URL")
cmd.Flags().Bool(cdnCustomEndpointFlag, false, "Custom CDN endpoint URL. If unset, uses the default base URL")
}
func parseInput(p *print.Printer, cmd *cobra.Command) *inputModel {
model := inputModel{
Async: flags.FlagToBoolValue(p, cmd, asyncFlag),
OutputFormat: flags.FlagToBoolValue(p, cmd, outputFormatFlag),
ProjectId: flags.FlagToBoolValue(p, cmd, projectIdFlag),
Region: flags.FlagToBoolValue(p, cmd, regionFlag),
Verbosity: flags.FlagToBoolValue(p, cmd, verbosityFlag),
AssumeYes: flags.FlagToBoolValue(p, cmd, assumeYesFlag),
SessionTimeLimit: flags.FlagToBoolValue(p, cmd, sessionTimeLimitFlag),
IdentityProviderCustomEndpoint: flags.FlagToBoolValue(p, cmd, identityProviderCustomWellKnownConfigurationFlag),
IdentityProviderCustomClientID: flags.FlagToBoolValue(p, cmd, identityProviderCustomClientIdFlag),
AllowedUrlDomain: flags.FlagToBoolValue(p, cmd, allowedUrlDomainFlag),
AuthorizationCustomEndpoint: flags.FlagToBoolValue(p, cmd, authorizationCustomEndpointFlag),
DNSCustomEndpoint: flags.FlagToBoolValue(p, cmd, dnsCustomEndpointFlag),
EdgeCustomEndpoint: flags.FlagToBoolValue(p, cmd, edgeCustomEndpointFlag),
LoadBalancerCustomEndpoint: flags.FlagToBoolValue(p, cmd, loadBalancerCustomEndpointFlag),
LogMeCustomEndpoint: flags.FlagToBoolValue(p, cmd, logMeCustomEndpointFlag),
MariaDBCustomEndpoint: flags.FlagToBoolValue(p, cmd, mariaDBCustomEndpointFlag),
MongoDBFlexCustomEndpoint: flags.FlagToBoolValue(p, cmd, mongoDBFlexCustomEndpointFlag),
ObjectStorageCustomEndpoint: flags.FlagToBoolValue(p, cmd, objectStorageCustomEndpointFlag),
ObservabilityCustomEndpoint: flags.FlagToBoolValue(p, cmd, observabilityCustomEndpointFlag),
OpenSearchCustomEndpoint: flags.FlagToBoolValue(p, cmd, openSearchCustomEndpointFlag),
PostgresFlexCustomEndpoint: flags.FlagToBoolValue(p, cmd, postgresFlexCustomEndpointFlag),
RabbitMQCustomEndpoint: flags.FlagToBoolValue(p, cmd, rabbitMQCustomEndpointFlag),
RedisCustomEndpoint: flags.FlagToBoolValue(p, cmd, redisCustomEndpointFlag),
ResourceManagerCustomEndpoint: flags.FlagToBoolValue(p, cmd, resourceManagerCustomEndpointFlag),
SecretsManagerCustomEndpoint: flags.FlagToBoolValue(p, cmd, secretsManagerCustomEndpointFlag),
KMSCustomEndpoint: flags.FlagToBoolValue(p, cmd, kmsCustomEndpointFlag),
ServiceAccountCustomEndpoint: flags.FlagToBoolValue(p, cmd, serviceAccountCustomEndpointFlag),
ServiceEnablementCustomEndpoint: flags.FlagToBoolValue(p, cmd, serviceEnablementCustomEndpointFlag),
ServerBackupCustomEndpoint: flags.FlagToBoolValue(p, cmd, serverBackupCustomEndpointFlag),
ServerOsUpdateCustomEndpoint: flags.FlagToBoolValue(p, cmd, serverOsUpdateCustomEndpointFlag),
RunCommandCustomEndpoint: flags.FlagToBoolValue(p, cmd, runCommandCustomEndpointFlag),
SKECustomEndpoint: flags.FlagToBoolValue(p, cmd, skeCustomEndpointFlag),
SfsCustomEndpoint: flags.FlagToBoolValue(p, cmd, sfsCustomEndpointFlag),
SQLServerFlexCustomEndpoint: flags.FlagToBoolValue(p, cmd, sqlServerFlexCustomEndpointFlag),
IaaSCustomEndpoint: flags.FlagToBoolValue(p, cmd, iaasCustomEndpointFlag),
TokenCustomEndpoint: flags.FlagToBoolValue(p, cmd, tokenCustomEndpointFlag),
IntakeCustomEndpoint: flags.FlagToBoolValue(p, cmd, intakeCustomEndpointFlag),
LogsCustomEndpoint: flags.FlagToBoolValue(p, cmd, logsCustomEndpointFlag),
CDNCustomEndpoint: flags.FlagToBoolValue(p, cmd, cdnCustomEndpointFlag),
}
p.DebugInputModel(model)
return &model
}