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

Function NewClientFactoryFromConfig

pkg/apiclient/client_factory.go:113–154  ·  view source on GitHub ↗

NewClientFactoryFromConfig Creates a new Client wrapper structure by reading the viper config. specifies nil for the HTTP Client, so this is not for unit tests; use NewClientFactory(... instead)

(ask question.AskProvider)

Source from the content-addressed store, hash-verified

111// NewClientFactoryFromConfig Creates a new Client wrapper structure by reading the viper config.
112// specifies nil for the HTTP Client, so this is not for unit tests; use NewClientFactory(... instead)
113func NewClientFactoryFromConfig(ask question.AskProvider) (ClientFactory, error) {
114 host := viper.GetString(constants.ConfigUrl)
115 apiKey := viper.GetString(constants.ConfigApiKey)
116 accessToken := viper.GetString(constants.ConfigAccessToken)
117 spaceNameOrID := viper.GetString(constants.ConfigSpace)
118
119 errs := ValidateMandatoryEnvironment(host, apiKey, accessToken, ask.IsInteractive())
120 if errs != nil {
121 return nil, errs
122 }
123
124 var httpClient *http.Client
125 http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
126 if ask.IsInteractive() {
127 // spinner round-tripper only needed for interactive mode
128 httpClient = &http.Client{
129 Transport: NewSpinnerRoundTripper(),
130 }
131 }
132
133 var credentials octopusApiClient.ICredential
134
135 if apiKey != "" {
136 apiKeyCredential, err := octopusApiClient.NewApiKey(apiKey)
137
138 if err != nil {
139 return nil, err
140 }
141
142 credentials = apiKeyCredential
143 } else if accessToken != "" {
144 accessTokenCredential, err := octopusApiClient.NewAccessToken(accessToken)
145
146 if err != nil {
147 return nil, err
148 }
149
150 credentials = accessTokenCredential
151 }
152
153 return NewClientFactory(httpClient, host, credentials, spaceNameOrID, ask)
154}
155
156func ValidateMandatoryEnvironment(host string, apiKey string, accessToken string, isInteractive bool) error {
157

Callers 1

mainFunction · 0.92

Calls 4

NewSpinnerRoundTripperFunction · 0.85
NewClientFactoryFunction · 0.85
IsInteractiveMethod · 0.65

Tested by

no test coverage detected