|
| 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 | + "github.com/google/uuid" |
| 16 | +) |
| 17 | + |
| 18 | +// ReportSchedulesApi service type |
| 19 | +type ReportSchedulesApi datadog.Service |
| 20 | + |
| 21 | +// CreateReportSchedule Create a report schedule. |
| 22 | +// Create a new scheduled report. A schedule renders a dashboard or integration dashboard |
| 23 | +// on a recurring cadence and delivers it to the configured recipients over email, Slack, |
| 24 | +// or Microsoft Teams. |
| 25 | +// Requires the `generate_dashboard_reports` permission. |
| 26 | +func (a *ReportSchedulesApi) CreateReportSchedule(ctx _context.Context, body ReportScheduleCreateRequest) (ReportScheduleResponse, *_nethttp.Response, error) { |
| 27 | + var ( |
| 28 | + localVarHTTPMethod = _nethttp.MethodPost |
| 29 | + localVarPostBody interface{} |
| 30 | + localVarReturnValue ReportScheduleResponse |
| 31 | + ) |
| 32 | + |
| 33 | + operationId := "v2.CreateReportSchedule" |
| 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.ReportSchedulesApi.CreateReportSchedule") |
| 43 | + if err != nil { |
| 44 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} |
| 45 | + } |
| 46 | + |
| 47 | + localVarPath := localBasePath + "/api/v2/reporting/schedule" |
| 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 == 403 || localVarHTTPResponse.StatusCode == 404 { |
| 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 | +// PatchReportSchedule Update a report schedule. |
| 123 | +// Update an existing scheduled report by its identifier. The editable attributes |
| 124 | +// are replaced with the supplied values; the targeted resource (`resource_id` and |
| 125 | +// `resource_type`) cannot be changed after creation. |
| 126 | +// Requires the `generate_dashboard_reports` permission and schedule ownership. |
| 127 | +func (a *ReportSchedulesApi) PatchReportSchedule(ctx _context.Context, scheduleUuid uuid.UUID, body ReportSchedulePatchRequest) (ReportScheduleResponse, *_nethttp.Response, error) { |
| 128 | + var ( |
| 129 | + localVarHTTPMethod = _nethttp.MethodPatch |
| 130 | + localVarPostBody interface{} |
| 131 | + localVarReturnValue ReportScheduleResponse |
| 132 | + ) |
| 133 | + |
| 134 | + operationId := "v2.PatchReportSchedule" |
| 135 | + isOperationEnabled := a.Client.Cfg.IsUnstableOperationEnabled(operationId) |
| 136 | + if !isOperationEnabled { |
| 137 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} |
| 138 | + } |
| 139 | + if isOperationEnabled && a.Client.Cfg.Debug { |
| 140 | + _log.Printf("WARNING: Using unstable operation '%s'", operationId) |
| 141 | + } |
| 142 | + |
| 143 | + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.ReportSchedulesApi.PatchReportSchedule") |
| 144 | + if err != nil { |
| 145 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} |
| 146 | + } |
| 147 | + |
| 148 | + localVarPath := localBasePath + "/api/v2/reporting/schedule/{schedule_uuid}" |
| 149 | + localVarPath = datadog.ReplacePathParameter(localVarPath, "{schedule_uuid}", _neturl.PathEscape(datadog.ParameterToString(scheduleUuid, ""))) |
| 150 | + |
| 151 | + localVarHeaderParams := make(map[string]string) |
| 152 | + localVarQueryParams := _neturl.Values{} |
| 153 | + localVarFormParams := _neturl.Values{} |
| 154 | + localVarHeaderParams["Content-Type"] = "application/json" |
| 155 | + localVarHeaderParams["Accept"] = "application/json" |
| 156 | + |
| 157 | + // body params |
| 158 | + localVarPostBody = &body |
| 159 | + if a.Client.Cfg.DelegatedTokenConfig != nil { |
| 160 | + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) |
| 161 | + if err != nil { |
| 162 | + return localVarReturnValue, nil, err |
| 163 | + } |
| 164 | + } else { |
| 165 | + datadog.SetAuthKeys( |
| 166 | + ctx, |
| 167 | + &localVarHeaderParams, |
| 168 | + [2]string{"apiKeyAuth", "DD-API-KEY"}, |
| 169 | + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, |
| 170 | + ) |
| 171 | + } |
| 172 | + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) |
| 173 | + if err != nil { |
| 174 | + return localVarReturnValue, nil, err |
| 175 | + } |
| 176 | + |
| 177 | + localVarHTTPResponse, err := a.Client.CallAPI(req) |
| 178 | + if err != nil || localVarHTTPResponse == nil { |
| 179 | + return localVarReturnValue, localVarHTTPResponse, err |
| 180 | + } |
| 181 | + |
| 182 | + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) |
| 183 | + if err != nil { |
| 184 | + return localVarReturnValue, localVarHTTPResponse, err |
| 185 | + } |
| 186 | + |
| 187 | + if localVarHTTPResponse.StatusCode >= 300 { |
| 188 | + newErr := datadog.GenericOpenAPIError{ |
| 189 | + ErrorBody: localVarBody, |
| 190 | + ErrorMessage: localVarHTTPResponse.Status, |
| 191 | + } |
| 192 | + if localVarHTTPResponse.StatusCode == 400 || localVarHTTPResponse.StatusCode == 403 || localVarHTTPResponse.StatusCode == 404 { |
| 193 | + var v JSONAPIErrorResponse |
| 194 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 195 | + if err != nil { |
| 196 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 197 | + } |
| 198 | + newErr.ErrorModel = v |
| 199 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 200 | + } |
| 201 | + if localVarHTTPResponse.StatusCode == 429 { |
| 202 | + var v APIErrorResponse |
| 203 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 204 | + if err != nil { |
| 205 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 206 | + } |
| 207 | + newErr.ErrorModel = v |
| 208 | + } |
| 209 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 210 | + } |
| 211 | + |
| 212 | + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 213 | + if err != nil { |
| 214 | + newErr := datadog.GenericOpenAPIError{ |
| 215 | + ErrorBody: localVarBody, |
| 216 | + ErrorMessage: err.Error(), |
| 217 | + } |
| 218 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 219 | + } |
| 220 | + |
| 221 | + return localVarReturnValue, localVarHTTPResponse, nil |
| 222 | +} |
| 223 | + |
| 224 | +// NewReportSchedulesApi Returns NewReportSchedulesApi. |
| 225 | +func NewReportSchedulesApi(client *datadog.APIClient) *ReportSchedulesApi { |
| 226 | + return &ReportSchedulesApi{ |
| 227 | + Client: client, |
| 228 | + } |
| 229 | +} |
0 commit comments