MCPcopy
hub / github.com/smallstep/cli / promptDeploymentType

Function promptDeploymentType

command/ca/init.go:754–812  ·  view source on GitHub ↗
(ctx *cli.Context, isRA bool)

Source from the content-addressed store, hash-verified

752}
753
754func promptDeploymentType(ctx *cli.Context, isRA bool) (pki.DeploymentType, error) {
755 type deployment struct {
756 Name string
757 Description string
758 Value pki.DeploymentType
759 }
760
761 var deploymentTypes []deployment
762 deploymentType := strings.ToLower(ctx.String("deployment-type"))
763
764 // Assume standalone for backward compatibility if all required flags are
765 // passed.
766 if deploymentType == "" && isNonInteractiveInit(ctx) {
767 return pki.StandaloneDeployment, nil
768 }
769
770 deploymentTypes = []deployment{
771 {"Standalone", "step-ca instance you run yourself", pki.StandaloneDeployment},
772 {"Linked", "standalone, plus cloud configuration, reporting & alerting", pki.LinkedDeployment},
773 {"Hosted", "fully-managed step-ca cloud instance run for you by smallstep", pki.HostedDeployment},
774 }
775
776 if isRA {
777 switch deploymentType {
778 case "":
779 // Deployment type Hosted is not supported for RAs
780 deploymentTypes = deploymentTypes[:2]
781 case "standalone":
782 return pki.StandaloneDeployment, nil
783 case "linked":
784 return pki.LinkedDeployment, nil
785 default:
786 return 0, errs.InvalidFlagValue(ctx, "deployment-type", deploymentType, "standalone or linked")
787 }
788 } else {
789 switch deploymentType {
790 case "":
791 case "standalone":
792 return pki.StandaloneDeployment, nil
793 case "linked":
794 return pki.LinkedDeployment, nil
795 case "hosted":
796 return pki.HostedDeployment, nil
797 default:
798 return 0, errs.InvalidFlagValue(ctx, "deployment-type", deploymentType, "standalone, linked or hosted")
799 }
800 }
801
802 i, _, err := ui.Select("What deployment type would you like to configure?", deploymentTypes,
803 ui.WithSelectTemplates(&promptui.SelectTemplates{
804 Active: fmt.Sprintf("%s {{ printf \"%%s - %%s\" .Name .Description | underline }}", ui.IconSelect),
805 Inactive: " {{ .Name }} - {{ .Description }}",
806 Selected: fmt.Sprintf(`{{ %q | green }} {{ "Deployment Type:" | bold }} {{ .Name }}`, ui.IconGood),
807 }))
808 if err != nil {
809 return 0, err
810 }
811 return deploymentTypes[i].Value, nil

Callers 1

initActionFunction · 0.85

Calls 2

isNonInteractiveInitFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…