|
| 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 | + _nethttp "net/http" |
| 10 | + _neturl "net/url" |
| 11 | + |
| 12 | + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" |
| 13 | + "github.com/google/uuid" |
| 14 | +) |
| 15 | + |
| 16 | +// OrgConnectionsApi service type |
| 17 | +type OrgConnectionsApi datadog.Service |
| 18 | + |
| 19 | +// CreateOrgConnections Create Org Connection. |
| 20 | +// Create a new org connection between the current org and a target org. |
| 21 | +func (a *OrgConnectionsApi) CreateOrgConnections(ctx _context.Context, body OrgConnectionCreateRequest) (OrgConnectionResponse, *_nethttp.Response, error) { |
| 22 | + var ( |
| 23 | + localVarHTTPMethod = _nethttp.MethodPost |
| 24 | + localVarPostBody interface{} |
| 25 | + localVarReturnValue OrgConnectionResponse |
| 26 | + ) |
| 27 | + |
| 28 | + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.OrgConnectionsApi.CreateOrgConnections") |
| 29 | + if err != nil { |
| 30 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} |
| 31 | + } |
| 32 | + |
| 33 | + localVarPath := localBasePath + "/api/v2/org_connections" |
| 34 | + |
| 35 | + localVarHeaderParams := make(map[string]string) |
| 36 | + localVarQueryParams := _neturl.Values{} |
| 37 | + localVarFormParams := _neturl.Values{} |
| 38 | + localVarHeaderParams["Content-Type"] = "application/json" |
| 39 | + localVarHeaderParams["Accept"] = "application/json" |
| 40 | + |
| 41 | + // body params |
| 42 | + localVarPostBody = &body |
| 43 | + if a.Client.Cfg.DelegatedTokenConfig != nil { |
| 44 | + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) |
| 45 | + if err != nil { |
| 46 | + return localVarReturnValue, nil, err |
| 47 | + } |
| 48 | + } else { |
| 49 | + datadog.SetAuthKeys( |
| 50 | + ctx, |
| 51 | + &localVarHeaderParams, |
| 52 | + [2]string{"apiKeyAuth", "DD-API-KEY"}, |
| 53 | + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, |
| 54 | + ) |
| 55 | + } |
| 56 | + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) |
| 57 | + if err != nil { |
| 58 | + return localVarReturnValue, nil, err |
| 59 | + } |
| 60 | + |
| 61 | + localVarHTTPResponse, err := a.Client.CallAPI(req) |
| 62 | + if err != nil || localVarHTTPResponse == nil { |
| 63 | + return localVarReturnValue, localVarHTTPResponse, err |
| 64 | + } |
| 65 | + |
| 66 | + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) |
| 67 | + if err != nil { |
| 68 | + return localVarReturnValue, localVarHTTPResponse, err |
| 69 | + } |
| 70 | + |
| 71 | + if localVarHTTPResponse.StatusCode >= 300 { |
| 72 | + newErr := datadog.GenericOpenAPIError{ |
| 73 | + ErrorBody: localVarBody, |
| 74 | + ErrorMessage: localVarHTTPResponse.Status, |
| 75 | + } |
| 76 | + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 401 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 409 || localVarHTTPResponse.StatusCode == 429 { |
| 77 | + var v APIErrorResponse |
| 78 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 79 | + if err != nil { |
| 80 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 81 | + } |
| 82 | + newErr.ErrorModel = v |
| 83 | + } |
| 84 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 85 | + } |
| 86 | + |
| 87 | + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 88 | + if err != nil { |
| 89 | + newErr := datadog.GenericOpenAPIError{ |
| 90 | + ErrorBody: localVarBody, |
| 91 | + ErrorMessage: err.Error(), |
| 92 | + } |
| 93 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 94 | + } |
| 95 | + |
| 96 | + return localVarReturnValue, localVarHTTPResponse, nil |
| 97 | +} |
| 98 | + |
| 99 | +// DeleteOrgConnections Delete Org Connection. |
| 100 | +// Delete an existing org connection. |
| 101 | +func (a *OrgConnectionsApi) DeleteOrgConnections(ctx _context.Context, connectionId uuid.UUID) (*_nethttp.Response, error) { |
| 102 | + var ( |
| 103 | + localVarHTTPMethod = _nethttp.MethodDelete |
| 104 | + localVarPostBody interface{} |
| 105 | + ) |
| 106 | + |
| 107 | + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.OrgConnectionsApi.DeleteOrgConnections") |
| 108 | + if err != nil { |
| 109 | + return nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} |
| 110 | + } |
| 111 | + |
| 112 | + localVarPath := localBasePath + "/api/v2/org_connections/{connection_id}" |
| 113 | + localVarPath = datadog.ReplacePathParameter(localVarPath, "{connection_id}", _neturl.PathEscape(datadog.ParameterToString(connectionId, ""))) |
| 114 | + |
| 115 | + localVarHeaderParams := make(map[string]string) |
| 116 | + localVarQueryParams := _neturl.Values{} |
| 117 | + localVarFormParams := _neturl.Values{} |
| 118 | + localVarHeaderParams["Accept"] = "*/*" |
| 119 | + |
| 120 | + if a.Client.Cfg.DelegatedTokenConfig != nil { |
| 121 | + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) |
| 122 | + if err != nil { |
| 123 | + return nil, err |
| 124 | + } |
| 125 | + } else { |
| 126 | + datadog.SetAuthKeys( |
| 127 | + ctx, |
| 128 | + &localVarHeaderParams, |
| 129 | + [2]string{"apiKeyAuth", "DD-API-KEY"}, |
| 130 | + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, |
| 131 | + ) |
| 132 | + } |
| 133 | + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) |
| 134 | + if err != nil { |
| 135 | + return nil, err |
| 136 | + } |
| 137 | + |
| 138 | + localVarHTTPResponse, err := a.Client.CallAPI(req) |
| 139 | + if err != nil || localVarHTTPResponse == nil { |
| 140 | + return localVarHTTPResponse, err |
| 141 | + } |
| 142 | + |
| 143 | + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) |
| 144 | + if err != nil { |
| 145 | + return localVarHTTPResponse, err |
| 146 | + } |
| 147 | + |
| 148 | + if localVarHTTPResponse.StatusCode >= 300 { |
| 149 | + newErr := datadog.GenericOpenAPIError{ |
| 150 | + ErrorBody: localVarBody, |
| 151 | + ErrorMessage: localVarHTTPResponse.Status, |
| 152 | + } |
| 153 | + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 401 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 { |
| 154 | + var v APIErrorResponse |
| 155 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 156 | + if err != nil { |
| 157 | + return localVarHTTPResponse, newErr |
| 158 | + } |
| 159 | + newErr.ErrorModel = v |
| 160 | + } |
| 161 | + return localVarHTTPResponse, newErr |
| 162 | + } |
| 163 | + |
| 164 | + return localVarHTTPResponse, nil |
| 165 | +} |
| 166 | + |
| 167 | +// ListOrgConnections List Org Connections. |
| 168 | +// Returns a list of org connections. |
| 169 | +func (a *OrgConnectionsApi) ListOrgConnections(ctx _context.Context) (OrgConnectionListResponse, *_nethttp.Response, error) { |
| 170 | + var ( |
| 171 | + localVarHTTPMethod = _nethttp.MethodGet |
| 172 | + localVarPostBody interface{} |
| 173 | + localVarReturnValue OrgConnectionListResponse |
| 174 | + ) |
| 175 | + |
| 176 | + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.OrgConnectionsApi.ListOrgConnections") |
| 177 | + if err != nil { |
| 178 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} |
| 179 | + } |
| 180 | + |
| 181 | + localVarPath := localBasePath + "/api/v2/org_connections" |
| 182 | + |
| 183 | + localVarHeaderParams := make(map[string]string) |
| 184 | + localVarQueryParams := _neturl.Values{} |
| 185 | + localVarFormParams := _neturl.Values{} |
| 186 | + localVarHeaderParams["Accept"] = "application/json" |
| 187 | + |
| 188 | + if a.Client.Cfg.DelegatedTokenConfig != nil { |
| 189 | + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) |
| 190 | + if err != nil { |
| 191 | + return localVarReturnValue, nil, err |
| 192 | + } |
| 193 | + } else { |
| 194 | + datadog.SetAuthKeys( |
| 195 | + ctx, |
| 196 | + &localVarHeaderParams, |
| 197 | + [2]string{"apiKeyAuth", "DD-API-KEY"}, |
| 198 | + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, |
| 199 | + ) |
| 200 | + } |
| 201 | + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) |
| 202 | + if err != nil { |
| 203 | + return localVarReturnValue, nil, err |
| 204 | + } |
| 205 | + |
| 206 | + localVarHTTPResponse, err := a.Client.CallAPI(req) |
| 207 | + if err != nil || localVarHTTPResponse == nil { |
| 208 | + return localVarReturnValue, localVarHTTPResponse, err |
| 209 | + } |
| 210 | + |
| 211 | + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) |
| 212 | + if err != nil { |
| 213 | + return localVarReturnValue, localVarHTTPResponse, err |
| 214 | + } |
| 215 | + |
| 216 | + if localVarHTTPResponse.StatusCode >= 300 { |
| 217 | + newErr := datadog.GenericOpenAPIError{ |
| 218 | + ErrorBody: localVarBody, |
| 219 | + ErrorMessage: localVarHTTPResponse.Status, |
| 220 | + } |
| 221 | + if localVarHTTPResponse.StatusCode == 401 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 429 { |
| 222 | + var v APIErrorResponse |
| 223 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 224 | + if err != nil { |
| 225 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 226 | + } |
| 227 | + newErr.ErrorModel = v |
| 228 | + } |
| 229 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 230 | + } |
| 231 | + |
| 232 | + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 233 | + if err != nil { |
| 234 | + newErr := datadog.GenericOpenAPIError{ |
| 235 | + ErrorBody: localVarBody, |
| 236 | + ErrorMessage: err.Error(), |
| 237 | + } |
| 238 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 239 | + } |
| 240 | + |
| 241 | + return localVarReturnValue, localVarHTTPResponse, nil |
| 242 | +} |
| 243 | + |
| 244 | +// UpdateOrgConnections Update Org Connection. |
| 245 | +// Update an existing org connection. |
| 246 | +func (a *OrgConnectionsApi) UpdateOrgConnections(ctx _context.Context, connectionId uuid.UUID, body OrgConnectionUpdateRequest) (OrgConnectionResponse, *_nethttp.Response, error) { |
| 247 | + var ( |
| 248 | + localVarHTTPMethod = _nethttp.MethodPatch |
| 249 | + localVarPostBody interface{} |
| 250 | + localVarReturnValue OrgConnectionResponse |
| 251 | + ) |
| 252 | + |
| 253 | + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.OrgConnectionsApi.UpdateOrgConnections") |
| 254 | + if err != nil { |
| 255 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} |
| 256 | + } |
| 257 | + |
| 258 | + localVarPath := localBasePath + "/api/v2/org_connections/{connection_id}" |
| 259 | + localVarPath = datadog.ReplacePathParameter(localVarPath, "{connection_id}", _neturl.PathEscape(datadog.ParameterToString(connectionId, ""))) |
| 260 | + |
| 261 | + localVarHeaderParams := make(map[string]string) |
| 262 | + localVarQueryParams := _neturl.Values{} |
| 263 | + localVarFormParams := _neturl.Values{} |
| 264 | + localVarHeaderParams["Content-Type"] = "application/json" |
| 265 | + localVarHeaderParams["Accept"] = "application/json" |
| 266 | + |
| 267 | + // body params |
| 268 | + localVarPostBody = &body |
| 269 | + if a.Client.Cfg.DelegatedTokenConfig != nil { |
| 270 | + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) |
| 271 | + if err != nil { |
| 272 | + return localVarReturnValue, nil, err |
| 273 | + } |
| 274 | + } else { |
| 275 | + datadog.SetAuthKeys( |
| 276 | + ctx, |
| 277 | + &localVarHeaderParams, |
| 278 | + [2]string{"apiKeyAuth", "DD-API-KEY"}, |
| 279 | + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, |
| 280 | + ) |
| 281 | + } |
| 282 | + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) |
| 283 | + if err != nil { |
| 284 | + return localVarReturnValue, nil, err |
| 285 | + } |
| 286 | + |
| 287 | + localVarHTTPResponse, err := a.Client.CallAPI(req) |
| 288 | + if err != nil || localVarHTTPResponse == nil { |
| 289 | + return localVarReturnValue, localVarHTTPResponse, err |
| 290 | + } |
| 291 | + |
| 292 | + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) |
| 293 | + if err != nil { |
| 294 | + return localVarReturnValue, localVarHTTPResponse, err |
| 295 | + } |
| 296 | + |
| 297 | + if localVarHTTPResponse.StatusCode >= 300 { |
| 298 | + newErr := datadog.GenericOpenAPIError{ |
| 299 | + ErrorBody: localVarBody, |
| 300 | + ErrorMessage: localVarHTTPResponse.Status, |
| 301 | + } |
| 302 | + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 401 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 || localVarHTTPResponse.StatusCode == 429 { |
| 303 | + var v APIErrorResponse |
| 304 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 305 | + if err != nil { |
| 306 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 307 | + } |
| 308 | + newErr.ErrorModel = v |
| 309 | + } |
| 310 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 311 | + } |
| 312 | + |
| 313 | + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 314 | + if err != nil { |
| 315 | + newErr := datadog.GenericOpenAPIError{ |
| 316 | + ErrorBody: localVarBody, |
| 317 | + ErrorMessage: err.Error(), |
| 318 | + } |
| 319 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 320 | + } |
| 321 | + |
| 322 | + return localVarReturnValue, localVarHTTPResponse, nil |
| 323 | +} |
| 324 | + |
| 325 | +// NewOrgConnectionsApi Returns NewOrgConnectionsApi. |
| 326 | +func NewOrgConnectionsApi(client *datadog.APIClient) *OrgConnectionsApi { |
| 327 | + return &OrgConnectionsApi{ |
| 328 | + Client: client, |
| 329 | + } |
| 330 | +} |
0 commit comments