Skip to content

Commit 5dd3d1f

Browse files
author
Gustavo Bazan
authored
chore: make opts a receiver for validation functions (#3570)
1 parent f574544 commit 5dd3d1f

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

internal/cli/alerts/acknowledge.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
2828
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
2929
"github.com/spf13/cobra"
30-
"go.mongodb.org/atlas-sdk/v20241113004/admin"
30+
atlasv2 "go.mongodb.org/atlas-sdk/v20241113004/admin"
3131
)
3232

3333
type AcknowledgeOpts struct {
@@ -56,7 +56,7 @@ func (opts *AcknowledgeOpts) Run() error {
5656
if err != nil {
5757
return err
5858
}
59-
params := &admin.AcknowledgeAlertApiParams{
59+
params := &atlasv2.AcknowledgeAlertApiParams{
6060
GroupId: opts.ConfigProjectID(),
6161
AlertId: opts.alertID,
6262
AcknowledgeAlert: body,
@@ -70,7 +70,7 @@ func (opts *AcknowledgeOpts) Run() error {
7070
return opts.Print(r)
7171
}
7272

73-
func (opts *AcknowledgeOpts) newAcknowledgeRequest() (*admin.AcknowledgeAlert, error) {
73+
func (opts *AcknowledgeOpts) newAcknowledgeRequest() (*atlasv2.AcknowledgeAlert, error) {
7474
if opts.forever {
7575
// To acknowledge an alert “forever”, set the field value to 100 years in the future.
7676
const years = 100
@@ -80,7 +80,7 @@ func (opts *AcknowledgeOpts) newAcknowledgeRequest() (*admin.AcknowledgeAlert, e
8080
if err != nil {
8181
return nil, err
8282
}
83-
return &admin.AcknowledgeAlert{
83+
return &atlasv2.AcknowledgeAlert{
8484
AcknowledgedUntil: &until,
8585
AcknowledgementComment: &opts.comment,
8686
}, nil

internal/cli/alerts/settings/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func CreateBuilder() *cobra.Command {
100100
opts.ValidateProjectID,
101101
func() error {
102102
if opts.filename == "" {
103-
return validateConfigOpts(&opts.ConfigOpts)
103+
return opts.ConfigOpts.validateConfigOpts()
104104
}
105105
return nil
106106
},

internal/cli/alerts/settings/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func UpdateBuilder() *cobra.Command {
9999
opts.ValidateProjectID,
100100
func() error {
101101
if opts.filename == "" {
102-
return validateConfigOpts(&opts.ConfigOpts)
102+
return opts.ConfigOpts.validateConfigOpts()
103103
}
104104
return nil
105105
},

internal/cli/alerts/settings/validator.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
2121
)
2222

23-
func validateConfigOpts(opts *ConfigOpts) error {
23+
func (opts *ConfigOpts) validateConfigOpts() error {
2424
if opts.event == "" {
2525
return fmt.Errorf("--%s flag is required", flag.Event)
2626
}
@@ -31,94 +31,94 @@ func validateConfigOpts(opts *ConfigOpts) error {
3131
return fmt.Errorf("--%s is required", flag.NotificationType)
3232
}
3333

34-
return validateAlertSettingsTypes(opts)
34+
return opts.validateAlertSettingsTypes()
3535
}
3636

37-
func validateAlertSettingsTypes(opts *ConfigOpts) error {
37+
func (opts *ConfigOpts) validateAlertSettingsTypes() error {
3838
switch opts.notificationType {
3939
case datadog:
40-
return validateDatadog(opts)
40+
return opts.validateDatadog()
4141
case email:
42-
return validateEmail(opts)
42+
return opts.validateEmail()
4343
case microsoftTeams:
44-
return validateMicrosoftTeams(opts)
44+
return opts.validateMicrosoftTeams()
4545
case opsGenie:
46-
return validateOpsGenie(opts)
46+
return opts.validateOpsGenie()
4747
case pagerDuty:
48-
return validatePagerDuty(opts)
48+
return opts.validatePagerDuty()
4949
case slack:
50-
return validateSlack(opts)
50+
return opts.validateSlack()
5151
case sms:
52-
return validateSMS(opts)
52+
return opts.validateSMS()
5353
case team:
54-
return validateTeams(opts)
54+
return opts.validateTeams()
5555
case user:
56-
return validateUser(opts)
56+
return opts.validateUser()
5757
case victor:
5858
return validateVictor(opts)
5959
case webhook:
60-
return validateWebhook(opts)
60+
return opts.validateWebhook()
6161
}
6262
return nil
6363
}
6464

65-
func validateDatadog(opts *ConfigOpts) error {
65+
func (opts *ConfigOpts) validateDatadog() error {
6666
if opts.apiKey == "" || opts.notificationRegion == "" {
6767
return fmt.Errorf("--%s and --%s are required when --%s is DATADOG", flag.APIKey, flag.NotificationRegion, flag.NotificationType)
6868
}
6969
return nil
7070
}
7171

72-
func validateEmail(opts *ConfigOpts) error {
72+
func (opts *ConfigOpts) validateEmail() error {
7373
if opts.notificationEmailAddress == "" {
7474
return fmt.Errorf("--%s is required when --%s is EMAIL", flag.NotificationEmailAddress, flag.NotificationType)
7575
}
7676
return nil
7777
}
7878

79-
func validateMicrosoftTeams(opts *ConfigOpts) error {
79+
func (opts *ConfigOpts) validateMicrosoftTeams() error {
8080
if opts.notificationWebhookURL == "" {
8181
return fmt.Errorf("--%s is required when --%s is MICROSOFT_TEAMS", flag.NotificationWebhookURL, flag.NotificationType)
8282
}
8383
return nil
8484
}
8585

86-
func validateOpsGenie(opts *ConfigOpts) error {
86+
func (opts *ConfigOpts) validateOpsGenie() error {
8787
if opts.apiKey == "" || opts.notificationRegion == "" {
8888
return fmt.Errorf("--%s and --%s are required when --%s is OPS_GENIE", flag.APIKey, flag.NotificationRegion, flag.NotificationType)
8989
}
9090
return nil
9191
}
9292

93-
func validatePagerDuty(opts *ConfigOpts) error {
93+
func (opts *ConfigOpts) validatePagerDuty() error {
9494
if opts.notificationServiceKey == "" || opts.notificationRegion == "" {
9595
return fmt.Errorf("--%s and --%s are required when --%s is PAGER_DUTY", flag.NotificationServiceKey, flag.NotificationRegion, flag.NotificationType)
9696
}
9797
return nil
9898
}
9999

100-
func validateSlack(opts *ConfigOpts) error {
100+
func (opts *ConfigOpts) validateSlack() error {
101101
if opts.notificationToken == "" || opts.notificationChannelName == "" {
102102
return fmt.Errorf("--%s and --%s are required when --%s is SLACK", flag.NotificationToken, flag.NotificationChannelName, flag.NotificationType)
103103
}
104104
return nil
105105
}
106106

107-
func validateSMS(opts *ConfigOpts) error {
107+
func (opts *ConfigOpts) validateSMS() error {
108108
if opts.notificationMobileNumber == "" {
109109
return fmt.Errorf("--%s is required when --%s is SMS", flag.NotificationMobileNumber, flag.NotificationType)
110110
}
111111
return nil
112112
}
113113

114-
func validateTeams(opts *ConfigOpts) error {
114+
func (opts *ConfigOpts) validateTeams() error {
115115
if opts.notificationTeamID == "" {
116116
return fmt.Errorf("--%s is required when --%s is TEAM", flag.NotificationTeamID, flag.NotificationType)
117117
}
118118
return nil
119119
}
120120

121-
func validateUser(opts *ConfigOpts) error {
121+
func (opts *ConfigOpts) validateUser() error {
122122
if opts.notificationUsername == "" {
123123
return fmt.Errorf("--%s is required when --%s is USER", flag.NotificationUsername, flag.NotificationType)
124124
}
@@ -132,7 +132,7 @@ func validateVictor(opts *ConfigOpts) error {
132132
return nil
133133
}
134134

135-
func validateWebhook(opts *ConfigOpts) error {
135+
func (opts *ConfigOpts) validateWebhook() error {
136136
if opts.notificationWebhookURL == "" {
137137
return fmt.Errorf("--%s is required when --%s is WEBHOOK", flag.NotificationWebhookURL, flag.NotificationType)
138138
}

0 commit comments

Comments
 (0)