diff --git a/cmd/instances/crtinstance.go b/cmd/instances/crtinstance.go index 496e8d9bf..94e267623 100644 --- a/cmd/instances/crtinstance.go +++ b/cmd/instances/crtinstance.go @@ -35,11 +35,11 @@ var CreateCmd = &cobra.Command{ return apiclient.SetApigeeOrg(org) }, RunE: func(cmd *cobra.Command, args []string) (err error) { - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) if billingType, err = orgs.GetOrgField("billingType"); err != nil { return err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if billingType != "EVALUATION" { re := regexp.MustCompile(`projects\/([a-zA-Z0-9_-]+)\/locations` + diff --git a/internal/apiclient/bundles.go b/internal/apiclient/bundles.go index 691c71f71..fe16b6892 100644 --- a/internal/apiclient/bundles.go +++ b/internal/apiclient/bundles.go @@ -169,8 +169,8 @@ func GetAsyncEntity(entityURL string, wg *sync.WaitGroup, mu *sync.Mutex) { var respBody []byte // don't print to sysout - SetClientPrintHttpResponse(false) - defer SetClientPrintHttpResponse(GetCmdPrintHttpResponseSetting()) + ClientPrintHttpResponse.Set(false) + defer ClientPrintHttpResponse.Set(GetCmdPrintHttpResponseSetting()) respBody, err := HttpClient(entityURL) if err != nil { clilog.Error.Fatalf("error with entity: %s", entityURL) diff --git a/internal/apiclient/httpclient.go b/internal/apiclient/httpclient.go index 7638be980..5b0f9e3d7 100644 --- a/internal/apiclient/httpclient.go +++ b/internal/apiclient/httpclient.go @@ -324,7 +324,7 @@ func HttpClient(params ...string) (respBody []byte, err error) { // PrettyPrint method prints formatted json func PrettyPrint(body []byte) error { - if GetCmdPrintHttpResponseSetting() && GetClientPrintHttpResponseSetting() { + if GetCmdPrintHttpResponseSetting() && ClientPrintHttpResponse.Get() { var prettyJSON bytes.Buffer err := json.Indent(&prettyJSON, body, "", "\t") if err != nil { diff --git a/internal/apiclient/iam.go b/internal/apiclient/iam.go index a2e9df206..5572637b8 100644 --- a/internal/apiclient/iam.go +++ b/internal/apiclient/iam.go @@ -112,8 +112,8 @@ func CreateIAMServiceAccount(name string, iamRole string) (err error) { return fmt.Errorf("invalid service account role") } - SetClientPrintHttpResponse(false) - defer SetClientPrintHttpResponse(GetCmdPrintHttpResponseSetting()) + ClientPrintHttpResponse.Set(false) + defer ClientPrintHttpResponse.Set(GetCmdPrintHttpResponseSetting()) // Step 1: create a new service account u, _ := url.Parse(iamURL) @@ -258,8 +258,8 @@ func SetIAMPermission(memberName string, iamRole string, memberType string) (err role = iamRole } - SetClientPrintHttpResponse(false) - defer SetClientPrintHttpResponse(GetCmdPrintHttpResponseSetting()) + ClientPrintHttpResponse.Set(false) + defer ClientPrintHttpResponse.Set(GetCmdPrintHttpResponseSetting()) u, _ := url.Parse(BaseURL) u.Path = path.Join(u.Path, GetApigeeOrg(), "environments", GetApigeeEnv()+":getIamPolicy") @@ -313,8 +313,8 @@ func SetIAMPermission(memberName string, iamRole string, memberType string) (err // RemoveIAMPermission removes/unbinds IAM permission from all roles for an Apigee Env func RemoveIAMPermission(memberName string, iamRole string) (err error) { - SetClientPrintHttpResponse(false) - defer SetClientPrintHttpResponse(GetCmdPrintHttpResponseSetting()) + ClientPrintHttpResponse.Set(false) + defer ClientPrintHttpResponse.Set(GetCmdPrintHttpResponseSetting()) u, _ := url.Parse(BaseURL) u.Path = path.Join(u.Path, GetApigeeOrg(), "environments", GetApigeeEnv()+":getIamPolicy") @@ -449,8 +449,8 @@ func AddWid(projectID string, namespace string, kServiceAccount string, gService u, _ := url.Parse(crmBetaURL) u.Path = path.Join(u.Path, GetProjectID()+":setIamPolicy") - SetClientPrintHttpResponse(false) - defer SetClientPrintHttpResponse(GetCmdPrintHttpResponseSetting()) + ClientPrintHttpResponse.Set(false) + defer ClientPrintHttpResponse.Set(GetCmdPrintHttpResponseSetting()) _, err = HttpClient(u.String(), string(setIamPolicyBody)) return err diff --git a/internal/apiclient/options.go b/internal/apiclient/options.go index a95e8cefa..c2aa21ca3 100644 --- a/internal/apiclient/options.go +++ b/internal/apiclient/options.go @@ -17,6 +17,7 @@ package apiclient import ( "fmt" "os" + "sync" "internal/clilog" ) @@ -55,10 +56,14 @@ const ( var apiRate Rate -var ( - cmdPrintHttpResponses = true - clientPrintHttpResponses = true -) +var cmdPrintHttpResponses = true + +type clientPrintHttpResponse struct { + enable bool + sync.Mutex +} + +var ClientPrintHttpResponse = &clientPrintHttpResponse{enable: true} // NewApigeeClient sets up options to invoke Apigee APIs func NewApigeeClient(o ApigeeClientOptions) { @@ -204,13 +209,17 @@ func GetCmdPrintHttpResponseSetting() bool { } // SetClientPrintHttpResponse -func SetClientPrintHttpResponse(b bool) { - clientPrintHttpResponses = b +func (c *clientPrintHttpResponse) Set(b bool) { + c.Lock() + defer c.Unlock() + c.enable = b } // GetPrintHttpResponseSetting -func GetClientPrintHttpResponseSetting() bool { - return clientPrintHttpResponses +func (c *clientPrintHttpResponse) Get() bool { + c.Lock() + defer c.Unlock() + return c.enable } // GetProxyURL diff --git a/internal/client/apis/apis.go b/internal/client/apis/apis.go index 86452ebdd..2e3c7adce 100644 --- a/internal/client/apis/apis.go +++ b/internal/client/apis/apis.go @@ -116,11 +116,11 @@ func DeployProxy(name string, revision int, overrides bool, sequencedRollout boo if safeDeploy { var safeResp []byte d := deploychangereport{} - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) if safeResp, err = GenerateDeployChangeReport(name, revision, overrides); err != nil { return nil, err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if err = json.Unmarshal(safeResp, &d); err != nil { return nil, err } @@ -170,8 +170,8 @@ func GetProxy(name string, revision int) (respBody []byte, err error) { // GetHighestProxyRevision func GetHighestProxyRevision(name string) (version int, err error) { - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis", name) @@ -273,11 +273,11 @@ func ListProxyRevisionDeployments(name string, revision int) (respBody []byte, e func UndeployProxy(name string, revision int, safeUndeploy bool) (respBody []byte, err error) { if safeUndeploy { var safeResp []byte - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) if safeResp, err = GenerateUndeployChangeReport(name, revision); err != nil { return nil, err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) d := deploychangereport{} if err = json.Unmarshal(safeResp, &d); err != nil { return nil, err @@ -350,8 +350,8 @@ func CleanProxy(name string, reportOnly bool, keepList []string) (err error) { var revision int // disable printing - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) // step 1. get a list of revisions that are deployed. if proxyDeploymentsBytes, err = ListProxyDeployments(name); err != nil { @@ -424,8 +424,8 @@ func ExportProxies(conn int, folder string, allRevisions bool) (err error) { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apis") // don't print to sysout - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) respBody, err := apiclient.HttpClient(u.String()) if err != nil { diff --git a/internal/client/apps/apps.go b/internal/client/apps/apps.go index 65e6c90d5..4fb0177fb 100644 --- a/internal/client/apps/apps.go +++ b/internal/client/apps/apps.go @@ -152,8 +152,8 @@ func Manage(appID string, developerEmail string, action string) (respBody []byte // SearchApp func SearchApp(name string) (respBody []byte, err error) { - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) u, _ := url.Parse(apiclient.BaseURL) // search by name is not implemented; use list and return the appropriate app @@ -239,8 +239,8 @@ func GenerateKey(name string, developerID string, apiProducts []string, callback // Export func Export(conn int) (payload [][]byte, err error) { - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) // parent workgroup var pwg sync.WaitGroup @@ -445,9 +445,9 @@ func createAsyncApp(app application, developerEntities developers.Appdevelopers, newAppCredentials := newDeveloperApp["credentials"].([]interface{}) temporaryCredential := newAppCredentials[0].(map[string]interface{}) - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) _, err = DeleteKey(developerEmail, newDeveloperApp["name"].(string), temporaryCredential["consumerKey"].(string)) - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if err != nil { clilog.Error.Println(err) return diff --git a/internal/client/apps/keys.go b/internal/client/apps/keys.go index 9d41838ff..27f211071 100644 --- a/internal/client/apps/keys.go +++ b/internal/client/apps/keys.go @@ -48,7 +48,7 @@ func CreateKey(developerEmail string, appID string, consumerKey string, consumer u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", developerEmail, "apps", appID, "keys") if len(apiProducts) > 0 { - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) } respBody, err = apiclient.HttpClient(u.String(), payload) @@ -58,9 +58,9 @@ func CreateKey(developerEmail string, appID string, consumerKey string, consumer // since the API does not support adding products when creating a key, use a second API call to add products if len(apiProducts) > 0 { - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) respBody, err = UpdateKeyProducts(developerEmail, appID, consumerKey, apiProducts) - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) } return respBody, err diff --git a/internal/client/developers/developers.go b/internal/client/developers/developers.go index 0c7a167ca..c103d6d72 100644 --- a/internal/client/developers/developers.go +++ b/internal/client/developers/developers.go @@ -95,8 +95,8 @@ func Get(email string) (respBody []byte, err error) { // GetDeveloperId func GetDeveloperId(email string) (developerId string, err error) { - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) var developerMap map[string]interface{} u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email)) // since developer emails can have + @@ -159,8 +159,8 @@ func Export() (respBody []byte, err error) { u.RawQuery = q.Encode() // don't print to sysout - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) respBody, err = apiclient.HttpClient(u.String()) return respBody, err } diff --git a/internal/client/developers/subscriptions.go b/internal/client/developers/subscriptions.go index 23027b49b..7c2c0eb7a 100644 --- a/internal/client/developers/subscriptions.go +++ b/internal/client/developers/subscriptions.go @@ -68,8 +68,8 @@ func ExportSubscriptions(email string) (respBody []byte, err error) { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "developers", url.QueryEscape(email), "subscriptions") // don't print to sysout - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) respBody, err = apiclient.HttpClient(u.String()) return respBody, err } diff --git a/internal/client/env/archives.go b/internal/client/env/archives.go index a125b6b5a..f0e5043fc 100644 --- a/internal/client/env/archives.go +++ b/internal/client/env/archives.go @@ -26,8 +26,8 @@ import ( // generateUploadURL func generateUploadURL() (respBody []byte, err error) { - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "archiveDeployments:generateUploadUrl") respBody, err = apiclient.HttpClient(u.String(), "") diff --git a/internal/client/env/env.go b/internal/client/env/env.go index dbdcc20b1..741862e55 100644 --- a/internal/client/env/env.go +++ b/internal/client/env/env.go @@ -94,7 +94,7 @@ func GetDeployments(sharedflows bool) (respBody []byte, err error) { } func GetAllDeployments() (respBody []byte, err error) { - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) proxiesResponse, err := GetDeployments(false) if err != nil { return nil, err @@ -111,7 +111,7 @@ func GetAllDeployments() (respBody []byte, err error) { deployments = append(deployments, "\"sharedFlows\":"+string(sharedFlowsResponse)) payload := "{" + strings.Join(deployments, ",") + "}" - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) err = apiclient.PrettyPrint([]byte(payload)) return []byte(payload), err } @@ -148,9 +148,9 @@ func SetEnvProperty(name string, value string) (err error) { u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv()) // get env details - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) envBody, err := apiclient.HttpClient(u.String()) - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if err != nil { return err } @@ -217,9 +217,9 @@ func ClearEnvProperties() (err error) { u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv()) // get env details - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) envBody, err := apiclient.HttpClient(u.String()) - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if err != nil { return err } diff --git a/internal/client/env/traceconfig.go b/internal/client/env/traceconfig.go index 439b86b2e..6d257b82b 100644 --- a/internal/client/env/traceconfig.go +++ b/internal/client/env/traceconfig.go @@ -80,11 +80,11 @@ func DisableTraceConfig() (respBody []byte, err error) { var traceRespBody []byte var payload []byte - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) if traceRespBody, err = GetTraceConfig(); err != nil { return nil, err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) traceResp := traceCfg{} if err = json.Unmarshal(traceRespBody, &traceResp); err != nil { diff --git a/internal/client/envgroups/envgroups.go b/internal/client/envgroups/envgroups.go index 9a06e4208..d49addda5 100644 --- a/internal/client/envgroups/envgroups.go +++ b/internal/client/envgroups/envgroups.go @@ -119,11 +119,11 @@ func DetachEnvironment(name string, environment string) (respBody []byte, err er envGroupAttachments := attachments{} - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) if respBody, err = ListAttach(name); err != nil { return nil, err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if err := json.Unmarshal(respBody, &envGroupAttachments); err != nil { return nil, err diff --git a/internal/client/instances/attachments.go b/internal/client/instances/attachments.go index d4672a773..f5001f79a 100644 --- a/internal/client/instances/attachments.go +++ b/internal/client/instances/attachments.go @@ -110,12 +110,12 @@ func getAttachmentName(instance string) (attachmentName string, err error) { instAttach := instanceAttachments{} - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) listAttachments, err := ListAttach(instance) if err != nil { return "", err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) err = json.Unmarshal(listAttachments, &instAttach) if err != nil { diff --git a/internal/client/kvm/entries.go b/internal/client/kvm/entries.go index 99a60643a..e14ccd3c4 100644 --- a/internal/client/kvm/entries.go +++ b/internal/client/kvm/entries.go @@ -112,8 +112,8 @@ func ExportEntries(proxyName string, mapName string) (payload [][]byte, err erro var respBody []byte count := 1 - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if respBody, err = ListEntries(proxyName, mapName, -1, ""); err != nil { return nil, err diff --git a/internal/client/operations/operations.go b/internal/client/operations/operations.go index 79b5d1830..bff691f42 100644 --- a/internal/client/operations/operations.go +++ b/internal/client/operations/operations.go @@ -72,11 +72,11 @@ func List(state string, completeState OperationCompleteState) (respBody []byte, u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "operations") if state != "" { - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) if respBody, err = apiclient.HttpClient(u.String()); err != nil { return nil, err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) return filterOperation(respBody, state, completeState) } diff --git a/internal/client/orgs/orgs.go b/internal/client/orgs/orgs.go index 2015d1625..11a6e2770 100644 --- a/internal/client/orgs/orgs.go +++ b/internal/client/orgs/orgs.go @@ -190,9 +190,9 @@ func SetOrgProperty(name string, value string) (err error) { u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()) // get org details - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) orgBody, err := apiclient.HttpClient(u.String()) - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if err != nil { return err } @@ -237,12 +237,12 @@ func SetOrgProperty(name string, value string) (err error) { // Update func Update(description string, displayName string, region string, network string, runtimeType string, databaseKey string) (respBody []byte, err error) { - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) orgBody, err := Get() if err != nil { return nil, err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) org := organization{} err = json.Unmarshal(orgBody, &org) @@ -288,7 +288,7 @@ func Update(description string, displayName string, region string, network strin // SetAddons func SetAddons(advancedApiOpsConfig bool, integrationConfig bool, monetizationConfig bool, connectorsConfig bool, apiSecurityConfig bool) (respBody []byte, err error) { - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) orgRespBody, err := Get() if err != nil { @@ -302,7 +302,7 @@ func SetAddons(advancedApiOpsConfig bool, integrationConfig bool, monetizationCo return nil, err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) addonPayload := []string{} diff --git a/internal/client/orgs/reports.go b/internal/client/orgs/reports.go index 14d63ce3a..cf197e19e 100644 --- a/internal/client/orgs/reports.go +++ b/internal/client/orgs/reports.go @@ -35,8 +35,8 @@ func TotalAPICallsInMonth(month int, year int, envDetails bool, conn int) (total // ensure the count is reset to zero before calculating the next set defer env.ApiCalls.ResetCount() - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if envListBytes, err = env.List(); err != nil { return -1, err diff --git a/internal/client/products/products.go b/internal/client/products/products.go index d2e4eed9a..3d96e9008 100644 --- a/internal/client/products/products.go +++ b/internal/client/products/products.go @@ -153,12 +153,12 @@ func upsert(p APIProduct, a Action) (respBody []byte, err error) { case UPDATE: createNew = false case UPSERT: - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) _, err = Get(p.Name) if err != nil { createNew = true // product does not exist } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) } payload, err := json.Marshal(p) @@ -243,7 +243,7 @@ func ListFilter(filter map[string]string) (respBody []byte, err error) { allprds := apiProducts{} outprds := apiProducts{} - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) for nextPage { pageResp, err := List(maxProducts, startKey, true) @@ -297,7 +297,7 @@ func ListFilter(filter map[string]string) (respBody []byte, err error) { } respBody, err = json.Marshal(outprds) - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) _ = apiclient.PrettyPrint(respBody) return respBody, err @@ -313,9 +313,9 @@ func Export(conn int) (payload [][]byte, err error) { u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), entityType) // don't print to sysout - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) respBody, err := apiclient.HttpClient(u.String()) - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if err != nil { return apiclient.GetEntityPayloadList(), err } diff --git a/internal/client/products/rateplans.go b/internal/client/products/rateplans.go index 859bbc980..fdb0139d0 100644 --- a/internal/client/products/rateplans.go +++ b/internal/client/products/rateplans.go @@ -59,8 +59,8 @@ func ExportRateplan(productName string) (respBody []byte, err error) { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "apiproducts", productName, "rateplans") // don't print to sysout - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) respBody, err = apiclient.HttpClient(u.String()) return respBody, err } diff --git a/internal/client/references/references.go b/internal/client/references/references.go index 2ab9f7e23..2654017e2 100644 --- a/internal/client/references/references.go +++ b/internal/client/references/references.go @@ -114,8 +114,8 @@ func Update(name string, description string, resourceType string, refers string) // Export func Export(conn int) (payload [][]byte, err error) { // don't print to sysout - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) respBody, err := List() if err != nil { return nil, err @@ -185,8 +185,8 @@ func Export(conn int) (payload [][]byte, err error) { func exportReferences(wg *sync.WaitGroup, jobs <-chan string, results chan<- []byte, errs chan<- error) { defer wg.Done() - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) - apiclient.SetClientPrintHttpResponse(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) for { job, ok := <-jobs if !ok { diff --git a/internal/client/sharedflows/sharedflows.go b/internal/client/sharedflows/sharedflows.go index bab4fa417..fe097f1a1 100644 --- a/internal/client/sharedflows/sharedflows.go +++ b/internal/client/sharedflows/sharedflows.go @@ -76,11 +76,11 @@ func Get(name string, revision int) (respBody []byte, err error) { // GetHighestSfRevision func GetHighestSfRevision(name string) (version int, err error) { - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sharedflows", name) respBody, err := apiclient.HttpClient(u.String()) - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if err != nil { return -1, err } @@ -213,7 +213,7 @@ func Clean(name string, reportOnly bool) (err error) { var revision int // disable printing - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) // step 1. get a list of revisions that are deployed. if sfDeploymentsBytes, err = ListDeployments(name); err != nil { @@ -246,7 +246,7 @@ func Clean(name string, reportOnly bool) (err error) { } // enable printing - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) for _, sfRevision := range sfRevisions.Revision { if !isRevisionDeployed(deployedRevisions, sfRevision) { @@ -297,9 +297,9 @@ func Export(conn int, folder string, allRevisions bool) (err error) { u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "sharedflows") // don't print to sysout - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) respBody, err := apiclient.HttpClient(u.String()) - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) if err != nil { return err } diff --git a/internal/client/sync/sync.go b/internal/client/sync/sync.go index e7592c7d0..ea063bd10 100644 --- a/internal/client/sync/sync.go +++ b/internal/client/sync/sync.go @@ -61,7 +61,7 @@ func Reset() (respBody []byte, err error) { func Set(identity interface{}) (respBody []byte, err error) { u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":getSyncAuthorization") - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) respBody, err = apiclient.HttpClient(u.String(), "") if err != nil { return respBody, err @@ -99,7 +99,7 @@ func Set(identity interface{}) (respBody []byte, err error) { return respBody, err } - apiclient.SetClientPrintHttpResponse(apiclient.GetClientPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) u, _ = url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":setSyncAuthorization") respBody, err = apiclient.HttpClient(u.String(), string(payload)) @@ -111,7 +111,7 @@ func Set(identity interface{}) (respBody []byte, err error) { func SetList(identities []string) (respBody []byte, err error) { u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":getSyncAuthorization") - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) respBody, err = apiclient.HttpClient(u.String(), "") if err != nil { return respBody, err @@ -136,7 +136,7 @@ func SetList(identities []string) (respBody []byte, err error) { return respBody, err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) u, _ = url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":setSyncAuthorization") respBody, err = apiclient.HttpClient(u.String(), string(payload)) @@ -148,7 +148,7 @@ func SetList(identities []string) (respBody []byte, err error) { func Remove(identity string) (respBody []byte, err error) { u, _ := url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":getSyncAuthorization") - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) respBody, err = apiclient.HttpClient(u.String(), "") if err != nil { return respBody, err @@ -188,7 +188,7 @@ func Remove(identity string) (respBody []byte, err error) { return respBody, err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) u, _ = url.Parse(apiclient.BaseURL) u.Path = path.Join(u.Path, apiclient.GetApigeeOrg()+":setSyncAuthorization") respBody, err = apiclient.HttpClient(u.String(), string(payload)) diff --git a/internal/client/targetservers/targetservers.go b/internal/client/targetservers/targetservers.go index 4d112de4f..66a1a6b91 100644 --- a/internal/client/targetservers/targetservers.go +++ b/internal/client/targetservers/targetservers.go @@ -70,12 +70,12 @@ func Create(name string, description string, host string, port int, enable bool, // Update func Update(name string, description string, host string, port int, enable bool, grpc bool, keyStore string, keyAlias string, trustStore string, sslinfo string, tlsenabled bool, clientAuthEnabled bool, ignoreValidationErrors bool) (respBody []byte, err error) { - apiclient.SetClientPrintHttpResponse(false) + apiclient.ClientPrintHttpResponse.Set(false) targetRespBody, err := Get(name) if err != nil { return nil, err } - apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) targetsvr := targetserver{} if err = json.Unmarshal(targetRespBody, &targetsvr); err != nil { @@ -150,8 +150,8 @@ func List() (respBody []byte, err error) { // Export func Export(conn int) (payload [][]byte, err error) { // don't print to sysout - apiclient.SetClientPrintHttpResponse(false) - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) respBody, err := List() if err != nil { @@ -222,8 +222,8 @@ func Export(conn int) (payload [][]byte, err error) { func exportServers(wg *sync.WaitGroup, jobs <-chan string, results chan<- []byte, errs chan<- error) { defer wg.Done() - defer apiclient.SetClientPrintHttpResponse(apiclient.GetCmdPrintHttpResponseSetting()) - apiclient.SetClientPrintHttpResponse(false) + defer apiclient.ClientPrintHttpResponse.Set(apiclient.GetCmdPrintHttpResponseSetting()) + apiclient.ClientPrintHttpResponse.Set(false) for { job, ok := <-jobs if !ok {