api_models.go 2.6 KB

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