|
| 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 | +// StaticAnalysisApi service type |
| 18 | +type StaticAnalysisApi datadog.Service |
| 19 | + |
| 20 | +// CreateSCAResolveVulnerableSymbols POST request to resolve vulnerable symbols. |
| 21 | +// Post vulnerable symbols |
| 22 | +func (a *StaticAnalysisApi) CreateSCAResolveVulnerableSymbols(ctx _context.Context, body ResolveVulnerableSymbolsRequest) (ResolveVulnerableSymbolsResponse, *_nethttp.Response, error) { |
| 23 | + var ( |
| 24 | + localVarHTTPMethod = _nethttp.MethodPost |
| 25 | + localVarPostBody interface{} |
| 26 | + localVarReturnValue ResolveVulnerableSymbolsResponse |
| 27 | + ) |
| 28 | + |
| 29 | + operationId := "v2.CreateSCAResolveVulnerableSymbols" |
| 30 | + isOperationEnabled := a.Client.Cfg.IsUnstableOperationEnabled(operationId) |
| 31 | + if !isOperationEnabled { |
| 32 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} |
| 33 | + } |
| 34 | + if isOperationEnabled && a.Client.Cfg.Debug { |
| 35 | + _log.Printf("WARNING: Using unstable operation '%s'", operationId) |
| 36 | + } |
| 37 | + |
| 38 | + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.StaticAnalysisApi.CreateSCAResolveVulnerableSymbols") |
| 39 | + if err != nil { |
| 40 | + return localVarReturnValue, nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} |
| 41 | + } |
| 42 | + |
| 43 | + localVarPath := localBasePath + "/api/v2/static-analysis-sca/vulnerabilities/resolve-vulnerable-symbols" |
| 44 | + |
| 45 | + localVarHeaderParams := make(map[string]string) |
| 46 | + localVarQueryParams := _neturl.Values{} |
| 47 | + localVarFormParams := _neturl.Values{} |
| 48 | + localVarHeaderParams["Content-Type"] = "application/json" |
| 49 | + localVarHeaderParams["Accept"] = "application/json" |
| 50 | + |
| 51 | + // body params |
| 52 | + localVarPostBody = &body |
| 53 | + if a.Client.Cfg.DelegatedTokenConfig != nil { |
| 54 | + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) |
| 55 | + if err != nil { |
| 56 | + return localVarReturnValue, nil, err |
| 57 | + } |
| 58 | + } else { |
| 59 | + datadog.SetAuthKeys( |
| 60 | + ctx, |
| 61 | + &localVarHeaderParams, |
| 62 | + [2]string{"apiKeyAuth", "DD-API-KEY"}, |
| 63 | + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, |
| 64 | + ) |
| 65 | + } |
| 66 | + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) |
| 67 | + if err != nil { |
| 68 | + return localVarReturnValue, nil, err |
| 69 | + } |
| 70 | + |
| 71 | + localVarHTTPResponse, err := a.Client.CallAPI(req) |
| 72 | + if err != nil || localVarHTTPResponse == nil { |
| 73 | + return localVarReturnValue, localVarHTTPResponse, err |
| 74 | + } |
| 75 | + |
| 76 | + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) |
| 77 | + if err != nil { |
| 78 | + return localVarReturnValue, localVarHTTPResponse, err |
| 79 | + } |
| 80 | + |
| 81 | + if localVarHTTPResponse.StatusCode >= 300 { |
| 82 | + newErr := datadog.GenericOpenAPIError{ |
| 83 | + ErrorBody: localVarBody, |
| 84 | + ErrorMessage: localVarHTTPResponse.Status, |
| 85 | + } |
| 86 | + if localVarHTTPResponse.StatusCode == 429 { |
| 87 | + var v APIErrorResponse |
| 88 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 89 | + if err != nil { |
| 90 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 91 | + } |
| 92 | + newErr.ErrorModel = v |
| 93 | + } |
| 94 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 95 | + } |
| 96 | + |
| 97 | + err = a.Client.Decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 98 | + if err != nil { |
| 99 | + newErr := datadog.GenericOpenAPIError{ |
| 100 | + ErrorBody: localVarBody, |
| 101 | + ErrorMessage: err.Error(), |
| 102 | + } |
| 103 | + return localVarReturnValue, localVarHTTPResponse, newErr |
| 104 | + } |
| 105 | + |
| 106 | + return localVarReturnValue, localVarHTTPResponse, nil |
| 107 | +} |
| 108 | + |
| 109 | +// CreateSCAResult Post dependencies for analysis. |
| 110 | +// Post dependencies for analysis |
| 111 | +func (a *StaticAnalysisApi) CreateSCAResult(ctx _context.Context, body ScaRequest) (*_nethttp.Response, error) { |
| 112 | + var ( |
| 113 | + localVarHTTPMethod = _nethttp.MethodPost |
| 114 | + localVarPostBody interface{} |
| 115 | + ) |
| 116 | + |
| 117 | + operationId := "v2.CreateSCAResult" |
| 118 | + isOperationEnabled := a.Client.Cfg.IsUnstableOperationEnabled(operationId) |
| 119 | + if !isOperationEnabled { |
| 120 | + return nil, datadog.GenericOpenAPIError{ErrorMessage: _fmt.Sprintf("Unstable operation '%s' is disabled", operationId)} |
| 121 | + } |
| 122 | + if isOperationEnabled && a.Client.Cfg.Debug { |
| 123 | + _log.Printf("WARNING: Using unstable operation '%s'", operationId) |
| 124 | + } |
| 125 | + |
| 126 | + localBasePath, err := a.Client.Cfg.ServerURLWithContext(ctx, "v2.StaticAnalysisApi.CreateSCAResult") |
| 127 | + if err != nil { |
| 128 | + return nil, datadog.GenericOpenAPIError{ErrorMessage: err.Error()} |
| 129 | + } |
| 130 | + |
| 131 | + localVarPath := localBasePath + "/api/v2/static-analysis-sca/dependencies" |
| 132 | + |
| 133 | + localVarHeaderParams := make(map[string]string) |
| 134 | + localVarQueryParams := _neturl.Values{} |
| 135 | + localVarFormParams := _neturl.Values{} |
| 136 | + localVarHeaderParams["Content-Type"] = "application/json" |
| 137 | + localVarHeaderParams["Accept"] = "*/*" |
| 138 | + |
| 139 | + // body params |
| 140 | + localVarPostBody = &body |
| 141 | + if a.Client.Cfg.DelegatedTokenConfig != nil { |
| 142 | + err = datadog.UseDelegatedTokenAuth(ctx, &localVarHeaderParams, a.Client.Cfg.DelegatedTokenConfig) |
| 143 | + if err != nil { |
| 144 | + return nil, err |
| 145 | + } |
| 146 | + } else { |
| 147 | + datadog.SetAuthKeys( |
| 148 | + ctx, |
| 149 | + &localVarHeaderParams, |
| 150 | + [2]string{"apiKeyAuth", "DD-API-KEY"}, |
| 151 | + [2]string{"appKeyAuth", "DD-APPLICATION-KEY"}, |
| 152 | + ) |
| 153 | + } |
| 154 | + req, err := a.Client.PrepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, nil) |
| 155 | + if err != nil { |
| 156 | + return nil, err |
| 157 | + } |
| 158 | + |
| 159 | + localVarHTTPResponse, err := a.Client.CallAPI(req) |
| 160 | + if err != nil || localVarHTTPResponse == nil { |
| 161 | + return localVarHTTPResponse, err |
| 162 | + } |
| 163 | + |
| 164 | + localVarBody, err := datadog.ReadBody(localVarHTTPResponse) |
| 165 | + if err != nil { |
| 166 | + return localVarHTTPResponse, err |
| 167 | + } |
| 168 | + |
| 169 | + if localVarHTTPResponse.StatusCode >= 300 { |
| 170 | + newErr := datadog.GenericOpenAPIError{ |
| 171 | + ErrorBody: localVarBody, |
| 172 | + ErrorMessage: localVarHTTPResponse.Status, |
| 173 | + } |
| 174 | + if localVarHTTPResponse.StatusCode == 429 { |
| 175 | + var v APIErrorResponse |
| 176 | + err = a.Client.Decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) |
| 177 | + if err != nil { |
| 178 | + return localVarHTTPResponse, newErr |
| 179 | + } |
| 180 | + newErr.ErrorModel = v |
| 181 | + } |
| 182 | + return localVarHTTPResponse, newErr |
| 183 | + } |
| 184 | + |
| 185 | + return localVarHTTPResponse, nil |
| 186 | +} |
| 187 | + |
| 188 | +// NewStaticAnalysisApi Returns NewStaticAnalysisApi. |
| 189 | +func NewStaticAnalysisApi(client *datadog.APIClient) *StaticAnalysisApi { |
| 190 | + return &StaticAnalysisApi{ |
| 191 | + Client: client, |
| 192 | + } |
| 193 | +} |
0 commit comments