infra.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. ClusterID uint `json:"cluster_id"`
  62. Kind string `json:"kind" form:"required"`
  63. Values map[string]interface{} `json:"values" form:"required"`
  64. }
  65. type ListInfraRequest struct {
  66. Version string `schema:"version"`
  67. }
  68. type DeleteInfraRequest struct {
  69. *InfraCredentials
  70. }
  71. type RetryInfraRequest struct {
  72. // Integration IDs are not required -- if they are passed in, they will override the
  73. // existing integration IDs
  74. *InfraCredentials
  75. // Values are not required -- if they are not passed in, the values will be
  76. // automatically populated from the previous operation
  77. Values map[string]interface{} `json:"values"`
  78. }
  79. type OperationMeta struct {
  80. LastUpdated time.Time `json:"last_updated"`
  81. UID string `json:"id"`
  82. InfraID uint `json:"infra_id"`
  83. Type string `json:"type"`
  84. Status string `json:"status"`
  85. Errored bool `json:"errored"`
  86. Error string `json:"error"`
  87. }
  88. type Operation struct {
  89. *OperationMeta
  90. LastApplied map[string]interface{} `json:"last_applied"`
  91. Form *FormYAML `json:"form"`
  92. }
  93. type InfraTemplateMeta struct {
  94. Icon string `json:"icon"`
  95. Description string `json:"description"`
  96. Name string `json:"name"`
  97. Version string `json:"version"`
  98. Kind string `json:"kind"`
  99. RequiredCredential string `json:"required_credential"`
  100. }
  101. type InfraTemplate struct {
  102. *InfraTemplateMeta
  103. Form *FormYAML `json:"form"`
  104. }