ecr.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package connect
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/fatih/color"
  6. "github.com/porter-dev/porter/cli/cmd/api"
  7. "github.com/porter-dev/porter/cli/cmd/utils"
  8. )
  9. // ECR creates an ECR integration
  10. func ECR(
  11. client *api.Client,
  12. projectID uint,
  13. ) (uint, error) {
  14. // if project ID is 0, ask the user to set the project ID or create a project
  15. if projectID == 0 {
  16. return 0, fmt.Errorf("no project set, please run porter project set [id]")
  17. }
  18. // query for the access key id
  19. accessKeyID, err := utils.PromptPlaintext(fmt.Sprintf(`AWS Access Key ID: `))
  20. if err != nil {
  21. return 0, err
  22. }
  23. // query for the secret access key
  24. secretKey, err := utils.PromptPlaintext(fmt.Sprintf(`AWS Secret Access Key: `))
  25. if err != nil {
  26. return 0, err
  27. }
  28. // query for the region
  29. region, err := utils.PromptPlaintext(fmt.Sprintf(`AWS Region: `))
  30. if err != nil {
  31. return 0, err
  32. }
  33. // create the aws integration
  34. integration, err := client.CreateAWSIntegration(
  35. context.Background(),
  36. projectID,
  37. &api.CreateAWSIntegrationRequest{
  38. AWSAccessKeyID: accessKeyID,
  39. AWSSecretAccessKey: secretKey,
  40. AWSRegion: region,
  41. },
  42. )
  43. if err != nil {
  44. return 0, err
  45. }
  46. color.New(color.FgGreen).Printf("created aws integration with id %d\n", integration.ID)
  47. // create the registry
  48. // query for registry name
  49. regName, err := utils.PromptPlaintext(fmt.Sprintf(`Give this registry a name: `))
  50. if err != nil {
  51. return 0, err
  52. }
  53. reg, err := client.CreateECR(
  54. context.Background(),
  55. projectID,
  56. &api.CreateECRRequest{
  57. Name: regName,
  58. AWSIntegrationID: integration.ID,
  59. },
  60. )
  61. if err != nil {
  62. return 0, err
  63. }
  64. color.New(color.FgGreen).Printf("created registry with id %d and name %s\n", reg.ID, reg.Name)
  65. return reg.ID, nil
  66. }