MCPcopy Create free account
hub / github.com/auth0/auth0-cli / validateAndSetBasicFields

Function validateAndSetBasicFields

internal/cli/network_acl.go:106–162  ·  view source on GitHub ↗

validateAndSetBasicFields handles the common validation and patch building logic for basic fields.

(inputs *struct {
	ID           string
	Description  string
	Active       bool
	ActiveStr    string
	Priority     int
	RuleJSON     string
	Action       string
	RedirectURI  string
	Scope        string
	ASNs         []int
	CountryCodes []string
	SubdivCodes  []string
	IPv4CIDRs    []string
	IPv6CIDRs    []string
	JA3          []string
	JA4          []string
	UserAgents   []string
	MatchRule    bool
	NoMatchRule  bool
}, patch *management.NetworkACL, cmd *cobra.Command)

Source from the content-addressed store, hash-verified

104
105// validateAndSetBasicFields handles the common validation and patch building logic for basic fields.
106func validateAndSetBasicFields(inputs *struct {
107 ID string
108 Description string
109 Active bool
110 ActiveStr string
111 Priority int
112 RuleJSON string
113 Action string
114 RedirectURI string
115 Scope string
116 ASNs []int
117 CountryCodes []string
118 SubdivCodes []string
119 IPv4CIDRs []string
120 IPv6CIDRs []string
121 JA3 []string
122 JA4 []string
123 UserAgents []string
124 MatchRule bool
125 NoMatchRule bool
126}, patch *management.NetworkACL, cmd *cobra.Command) error {
127 if cmd.Flags().Changed("description") {
128 if len(inputs.Description) > 255 {
129 return fmt.Errorf("description cannot exceed 255 characters")
130 }
131 if len(inputs.Description) == 0 {
132 return fmt.Errorf("description cannot be empty")
133 }
134 patch.Description = &inputs.Description
135 }
136
137 if cmd.Flags().Changed("active") {
138 switch inputs.ActiveStr {
139 case "true":
140 inputs.Active = true
141 case "false":
142 inputs.Active = false
143 default:
144 return fmt.Errorf("--active must be either 'true' or 'false', got %q", inputs.ActiveStr)
145 }
146 patch.Active = &inputs.Active
147 }
148
149 if cmd.Flags().Changed("priority") {
150 patch.Priority = &inputs.Priority
151 }
152
153 if cmd.Flags().Changed("rule") {
154 var rule management.NetworkACLRule
155 if err := json.Unmarshal([]byte(inputs.RuleJSON), &rule); err != nil {
156 return fmt.Errorf("invalid rule JSON: %w", err)
157 }
158 patch.Rule = &rule
159 }
160
161 return nil
162}
163

Callers 1

updateNetworkACLCmdFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by

no test coverage detected