Skip to content

Commit

Permalink
fix: Added feature Flag License Error check
Browse files Browse the repository at this point in the history
  • Loading branch information
willguibr committed Aug 24, 2023
1 parent cf9d5d1 commit ec06f64
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion internal/app/zscaler-terraformer/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ var importCommand = &cobra.Command{
PreRun: sharedPreRun,
}

type APIError struct {
Params []string `json:"params"`
ID string `json:"id"`
Reason string `json:"reason"`
}

// Check if the error is due to license issue
func isLicenseError(err error) (bool, string) {
const licenseErrorMsg = "authz.featureflag.permission.denied"
if strings.Contains(err.Error(), licenseErrorMsg) {
apiErr := &APIError{}
json.Unmarshal([]byte(err.Error()), apiErr)

Check failure on line 91 in internal/app/zscaler-terraformer/cmd/import.go

View workflow job for this annotation

GitHub Actions / golangci-lint

[golangci-lint] internal/app/zscaler-terraformer/cmd/import.go#L91

Error return value of `json.Unmarshal` is not checked (errcheck)
Raw output
internal/app/zscaler-terraformer/cmd/import.go:91:17: Error return value of `json.Unmarshal` is not checked (errcheck)
		json.Unmarshal([]byte(err.Error()), apiErr)
		              ^
return true, apiErr.Reason
}
return false, ""
}

func runImport() func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
if resources != "" {
Expand Down Expand Up @@ -122,7 +139,13 @@ func importResource(cmd *cobra.Command, writer io.Writer, resourceType string) {
case "zpa_app_connector_group":
list, _, err := api.zpa.appconnectorgroup.GetAll()
if err != nil {
log.Fatal(err)
isLicErr, reason := isLicenseError(err)
// If it's a license error, log and continue, otherwise, terminate.
if isLicErr {
log.Printf("[WARNING] License error encountered: %s. Continuing with the import.", reason)
} else {
log.Fatal(err)
}
}
jsonPayload := []appconnectorgroup.AppConnectorGroup{}
for _, i := range list {
Expand Down

0 comments on commit ec06f64

Please sign in to comment.