registry.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // Helm connects a Helm repository using HTTP basic authentication
  10. func Registry(
  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 helm repo name
  19. repoURL, err := utils.PromptPlaintext(fmt.Sprintf(`Provide the image registry URL (include the protocol). For example, https://my-custom-registry.getporter.dev.
  20. Image registry URL: `))
  21. if err != nil {
  22. return 0, err
  23. }
  24. username, err := utils.PromptPlaintext(fmt.Sprintf(`Provide the username/password for authentication (press enter if no authenicaiton is required).
  25. Username: `))
  26. if err != nil {
  27. return 0, err
  28. }
  29. password, err := utils.PromptPasswordWithConfirmation()
  30. if err != nil {
  31. return 0, err
  32. }
  33. // create the basic auth integration
  34. integration, err := client.CreateBasicAuthIntegration(
  35. context.Background(),
  36. projectID,
  37. &api.CreateBasicAuthIntegrationRequest{
  38. Username: username,
  39. Password: password,
  40. },
  41. )
  42. if err != nil {
  43. return 0, err
  44. }
  45. color.New(color.FgGreen).Printf("created basic auth integration with id %d\n", integration.ID)
  46. reg, err := client.CreatePrivateRegistry(
  47. context.Background(),
  48. projectID,
  49. &api.CreatePrivateRegistryRequest{
  50. URL: repoURL,
  51. Name: repoURL,
  52. BasicIntegrationID: integration.ID,
  53. },
  54. )
  55. if err != nil {
  56. return 0, err
  57. }
  58. color.New(color.FgGreen).Printf("created private registry with id %d and name %s\n", reg.ID, reg.Name)
  59. return reg.ID, nil
  60. }