|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. |
| 2 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 3 | +// Copyright 2019-Present Datadog, Inc. |
| 4 | + |
| 5 | +package datadogV2 |
| 6 | + |
| 7 | +import ( |
| 8 | + _context "context" |
| 9 | + _fmt "fmt" |
| 10 | + _log "log" |
| 11 | + _nethttp "net/http" |
| 12 | + _neturl "net/url" |
| 13 | + |
| 14 | + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" |
| 15 | +) |
| 16 | + |
| 17 | +// CustomerOrgApi service type |
| 18 | +type CustomerOrgApi datadog.Service |
| 19 | + |
| 20 | +// DisableCustomerOrg Disable the authenticated customer organization. |
| 21 | +// Disable the Datadog organization associated with the authenticated user or API key. |
| 22 | +// The request body uses JSON:API format. If `org_uuid` is supplied, it must match |
| 23 | +// the authenticated org or the request is rejected. Successful calls disable the org |
| 24 | +// and return the resulting state from the downstream service. Requires the |
| 25 | +// `org_management` permission. |
| 26 | +func (a *CustomerOrgApi) DisableCustomerOrg(ctx _context.Context, body CustomerOrgDisableRequest) (CustomerOrgDisableResponse, *_nethttp.Response, error) { |
| 27 | + var ( |
| 28 | + localVarHTTPMethod = _nethttp.MethodPost |
| 29 | + localVarPostBody interface{} |
| 30 | + localVarReturnValue CustomerOrgDisableResponse |
| 31 | + ) |
| 32 | + |
| 33 | + operationId := "v2.DisableCustomerOrg" |
| 34 | + isOperationEnabled := a.Client.Cfg.IsUnstableOperationEnabled(operationId) |
| 35 | + if !isOperationEnabled { |
| 36 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} |
| 37 | + } |
| 38 | + if isOperationEnabled && a.Client.Cfg.Debug { |
| 39 | + _log.Printf("WARNING: Using unstable operation '%s'", operationId) |
| 40 | + } |
| 41 | + |
| 42 | + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.CustomerOrgApi.DisableCustomerOrg") |
| 43 | + if err != nil { |
| 44 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} |
| 45 | + } |
| 46 | + |
| 47 | + localVarPath := localBasePath + "/api/v2/org/disable" |
| 48 | + |
| 49 | + localVarHeaderParams := make(map[string]string) |
| 50 | + localVarQueryParams := _neturl.Values{} |
| 51 | + localVarFormParams := _neturl.Values{} |
| 52 | + localVarHeaderParams["Content-Type"] = "application/json" |
| 53 | + localVarHeaderParams["Accept"] = "application/json" |
| 54 | + |
| 55 | + // body params |
| 56 | + localVarPostBody = &body |
| 57 | + if a.Client.Cfg.DelegatedTokenConfig != nil { |
| 58 | + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) |
| 59 | + if err != nil { |
| 60 | + return localVarReturnValue, nil, err |
| 61 | + } |
| 62 | + } else { |
| 63 | + datadog.SetAuthKeys( |
| 64 | + ctx, |
| 65 | + &localVarHeaderParams, |
| 66 | + [2]string{"apiKeyAuth", "DD-API-KEY"}, |
| 67 | + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, |
| 68 | + ) |
| 69 | + } |
| 70 | + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) |
| 71 | + if err != nil { |
| 72 | + return localVarReturnValue, nil, err |
| 73 | + } |
| 74 | + |
| 75 | + localVarHTTPResponse, err := a.Client.CallAPI(req) |
| 76 | + if err != nil || localVarHTTPResponse == nil { |
| 77 | + return localVarReturnValue, localVarHTTPResponse, err |
| 78 | + } |
| 79 | + |
| 80 | + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) |
| 81 | + if err != nil { |
| 82 | + return localVarReturnValue, localVarHTTPResponse, err |
| 83 | + } |
| 84 | + |
| 85 | + if localVarHTTPResponse.StatusCode >= 300 { |
| 86 | + newErr := datadog.GenericOpenAPIError{ |
| 87 | + ErrorBody: localVarBody, |
| 88 | + ErrorMessage: localVarHTTPResponse.Status, |
| 89 | + } |
| 90 | + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 401 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 500 { |
| 91 | + var v JSONAPIErrorResponse |
| 92 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 93 | + if err != nil { |
| 94 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 95 | + } |
| 96 | + newErr.ErrorModel = v |
| 97 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 98 | + } |
| 99 | + if localVarHTTPResponse.StatusCode == 429 { |
| 100 | + var v APIErrorResponse |
| 101 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 102 | + if err != nil { |
| 103 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 104 | + } |
| 105 | + newErr.ErrorModel = v |
| 106 | + } |
| 107 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 108 | + } |
| 109 | + |
| 110 | + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 111 | + if err != nil { |
| 112 | + newErr := datadog.GenericOpenAPIError{ |
| 113 | + ErrorBody: localVarBody, |
| 114 | + ErrorMessage: err.Error(), |
| 115 | + } |
| 116 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 117 | + } |
| 118 | + |
| 119 | + return localVarReturnValue, localVarHTTPResponse, nil |
| 120 | +} |
| 121 | + |
| 122 | +// NewCustomerOrgApi Returns NewCustomerOrgApi. |
| 123 | +func NewCustomerOrgApi(client *datadog.APIClient) *CustomerOrgApi { |
| 124 | + return &CustomerOrgApi{ |
| 125 | + Client: client, |
| 126 | + } |
| 127 | +} |
0 commit comments