MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / convertValue

Function convertValue

pkg/cmd/tenant/variables/update/update.go:1046–1112  ·  view source on GitHub ↗
(opts *UpdateOptions, t *actiontemplates.ActionTemplateParameter)

Source from the content-addressed store, hash-verified

1044}
1045
1046func convertValue(opts *UpdateOptions, t *actiontemplates.ActionTemplateParameter) (*core.PropertyValue, error) {
1047 variableType := resources.ControlType(t.DisplaySettings["Octopus.ControlType"])
1048 value := opts.Value.Value
1049 var err error
1050 switch variableType {
1051 case resources.ControlTypeAwsAccount:
1052 value, err = findAccount(opts, accounts.AccountTypeAmazonWebServicesAccount)
1053 case resources.ControlTypeGoogleCloudAccount:
1054 value, err = findAccount(opts, accounts.AccountTypeGoogleCloudPlatformAccount)
1055 case resources.ControlTypeAzureAccount:
1056 value, err = findAccount(opts, accounts.AccountTypeAzureServicePrincipal)
1057 case resources.ControlTypeWorkerPool:
1058 allWorkerPools, err := opts.GetAllWorkerPools()
1059 if err != nil {
1060 return nil, err
1061 }
1062 matchedWorkerPools := util.SliceFilter(allWorkerPools, func(p *workerpools.WorkerPoolListResult) bool {
1063 return strings.EqualFold(p.Name, opts.Value.Value) || strings.EqualFold(p.ID, opts.Value.Value) || strings.EqualFold(p.Slug, opts.Value.Value)
1064 })
1065 if util.Empty(matchedWorkerPools) {
1066 return nil, fmt.Errorf("cannot find worker pool '%s'", opts.Value.Value)
1067 }
1068 if len(matchedWorkerPools) > 1 {
1069 return nil, fmt.Errorf("matched multiple worker pools")
1070 }
1071
1072 value, err = matchedWorkerPools[0].ID, nil
1073 case resources.ControlTypeCertificate:
1074 allCertificates, err := opts.GetAllCertificates()
1075 if err != nil {
1076 return nil, err
1077 }
1078 matchedCertificate := util.SliceFilter(allCertificates, func(p *certificates.CertificateResource) bool {
1079 return !p.IsExpired && (strings.EqualFold(p.Name, opts.Value.Value) || strings.EqualFold(p.ID, opts.Value.Value))
1080 })
1081 if util.Empty(matchedCertificate) {
1082 return nil, fmt.Errorf("cannot find certifcate '%s'", opts.Value.Value)
1083 }
1084 if len(matchedCertificate) > 1 {
1085 return nil, fmt.Errorf("matched multiple certificates")
1086 }
1087
1088 value, err = matchedCertificate[0].ID, nil
1089 case resources.ControlTypeSelect:
1090 selectionOptions := sharedVariable.GetSelectOptions(t)
1091 for _, o := range selectionOptions {
1092 if strings.EqualFold(o.Display, opts.Value.Value) || strings.EqualFold(o.Value, opts.Value.Value) {
1093 value, err = o.Value, nil
1094 break
1095 }
1096 }
1097
1098 if value == "" {
1099 err = fmt.Errorf("cannot match selection value '%s'", opts.Value.Value)
1100 }
1101 case resources.ControlTypeSensitive:
1102 propertyValue := core.NewPropertyValue(value, true)
1103 return &propertyValue, nil

Callers 4

Calls 3

SliceFilterFunction · 0.92
EmptyFunction · 0.92
findAccountFunction · 0.85

Tested by

no test coverage detected