bunnyshell.com/sdk@v0.16.0/api_secret.go (about) 1 /* 2 API Bunnyshell Environments 3 4 Interact with Bunnyshell Platform 5 6 API version: 1.1.0 7 Contact: osi+support@bunnyshell.com 8 */ 9 10 // Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. 11 12 package sdk 13 14 import ( 15 "bytes" 16 "context" 17 "io" 18 "net/http" 19 "net/url" 20 ) 21 22 // SecretAPIService SecretAPI service 23 type SecretAPIService service 24 25 type ApiSecretDecryptRequest struct { 26 ctx context.Context 27 ApiService *SecretAPIService 28 secretDecryptAction *SecretDecryptAction 29 } 30 31 // The new secret resource 32 func (r ApiSecretDecryptRequest) SecretDecryptAction(secretDecryptAction SecretDecryptAction) ApiSecretDecryptRequest { 33 r.secretDecryptAction = &secretDecryptAction 34 return r 35 } 36 37 func (r ApiSecretDecryptRequest) Execute() (*SecretDecryptedItem, *http.Response, error) { 38 return r.ApiService.SecretDecryptExecute(r) 39 } 40 41 /* 42 SecretDecrypt Decrypt a cipher text. 43 44 Decrypt a cipher text. 45 46 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 47 @return ApiSecretDecryptRequest 48 */ 49 func (a *SecretAPIService) SecretDecrypt(ctx context.Context) ApiSecretDecryptRequest { 50 return ApiSecretDecryptRequest{ 51 ApiService: a, 52 ctx: ctx, 53 } 54 } 55 56 // Execute executes the request 57 // 58 // @return SecretDecryptedItem 59 func (a *SecretAPIService) SecretDecryptExecute(r ApiSecretDecryptRequest) (*SecretDecryptedItem, *http.Response, error) { 60 var ( 61 localVarHTTPMethod = http.MethodPost 62 localVarPostBody interface{} 63 formFiles []formFile 64 localVarReturnValue *SecretDecryptedItem 65 ) 66 67 localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "SecretAPIService.SecretDecrypt") 68 if err != nil { 69 return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} 70 } 71 72 localVarPath := localBasePath + "/v1/secrets/decrypt" 73 74 localVarHeaderParams := make(map[string]string) 75 localVarQueryParams := url.Values{} 76 localVarFormParams := url.Values{} 77 if r.secretDecryptAction == nil { 78 return localVarReturnValue, nil, reportError("secretDecryptAction is required and must be specified") 79 } 80 81 // to determine the Content-Type header 82 localVarHTTPContentTypes := []string{"application/json"} 83 84 // set Content-Type header 85 localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) 86 if localVarHTTPContentType != "" { 87 localVarHeaderParams["Content-Type"] = localVarHTTPContentType 88 } 89 90 // to determine the Accept header 91 localVarHTTPHeaderAccepts := []string{"application/hal+json", "application/problem+json"} 92 93 // set Accept header 94 localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) 95 if localVarHTTPHeaderAccept != "" { 96 localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept 97 } 98 // body params 99 localVarPostBody = r.secretDecryptAction 100 if r.ctx != nil { 101 // API Key Authentication 102 if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { 103 if apiKey, ok := auth["JWT"]; ok { 104 var key string 105 if apiKey.Prefix != "" { 106 key = apiKey.Prefix + " " + apiKey.Key 107 } else { 108 key = apiKey.Key 109 } 110 localVarHeaderParams["Authorization"] = key 111 } 112 } 113 } 114 if r.ctx != nil { 115 // API Key Authentication 116 if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { 117 if apiKey, ok := auth["ApiKeyAuth"]; ok { 118 var key string 119 if apiKey.Prefix != "" { 120 key = apiKey.Prefix + " " + apiKey.Key 121 } else { 122 key = apiKey.Key 123 } 124 localVarHeaderParams["X-Auth-Token"] = key 125 } 126 } 127 } 128 req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) 129 if err != nil { 130 return localVarReturnValue, nil, err 131 } 132 133 localVarHTTPResponse, err := a.client.callAPI(req) 134 if err != nil || localVarHTTPResponse == nil { 135 return localVarReturnValue, localVarHTTPResponse, err 136 } 137 138 localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) 139 localVarHTTPResponse.Body.Close() 140 localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) 141 if err != nil { 142 return localVarReturnValue, localVarHTTPResponse, err 143 } 144 145 if localVarHTTPResponse.StatusCode >= 300 { 146 newErr := &GenericOpenAPIError{ 147 body: localVarBody, 148 error: localVarHTTPResponse.Status, 149 } 150 if localVarHTTPResponse.StatusCode >= 400 && localVarHTTPResponse.StatusCode < 500 { 151 var v ProblemGeneric 152 err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) 153 if err != nil { 154 newErr.error = err.Error() 155 return localVarReturnValue, localVarHTTPResponse, newErr 156 } 157 newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) 158 newErr.model = v 159 } 160 return localVarReturnValue, localVarHTTPResponse, newErr 161 } 162 163 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) 164 if err != nil { 165 newErr := &GenericOpenAPIError{ 166 body: localVarBody, 167 error: err.Error(), 168 } 169 return localVarReturnValue, localVarHTTPResponse, newErr 170 } 171 172 return localVarReturnValue, localVarHTTPResponse, nil 173 } 174 175 type ApiSecretEncryptRequest struct { 176 ctx context.Context 177 ApiService *SecretAPIService 178 secretEncryptAction *SecretEncryptAction 179 } 180 181 // The new secret resource 182 func (r ApiSecretEncryptRequest) SecretEncryptAction(secretEncryptAction SecretEncryptAction) ApiSecretEncryptRequest { 183 r.secretEncryptAction = &secretEncryptAction 184 return r 185 } 186 187 func (r ApiSecretEncryptRequest) Execute() (*SecretEncryptedItem, *http.Response, error) { 188 return r.ApiService.SecretEncryptExecute(r) 189 } 190 191 /* 192 SecretEncrypt Encrypt a plain text. 193 194 Encrypt a plain text. 195 196 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 197 @return ApiSecretEncryptRequest 198 */ 199 func (a *SecretAPIService) SecretEncrypt(ctx context.Context) ApiSecretEncryptRequest { 200 return ApiSecretEncryptRequest{ 201 ApiService: a, 202 ctx: ctx, 203 } 204 } 205 206 // Execute executes the request 207 // 208 // @return SecretEncryptedItem 209 func (a *SecretAPIService) SecretEncryptExecute(r ApiSecretEncryptRequest) (*SecretEncryptedItem, *http.Response, error) { 210 var ( 211 localVarHTTPMethod = http.MethodPost 212 localVarPostBody interface{} 213 formFiles []formFile 214 localVarReturnValue *SecretEncryptedItem 215 ) 216 217 localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "SecretAPIService.SecretEncrypt") 218 if err != nil { 219 return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} 220 } 221 222 localVarPath := localBasePath + "/v1/secrets/encrypt" 223 224 localVarHeaderParams := make(map[string]string) 225 localVarQueryParams := url.Values{} 226 localVarFormParams := url.Values{} 227 if r.secretEncryptAction == nil { 228 return localVarReturnValue, nil, reportError("secretEncryptAction is required and must be specified") 229 } 230 231 // to determine the Content-Type header 232 localVarHTTPContentTypes := []string{"application/json"} 233 234 // set Content-Type header 235 localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) 236 if localVarHTTPContentType != "" { 237 localVarHeaderParams["Content-Type"] = localVarHTTPContentType 238 } 239 240 // to determine the Accept header 241 localVarHTTPHeaderAccepts := []string{"application/hal+json", "application/problem+json"} 242 243 // set Accept header 244 localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) 245 if localVarHTTPHeaderAccept != "" { 246 localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept 247 } 248 // body params 249 localVarPostBody = r.secretEncryptAction 250 if r.ctx != nil { 251 // API Key Authentication 252 if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { 253 if apiKey, ok := auth["JWT"]; ok { 254 var key string 255 if apiKey.Prefix != "" { 256 key = apiKey.Prefix + " " + apiKey.Key 257 } else { 258 key = apiKey.Key 259 } 260 localVarHeaderParams["Authorization"] = key 261 } 262 } 263 } 264 if r.ctx != nil { 265 // API Key Authentication 266 if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { 267 if apiKey, ok := auth["ApiKeyAuth"]; ok { 268 var key string 269 if apiKey.Prefix != "" { 270 key = apiKey.Prefix + " " + apiKey.Key 271 } else { 272 key = apiKey.Key 273 } 274 localVarHeaderParams["X-Auth-Token"] = key 275 } 276 } 277 } 278 req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) 279 if err != nil { 280 return localVarReturnValue, nil, err 281 } 282 283 localVarHTTPResponse, err := a.client.callAPI(req) 284 if err != nil || localVarHTTPResponse == nil { 285 return localVarReturnValue, localVarHTTPResponse, err 286 } 287 288 localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) 289 localVarHTTPResponse.Body.Close() 290 localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) 291 if err != nil { 292 return localVarReturnValue, localVarHTTPResponse, err 293 } 294 295 if localVarHTTPResponse.StatusCode >= 300 { 296 newErr := &GenericOpenAPIError{ 297 body: localVarBody, 298 error: localVarHTTPResponse.Status, 299 } 300 if localVarHTTPResponse.StatusCode >= 400 && localVarHTTPResponse.StatusCode < 500 { 301 var v ProblemGeneric 302 err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) 303 if err != nil { 304 newErr.error = err.Error() 305 return localVarReturnValue, localVarHTTPResponse, newErr 306 } 307 newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) 308 newErr.model = 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 := &GenericOpenAPIError{ 316 body: localVarBody, 317 error: err.Error(), 318 } 319 return localVarReturnValue, localVarHTTPResponse, newErr 320 } 321 322 return localVarReturnValue, localVarHTTPResponse, nil 323 } 324 325 type ApiSecretTranscryptConfigurationRequest struct { 326 ctx context.Context 327 ApiService *SecretAPIService 328 secretTranscryptConfigurationAction *SecretTranscryptConfigurationAction 329 } 330 331 // The new secret resource 332 func (r ApiSecretTranscryptConfigurationRequest) SecretTranscryptConfigurationAction(secretTranscryptConfigurationAction SecretTranscryptConfigurationAction) ApiSecretTranscryptConfigurationRequest { 333 r.secretTranscryptConfigurationAction = &secretTranscryptConfigurationAction 334 return r 335 } 336 337 func (r ApiSecretTranscryptConfigurationRequest) Execute() (map[string]interface{}, *http.Response, error) { 338 return r.ApiService.SecretTranscryptConfigurationExecute(r) 339 } 340 341 /* 342 SecretTranscryptConfiguration Encrypt or decrypt secrets from an environment configuration. 343 344 Encrypt or decrypt secrets from an environment configuration. 345 346 @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). 347 @return ApiSecretTranscryptConfigurationRequest 348 */ 349 func (a *SecretAPIService) SecretTranscryptConfiguration(ctx context.Context) ApiSecretTranscryptConfigurationRequest { 350 return ApiSecretTranscryptConfigurationRequest{ 351 ApiService: a, 352 ctx: ctx, 353 } 354 } 355 356 // Execute executes the request 357 // 358 // @return map[string]interface{} 359 func (a *SecretAPIService) SecretTranscryptConfigurationExecute(r ApiSecretTranscryptConfigurationRequest) (map[string]interface{}, *http.Response, error) { 360 var ( 361 localVarHTTPMethod = http.MethodPost 362 localVarPostBody interface{} 363 formFiles []formFile 364 localVarReturnValue map[string]interface{} 365 ) 366 367 localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "SecretAPIService.SecretTranscryptConfiguration") 368 if err != nil { 369 return localVarReturnValue, nil, &GenericOpenAPIError{error: err.Error()} 370 } 371 372 localVarPath := localBasePath + "/v1/secrets/transcrypt-configuration" 373 374 localVarHeaderParams := make(map[string]string) 375 localVarQueryParams := url.Values{} 376 localVarFormParams := url.Values{} 377 if r.secretTranscryptConfigurationAction == nil { 378 return localVarReturnValue, nil, reportError("secretTranscryptConfigurationAction is required and must be specified") 379 } 380 381 // to determine the Content-Type header 382 localVarHTTPContentTypes := []string{"application/json"} 383 384 // set Content-Type header 385 localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) 386 if localVarHTTPContentType != "" { 387 localVarHeaderParams["Content-Type"] = localVarHTTPContentType 388 } 389 390 // to determine the Accept header 391 localVarHTTPHeaderAccepts := []string{"application/x+yaml", "application/problem+json"} 392 393 // set Accept header 394 localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) 395 if localVarHTTPHeaderAccept != "" { 396 localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept 397 } 398 // body params 399 localVarPostBody = r.secretTranscryptConfigurationAction 400 if r.ctx != nil { 401 // API Key Authentication 402 if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { 403 if apiKey, ok := auth["JWT"]; ok { 404 var key string 405 if apiKey.Prefix != "" { 406 key = apiKey.Prefix + " " + apiKey.Key 407 } else { 408 key = apiKey.Key 409 } 410 localVarHeaderParams["Authorization"] = key 411 } 412 } 413 } 414 if r.ctx != nil { 415 // API Key Authentication 416 if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok { 417 if apiKey, ok := auth["ApiKeyAuth"]; ok { 418 var key string 419 if apiKey.Prefix != "" { 420 key = apiKey.Prefix + " " + apiKey.Key 421 } else { 422 key = apiKey.Key 423 } 424 localVarHeaderParams["X-Auth-Token"] = key 425 } 426 } 427 } 428 req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles) 429 if err != nil { 430 return localVarReturnValue, nil, err 431 } 432 433 localVarHTTPResponse, err := a.client.callAPI(req) 434 if err != nil || localVarHTTPResponse == nil { 435 return localVarReturnValue, localVarHTTPResponse, err 436 } 437 438 localVarBody, err := io.ReadAll(localVarHTTPResponse.Body) 439 localVarHTTPResponse.Body.Close() 440 localVarHTTPResponse.Body = io.NopCloser(bytes.NewBuffer(localVarBody)) 441 if err != nil { 442 return localVarReturnValue, localVarHTTPResponse, err 443 } 444 445 if localVarHTTPResponse.StatusCode >= 300 { 446 newErr := &GenericOpenAPIError{ 447 body: localVarBody, 448 error: localVarHTTPResponse.Status, 449 } 450 if localVarHTTPResponse.StatusCode >= 400 && localVarHTTPResponse.StatusCode < 500 { 451 var v ProblemGeneric 452 err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) 453 if err != nil { 454 newErr.error = err.Error() 455 return localVarReturnValue, localVarHTTPResponse, newErr 456 } 457 newErr.error = formatErrorMessage(localVarHTTPResponse.Status, &v) 458 newErr.model = v 459 } 460 return localVarReturnValue, localVarHTTPResponse, newErr 461 } 462 463 err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) 464 if err != nil { 465 newErr := &GenericOpenAPIError{ 466 body: localVarBody, 467 error: err.Error(), 468 } 469 return localVarReturnValue, localVarHTTPResponse, newErr 470 } 471 472 return localVarReturnValue, localVarHTTPResponse, nil 473 }