api_models.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Copyright © The ESO Authors
  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 provides the API client implementation for Infisical.
  14. package api
  15. import (
  16. "encoding/json"
  17. "fmt"
  18. )
  19. // MachineIdentityUniversalAuthRefreshRequest represents the request structure for refreshing universal auth tokens.
  20. type MachineIdentityUniversalAuthRefreshRequest struct {
  21. AccessToken string `json:"accessToken"`
  22. }
  23. // InfisicalAPIError represents an API error from Infisical.
  24. type InfisicalAPIError struct {
  25. StatusCode int
  26. Err any
  27. Message any
  28. Details any
  29. }
  30. func (e *InfisicalAPIError) Error() string {
  31. if e.Details != nil {
  32. detailsJSON, _ := json.Marshal(e.Details)
  33. return fmt.Sprintf("API error (%d): error=%v message=%v, details=%s", e.StatusCode, e.Err, e.Message, string(detailsJSON))
  34. }
  35. return fmt.Sprintf("API error (%d): error=%v message=%v", e.StatusCode, e.Err, e.Message)
  36. }
  37. // MachineIdentityDetailsResponse represents a response containing machine identity details.
  38. type MachineIdentityDetailsResponse struct {
  39. AccessToken string `json:"accessToken"`
  40. ExpiresIn int `json:"expiresIn"`
  41. AccessTokenMaxTTL int `json:"accessTokenMaxTTL"`
  42. TokenType string `json:"tokenType"`
  43. }
  44. // RevokeMachineIdentityAccessTokenResponse represents a response from revoking a machine identity token.
  45. type RevokeMachineIdentityAccessTokenResponse struct {
  46. Message string `json:"message"`
  47. }
  48. // GetSecretByKeyV3Response represents a response from getting a secret by key in V3 API.
  49. type GetSecretByKeyV3Response struct {
  50. Secret SecretsV3 `json:"secret"`
  51. }
  52. // GetSecretsV3Response represents a response from getting secrets in V3 API.
  53. type GetSecretsV3Response struct {
  54. Secrets []SecretsV3 `json:"secrets"`
  55. ImportedSecrets []ImportedSecretV3 `json:"imports,omitempty"`
  56. Modified bool `json:"modified,omitempty"`
  57. ETag string `json:"ETag,omitempty"`
  58. }
  59. // SecretsV3 represents secrets in V3 API format.
  60. type SecretsV3 struct {
  61. ID string `json:"id"`
  62. Workspace string `json:"workspace"`
  63. Environment string `json:"environment"`
  64. Version int `json:"version"`
  65. Type string `json:"string"`
  66. SecretKey string `json:"secretKey"`
  67. SecretValue string `json:"secretValue"`
  68. SecretComment string `json:"secretComment"`
  69. }
  70. // ImportedSecretV3 represents an imported secret in V3 API format.
  71. type ImportedSecretV3 struct {
  72. Environment string `json:"environment"`
  73. FolderID string `json:"folderId"`
  74. SecretPath string `json:"secretPath"`
  75. Secrets []SecretsV3 `json:"secrets"`
  76. }
  77. // InfisicalAPIErrorResponse represents an error response from the Infisical API.
  78. type InfisicalAPIErrorResponse struct {
  79. StatusCode int `json:"statusCode"`
  80. Message string `json:"message"`
  81. Error string `json:"error"`
  82. // According to Infisical's API docs, `details` are only returned for 403 errors.
  83. Details any `json:"details,omitempty"`
  84. }