|
|
@@ -1,7 +1,9 @@
|
|
|
package forms
|
|
|
|
|
|
import (
|
|
|
- cmdutils "github.com/porter-dev/porter/cli/cmd/utils"
|
|
|
+ "math/rand"
|
|
|
+ "time"
|
|
|
+
|
|
|
"github.com/porter-dev/porter/internal/models"
|
|
|
)
|
|
|
|
|
|
@@ -20,7 +22,7 @@ func (ce *CreateECRInfra) ToAWSInfra() (*models.AWSInfra, error) {
|
|
|
return &models.AWSInfra{
|
|
|
Kind: models.AWSInfraECR,
|
|
|
ProjectID: ce.ProjectID,
|
|
|
- Suffix: cmdutils.StringWithCharset(6, randCharset),
|
|
|
+ Suffix: stringWithCharset(6, randCharset),
|
|
|
Status: models.StatusCreating,
|
|
|
AWSIntegrationID: ce.AWSIntegrationID,
|
|
|
}, nil
|
|
|
@@ -39,7 +41,7 @@ func (ce *CreateEKSInfra) ToAWSInfra() (*models.AWSInfra, error) {
|
|
|
return &models.AWSInfra{
|
|
|
Kind: models.AWSInfraEKS,
|
|
|
ProjectID: ce.ProjectID,
|
|
|
- Suffix: cmdutils.StringWithCharset(6, randCharset),
|
|
|
+ Suffix: stringWithCharset(6, randCharset),
|
|
|
Status: models.StatusCreating,
|
|
|
AWSIntegrationID: ce.AWSIntegrationID,
|
|
|
}, nil
|
|
|
@@ -56,3 +58,16 @@ type DestroyECRInfra struct {
|
|
|
type DestroyEKSInfra struct {
|
|
|
EKSName string `json:"eks_name" form:"required"`
|
|
|
}
|
|
|
+
|
|
|
+// helpers for random string
|
|
|
+var seededRand *rand.Rand = rand.New(
|
|
|
+ rand.NewSource(time.Now().UnixNano()))
|
|
|
+
|
|
|
+// stringWithCharset returns a random string by pulling from a given charset
|
|
|
+func stringWithCharset(length int, charset string) string {
|
|
|
+ b := make([]byte, length)
|
|
|
+ for i := range b {
|
|
|
+ b[i] = charset[seededRand.Intn(len(charset))]
|
|
|
+ }
|
|
|
+ return string(b)
|
|
|
+}
|