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

Function accountCreate

pkg/executor/account.go:34–107  ·  view source on GitHub ↗
(octopus *client.Client, _ *spaces.Space, input any)

Source from the content-addressed store, hash-verified

32}
33
34func accountCreate(octopus *client.Client, _ *spaces.Space, input any) error {
35 params, ok := input.(*TaskOptionsCreateAccount)
36 if !ok {
37 return errors.New("invalid input type; expecting TaskOptionsCreateAccount")
38 }
39
40 // TODO should we validate these here, or should we assume that the outer code has already validated them?
41 // most of the lines of code here are validation
42 accountName := params.Name
43 if params.Name == "" {
44 return errors.New("must specify account name")
45 }
46
47 var account accounts.IAccount = nil
48 switch params.Type {
49 // Note the Command Processor will have screened and converted any user input first,
50 // so if we want to be nice and allow multiple options with the same meaning, that is the place to handle it,
51 // rather than here
52 case AccountTypeUsernamePassword:
53 options, ok := params.Options.(TaskOptionsCreateAccountUsernamePassword)
54 if !ok {
55 return errors.New("options must be TaskInputCreateAccountUsernamePassword")
56 }
57
58 p, err := accounts.NewUsernamePasswordAccount(accountName)
59 if err != nil {
60 return err
61 }
62 account = p
63
64 if options.Username == "" {
65 return errors.New("must specify username")
66 }
67 p.Username = options.Username
68
69 if !options.Password.HasValue {
70 return errors.New("must specify password")
71 }
72 p.Password = options.Password
73
74 case AccountTypeToken:
75 options, ok := params.Options.(TaskOptionsCreateAccountToken)
76 if !ok {
77 return errors.New("options must be TaskInputCreateAccountUsernamePassword")
78 }
79
80 if !options.Token.HasValue {
81 return errors.New("must specify token")
82 }
83
84 p, err := accounts.NewTokenAccount(accountName, options.Token)
85 if err != nil {
86 return err
87 }
88 account = p
89
90 // TODO AWS, Azure, Google accounts etc
91

Callers 1

ProcessTasksFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected