MCPcopy Index your code
hub / github.com/devspace-sh/devspace / addPullSecretConfig

Method addPullSecretConfig

pkg/devspace/configure/image.go:223–328  ·  view source on GitHub ↗
(dockerClient docker.Client, image string)

Source from the content-addressed store, hash-verified

221}
222
223func (m *manager) addPullSecretConfig(dockerClient docker.Client, image string) (string, error) {
224 var err error
225 image, _, err = dockerfile.GetStrippedDockerImageName(strings.ToLower(image))
226 if err != nil {
227 return "", err
228 }
229
230 registryHostname, err := pullsecrets.GetRegistryFromImageName(image)
231 if err != nil {
232 return "", err
233 }
234
235 registryHostnamePrintable := registryHostname
236 if registryHostnamePrintable == "" {
237 registryHostnamePrintable = dockerHubHostname
238 }
239
240 usernameQuestion := fmt.Sprintf("What is your username for %s? (optional, Enter to skip)", registryHostnamePrintable)
241 passwordQuestion := fmt.Sprintf("What is your password for %s? (optional, Enter to skip)", registryHostnamePrintable)
242 if strings.Contains(registryHostname, "ghcr.io") || strings.Contains(registryHostname, "github.com") {
243 usernameQuestion = "What is your GitHub username? (optional, Enter to skip)"
244 passwordQuestion = "Please enter a GitHub personal access token (optional, Enter to skip)"
245 }
246
247 registryUsername := ""
248 registryPassword := ""
249 retry := false
250
251 m.log.WriteString(logrus.WarnLevel, "\n")
252
253 for {
254 m.log.Info("Checking registry authentication for " + registryHostnamePrintable + "...")
255 authConfig, err := dockerClient.Login(context.TODO(), registryHostname, registryUsername, registryPassword, true, retry, retry)
256 if err == nil && (authConfig.Username != "" || authConfig.Password != "") {
257 registryUsername = authConfig.Username
258
259 m.log.Donef("Great! You are authenticated with %s", registryHostnamePrintable)
260 break
261 }
262
263 m.log.WriteString(logrus.WarnLevel, "\n")
264 m.log.Warnf("Unable to find registry credentials for %s", registryHostnamePrintable)
265 m.log.Warnf("Running `%s` for you to authenticate with the registry (optional)", strings.TrimSpace("docker login "+registryHostname))
266
267 registryUsername, err = m.log.Question(&survey.QuestionOptions{
268 Question: usernameQuestion,
269 ValidationRegexPattern: "^[^A-Z\\s]+\\.[^A-Z\\s]+$",
270 ValidationMessage: "Error parsing registry username: must only include lowercase letters.",
271 })
272
273 if err != nil {
274 return "", err
275 }
276 if registryUsername != "" {
277 registryPassword, err = m.log.Question(&survey.QuestionOptions{
278 Question: passwordQuestion,
279 ValidationRegexPattern: "^.*$",
280 IsPassword: true,

Callers 1

AddImageMethod · 0.95

Calls 12

GetRegistryFromImageNameFunction · 0.92
ConvertFunction · 0.92
WriteStringMethod · 0.65
LoginMethod · 0.65
QuestionMethod · 0.65
EnvironMethod · 0.65
SetVarMethod · 0.65
InfoMethod · 0.45
DonefMethod · 0.45
WarnfMethod · 0.45
WarnMethod · 0.45

Tested by

no test coverage detected