|
|
@@ -1,6 +1,7 @@
|
|
|
package models
|
|
|
|
|
|
import (
|
|
|
+ "encoding/json"
|
|
|
"fmt"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
@@ -8,6 +9,7 @@ import (
|
|
|
"gorm.io/gorm"
|
|
|
|
|
|
"github.com/porter-dev/porter/api/types"
|
|
|
+ "github.com/porter-dev/porter/internal/kubernetes/provisioner/input"
|
|
|
)
|
|
|
|
|
|
// Infra represents the metadata for an infrastructure type provisioned on
|
|
|
@@ -51,13 +53,94 @@ type Infra struct {
|
|
|
// ToInfraType generates an external Infra to be shared over REST
|
|
|
func (i *Infra) ToInfraType() *types.Infra {
|
|
|
return &types.Infra{
|
|
|
- ID: i.ID,
|
|
|
- ProjectID: i.ProjectID,
|
|
|
- Kind: i.Kind,
|
|
|
- Status: i.Status,
|
|
|
+ ID: i.ID,
|
|
|
+ ProjectID: i.ProjectID,
|
|
|
+ Kind: i.Kind,
|
|
|
+ Status: i.Status,
|
|
|
+ AWSIntegrationID: i.AWSIntegrationID,
|
|
|
+ DOIntegrationID: i.DOIntegrationID,
|
|
|
+ GCPIntegrationID: i.GCPIntegrationID,
|
|
|
+ LastApplied: i.SafelyGetLastApplied(),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// SafeGetLastApplied gets non-sensitive values for the last applied configuration
|
|
|
+func (i *Infra) SafelyGetLastApplied() map[string]string {
|
|
|
+ resp := make(map[string]string)
|
|
|
+
|
|
|
+ switch i.Kind {
|
|
|
+ case types.InfraECR:
|
|
|
+ lastApplied := &input.ECR{}
|
|
|
+
|
|
|
+ if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
|
|
|
+ return resp
|
|
|
+ }
|
|
|
+
|
|
|
+ resp["region"] = lastApplied.AWSRegion
|
|
|
+
|
|
|
+ return resp
|
|
|
+ case types.InfraEKS:
|
|
|
+ lastApplied := &input.EKS{}
|
|
|
+
|
|
|
+ if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
|
|
|
+ return resp
|
|
|
+ }
|
|
|
+
|
|
|
+ resp["region"] = lastApplied.AWSRegion
|
|
|
+ resp["cluster_name"] = lastApplied.ClusterName
|
|
|
+ resp["machine_type"] = lastApplied.MachineType
|
|
|
+
|
|
|
+ return resp
|
|
|
+ case types.InfraGCR:
|
|
|
+ lastApplied := &input.GCR{}
|
|
|
+
|
|
|
+ if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
|
|
|
+ return resp
|
|
|
+ }
|
|
|
+
|
|
|
+ resp["project_id"] = lastApplied.GCPProjectID
|
|
|
+ resp["region"] = lastApplied.GCPRegion
|
|
|
+
|
|
|
+ return resp
|
|
|
+ case types.InfraGKE:
|
|
|
+ lastApplied := &input.GKE{}
|
|
|
+
|
|
|
+ if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
|
|
|
+ return resp
|
|
|
+ }
|
|
|
+
|
|
|
+ resp["project_id"] = lastApplied.GCPProjectID
|
|
|
+ resp["region"] = lastApplied.GCPRegion
|
|
|
+ resp["cluster_name"] = lastApplied.ClusterName
|
|
|
+
|
|
|
+ return resp
|
|
|
+ case types.InfraDOCR:
|
|
|
+ lastApplied := &input.DOCR{}
|
|
|
+
|
|
|
+ if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
|
|
|
+ return resp
|
|
|
+ }
|
|
|
+
|
|
|
+ resp["name"] = lastApplied.DOCRName
|
|
|
+ resp["subscription_tier"] = lastApplied.DOCRSubscriptionTier
|
|
|
+
|
|
|
+ return resp
|
|
|
+ case types.InfraDOKS:
|
|
|
+ lastApplied := &input.DOKS{}
|
|
|
+
|
|
|
+ if err := json.Unmarshal(i.LastApplied, lastApplied); err != nil {
|
|
|
+ return resp
|
|
|
+ }
|
|
|
+
|
|
|
+ resp["cluster_name"] = lastApplied.ClusterName
|
|
|
+ resp["region"] = lastApplied.DORegion
|
|
|
+
|
|
|
+ return resp
|
|
|
+ }
|
|
|
+
|
|
|
+ return resp
|
|
|
+}
|
|
|
+
|
|
|
// GetID returns the unique id for this infra
|
|
|
func (i *Infra) GetUniqueName() string {
|
|
|
return fmt.Sprintf("%s-%d-%d-%s", i.Kind, i.ProjectID, i.ID, i.Suffix)
|