api_models.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Copyright © 2025 ESO Maintainer Team
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package api
  14. import (
  15. "encoding/json"
  16. "fmt"
  17. )
  18. type MachineIdentityUniversalAuthRefreshRequest struct {
  19. AccessToken string `json:"accessToken"`
  20. }
  21. type InfisicalAPIError struct {
  22. StatusCode int
  23. Err any
  24. Message any
  25. Details any
  26. }
  27. func (e *InfisicalAPIError) Error() string {
  28. if e.Details != nil {
  29. detailsJSON, _ := json.Marshal(e.Details)
  30. return fmt.Sprintf("API error (%d): error=%v message=%v, details=%s", e.StatusCode, e.Err, e.Message, string(detailsJSON))
  31. }
  32. return fmt.Sprintf("API error (%d): error=%v message=%v", e.StatusCode, e.Err, e.Message)
  33. }
  34. type MachineIdentityDetailsResponse struct {
  35. AccessToken string `json:"accessToken"`
  36. ExpiresIn int `json:"expiresIn"`
  37. AccessTokenMaxTTL int `json:"accessTokenMaxTTL"`
  38. TokenType string `json:"tokenType"`
  39. }
  40. type RevokeMachineIdentityAccessTokenResponse struct {
  41. Message string `json:"message"`
  42. }
  43. type GetSecretByKeyV3Response struct {
  44. Secret SecretsV3 `json:"secret"`
  45. }
  46. type GetSecretsV3Response struct {
  47. Secrets []SecretsV3 `json:"secrets"`
  48. ImportedSecrets []ImportedSecretV3 `json:"imports,omitempty"`
  49. Modified bool `json:"modified,omitempty"`
  50. ETag string `json:"ETag,omitempty"`
  51. }
  52. type SecretsV3 struct {
  53. ID string `json:"id"`
  54. Workspace string `json:"workspace"`
  55. Environment string `json:"environment"`
  56. Version int `json:"version"`
  57. Type string `json:"string"`
  58. SecretKey string `json:"secretKey"`
  59. SecretValue string `json:"secretValue"`
  60. SecretComment string `json:"secretComment"`
  61. }
  62. type ImportedSecretV3 struct {
  63. Environment string `json:"environment"`
  64. FolderID string `json:"folderId"`
  65. SecretPath string `json:"secretPath"`
  66. Secrets []SecretsV3 `json:"secrets"`
  67. }
  68. type InfisicalAPIErrorResponse struct {
  69. StatusCode int `json:"statusCode"`
  70. Message string `json:"message"`
  71. Error string `json:"error"`
  72. // According to Infisical's API docs, `details` are only returned for 403 errors.
  73. Details any `json:"details,omitempty"`
  74. }