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

Function extractCurrentRuleDefaults

internal/cli/network_acl.go:230–301  ·  view source on GitHub ↗

extractCurrentRuleDefaults extracts default values from current ACL rule for interactive prompts.

(currentACL *management.NetworkACL)

Source from the content-addressed store, hash-verified

228
229// extractCurrentRuleDefaults extracts default values from current ACL rule for interactive prompts.
230func extractCurrentRuleDefaults(currentACL *management.NetworkACL) *ruleDefaults {
231 defaults := &ruleDefaults{}
232
233 if currentACL == nil || currentACL.Rule == nil {
234 defaults.Scope = "tenant"
235 defaults.Action = "block"
236 return defaults
237 }
238
239 // Extract scope.
240 if currentACL.Rule.Scope != nil {
241 defaults.Scope = *currentACL.Rule.Scope
242 }
243
244 // Extract action.
245 if currentACL.Rule.Action != nil {
246 switch {
247 case currentACL.Rule.Action.Block != nil && *currentACL.Rule.Action.Block:
248 defaults.Action = "block"
249 case currentACL.Rule.Action.Allow != nil && *currentACL.Rule.Action.Allow:
250 defaults.Action = "allow"
251 case currentACL.Rule.Action.Log != nil && *currentACL.Rule.Action.Log:
252 defaults.Action = "log"
253 case currentACL.Rule.Action.Redirect != nil && *currentACL.Rule.Action.Redirect:
254 defaults.Action = "redirect"
255 if currentACL.Rule.Action.RedirectURI != nil {
256 defaults.RedirectURI = *currentACL.Rule.Action.RedirectURI
257 }
258 }
259 }
260
261 // Extract match criteria from either Match or NotMatch.
262 var match *management.NetworkACLRuleMatch
263 if currentACL.Rule.Match != nil {
264 match = currentACL.Rule.Match
265 defaults.IsMatchRule = true
266 defaults.HasMatchRule = true
267 } else if currentACL.Rule.NotMatch != nil {
268 match = currentACL.Rule.NotMatch
269 defaults.IsMatchRule = false
270 defaults.HasNotMatch = true
271 }
272
273 if match != nil {
274 if len(match.Asns) > 0 {
275 defaults.ASNs = match.Asns
276 }
277 if match.GeoCountryCodes != nil {
278 defaults.CountryCodes = *match.GeoCountryCodes
279 }
280 if match.GeoSubdivisionCodes != nil {
281 defaults.SubdivCodes = *match.GeoSubdivisionCodes
282 }
283 if match.IPv4Cidrs != nil {
284 defaults.IPv4CIDRs = *match.IPv4Cidrs
285 }
286 if match.IPv6Cidrs != nil {
287 defaults.IPv6CIDRs = *match.IPv6Cidrs

Callers 1

updateNetworkACLCmdFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected