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

Method createPullSecret

pkg/devspace/pullsecrets/init.go:165–215  ·  view source on GitHub ↗
(ctx devspacecontext.Context, dockerClient docker.Client, pullSecret *latest.PullSecretConfig)

Source from the content-addressed store, hash-verified

163}
164
165func (r *client) createPullSecret(ctx devspacecontext.Context, dockerClient docker.Client, pullSecret *latest.PullSecretConfig) error {
166 username := pullSecret.Username
167 password := pullSecret.Password
168 if username == "" && password == "" && dockerClient != nil {
169 authConfig, err := dockerClient.GetAuthConfig(ctx.Context(), pullSecret.Registry, true)
170 if authConfig != nil {
171 username = authConfig.Username
172 password = authConfig.Password
173
174 if password == "" && authConfig.IdentityToken != "" {
175 password = authConfig.IdentityToken
176 }
177
178 // Handle Azure Container Registry (ACR) when credentials helper does not provide a username
179 // https://learn.microsoft.com/en-us/azure/container-registry/container-registry-authentication?tabs=azure-cli#az-acr-login-with---expose-token
180 if username == "" && IsAzureContainerRegistry(authConfig.ServerAddress) {
181 username = AzureContainerRegistryUsername
182 }
183 } else if err != nil {
184 ctx.Log().Debugf("Error retrieving docker credentials for registry %s: %v", pullSecret.Registry, err)
185 }
186 }
187
188 email := pullSecret.Email
189 if email == "" {
190 email = "noreply@devspace.sh"
191 }
192
193 if username != "" && password != "" {
194 err := r.CreatePullSecret(ctx, &PullSecretOptions{
195 Namespace: ctx.KubeClient().Namespace(),
196 RegistryURL: pullSecret.Registry,
197 Username: username,
198 PasswordOrToken: password,
199 Email: email,
200 Secret: pullSecret.Secret,
201 })
202 if err != nil {
203 return err
204 }
205 } else {
206 if username == "" {
207 ctx.Log().Warnf("Couldn't retrieve username for registry %s from docker store", pullSecret.Registry)
208 }
209 if password == "" {
210 ctx.Log().Warnf("Couldn't retrieve password for registry %s from docker store", pullSecret.Registry)
211 }
212 }
213
214 return nil
215}

Callers 1

ensurePullSecretMethod · 0.95

Calls 9

CreatePullSecretMethod · 0.95
IsAzureContainerRegistryFunction · 0.85
GetAuthConfigMethod · 0.65
ContextMethod · 0.65
LogMethod · 0.65
NamespaceMethod · 0.65
KubeClientMethod · 0.65
DebugfMethod · 0.45
WarnfMethod · 0.45

Tested by

no test coverage detected