infra.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package types
  2. import "time"
  3. // InfraStatus is the status that an infrastructure can take
  4. type InfraStatus string
  5. // The allowed statuses
  6. const (
  7. StatusCreating InfraStatus = "creating"
  8. StatusCreated InfraStatus = "created"
  9. StatusError InfraStatus = "error"
  10. StatusDestroying InfraStatus = "destroying"
  11. StatusDestroyed InfraStatus = "destroyed"
  12. )
  13. // InfraKind is the kind that infra can be
  14. type InfraKind string
  15. // The supported infra kinds
  16. const (
  17. InfraTest InfraKind = "test"
  18. InfraECR InfraKind = "ecr"
  19. InfraEKS InfraKind = "eks"
  20. InfraGCR InfraKind = "gcr"
  21. InfraGKE InfraKind = "gke"
  22. InfraDOCR InfraKind = "docr"
  23. InfraDOKS InfraKind = "doks"
  24. InfraRDS InfraKind = "rds"
  25. )
  26. type Infra struct {
  27. ID uint `json:"id"`
  28. CreatedAt time.Time `json:"created_at"`
  29. UpdatedAt time.Time `json:"updated_at"`
  30. // The project that this integration belongs to
  31. ProjectID uint `json:"project_id"`
  32. APIVersion string `json:"api_version,omitempty"`
  33. SourceLink string `json:"source_link,omitempty"`
  34. SourceVersion string `json:"source_version,omitempty"`
  35. // The type of infra that was provisioned
  36. Kind InfraKind `json:"kind"`
  37. // Status is the status of the infra
  38. Status InfraStatus `json:"status"`
  39. // The AWS integration that was used to create the infra
  40. AWSIntegrationID uint `json:"aws_integration_id,omitempty"`
  41. // The GCP integration that was used to create the infra
  42. GCPIntegrationID uint `json:"gcp_integration_id,omitempty"`
  43. // The DO integration that was used to create the infra:
  44. // this points to an OAuthIntegrationID
  45. DOIntegrationID uint `json:"do_integration_id,omitempty"`
  46. // The last-applied, non-sensitive input variables to the provisioner. For now,
  47. // this is a map[string]string since we marshal into env vars anyway, but
  48. // eventually this config will be more complex.
  49. LastApplied map[string]string `json:"last_applied"`
  50. // LatestOperation is the last operation that was run against this infra, if
  51. // one exists
  52. LatestOperation *Operation `json:"latest_operation"`
  53. }
  54. type InfraCredentials struct {
  55. AWSIntegrationID uint `json:"aws_integration_id,omitempty"`
  56. GCPIntegrationID uint `json:"gcp_integration_id,omitempty"`
  57. DOIntegrationID uint `json:"do_integration_id,omitempty"`
  58. }
  59. type CreateInfraRequest struct {
  60. *InfraCredentials
  61. Kind string `json:"kind" form:"required"`
  62. Values map[string]interface{} `json:"values" form:"required"`
  63. }
  64. type ListInfraRequest struct {
  65. Version string `schema:"version"`
  66. }
  67. type DeleteInfraRequest struct {
  68. *InfraCredentials
  69. }
  70. type RetryInfraRequest struct {
  71. // Integration IDs are not required -- if they are passed in, they will override the
  72. // existing integration IDs
  73. *InfraCredentials
  74. // Values are not required -- if they are not passed in, the values will be
  75. // automatically populated from the previous operation
  76. Values map[string]interface{} `json:"values"`
  77. }
  78. type OperationMeta struct {
  79. LastUpdated time.Time `json:"last_updated"`
  80. UID string `json:"id"`
  81. InfraID uint `json:"infra_id"`
  82. Type string `json:"type"`
  83. Status string `json:"status"`
  84. Errored bool `json:"errored"`
  85. Error string `json:"error"`
  86. }
  87. type Operation struct {
  88. *OperationMeta
  89. LastApplied map[string]interface{} `json:"last_applied"`
  90. Form *FormYAML `json:"form"`
  91. }
  92. type InfraTemplateMeta struct {
  93. Icon string `json:"icon"`
  94. Description string `json:"description"`
  95. Name string `json:"name"`
  96. Version string `json:"version"`
  97. Kind string `json:"kind"`
  98. RequiredCredential string `json:"required_credential"`
  99. }
  100. type InfraTemplate struct {
  101. *InfraTemplateMeta
  102. Form *FormYAML `json:"form"`
  103. }