infra.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. InfraAKS InfraKind = "aks"
  25. InfraACR InfraKind = "acr"
  26. InfraRDS InfraKind = "rds"
  27. InfraS3 InfraKind = "s3"
  28. )
  29. type Infra struct {
  30. ID uint `json:"id"`
  31. CreatedAt time.Time `json:"created_at"`
  32. UpdatedAt time.Time `json:"updated_at"`
  33. // The project that this integration belongs to
  34. ProjectID uint `json:"project_id"`
  35. APIVersion string `json:"api_version,omitempty"`
  36. SourceLink string `json:"source_link,omitempty"`
  37. SourceVersion string `json:"source_version,omitempty"`
  38. // The type of infra that was provisioned
  39. Kind InfraKind `json:"kind"`
  40. // Status is the status of the infra
  41. Status InfraStatus `json:"status"`
  42. // The AWS integration that was used to create the infra
  43. AWSIntegrationID uint `json:"aws_integration_id,omitempty"`
  44. // The GCP integration that was used to create the infra
  45. GCPIntegrationID uint `json:"gcp_integration_id,omitempty"`
  46. // The DO integration that was used to create the infra:
  47. // this points to an OAuthIntegrationID
  48. DOIntegrationID uint `json:"do_integration_id,omitempty"`
  49. // The Azure integration that was used to create the infra
  50. AzureIntegrationID uint `json:"azure_integration_id,omitempty"`
  51. // The last-applied, non-sensitive input variables to the provisioner. For now,
  52. // this is a map[string]string since we marshal into env vars anyway, but
  53. // eventually this config will be more complex.
  54. LastApplied map[string]string `json:"last_applied"`
  55. // LatestOperation is the last operation that was run against this infra, if
  56. // one exists
  57. LatestOperation *Operation `json:"latest_operation"`
  58. }
  59. type InfraCredentials struct {
  60. AWSIntegrationID uint `json:"aws_integration_id,omitempty"`
  61. GCPIntegrationID uint `json:"gcp_integration_id,omitempty"`
  62. DOIntegrationID uint `json:"do_integration_id,omitempty"`
  63. AzureIntegrationID uint `json:"azure_integration_id,omitempty"`
  64. }
  65. type CreateInfraRequest struct {
  66. *InfraCredentials
  67. ClusterID uint `json:"cluster_id"`
  68. Kind string `json:"kind" form:"required"`
  69. Values map[string]interface{} `json:"values" form:"required"`
  70. }
  71. type ListInfraRequest struct {
  72. Version string `schema:"version"`
  73. }
  74. type DeleteInfraRequest struct {
  75. *InfraCredentials
  76. }
  77. type RetryInfraRequest struct {
  78. // Integration IDs are not required -- if they are passed in, they will override the
  79. // existing integration IDs
  80. *InfraCredentials
  81. // Values are not required -- if they are not passed in, the values will be
  82. // automatically populated from the previous operation
  83. Values map[string]interface{} `json:"values"`
  84. }
  85. type OperationMeta struct {
  86. LastUpdated time.Time `json:"last_updated"`
  87. UID string `json:"id"`
  88. InfraID uint `json:"infra_id"`
  89. Type string `json:"type"`
  90. Status string `json:"status"`
  91. Errored bool `json:"errored"`
  92. Error string `json:"error"`
  93. }
  94. type Operation struct {
  95. *OperationMeta
  96. LastApplied map[string]interface{} `json:"last_applied"`
  97. Form *FormYAML `json:"form"`
  98. }
  99. type InfraTemplateMeta struct {
  100. Icon string `json:"icon"`
  101. Description string `json:"description"`
  102. Name string `json:"name"`
  103. Version string `json:"version"`
  104. Kind string `json:"kind"`
  105. RequiredCredential string `json:"required_credential"`
  106. }
  107. type InfraTemplate struct {
  108. *InfraTemplateMeta
  109. Form *FormYAML `json:"form"`
  110. }