func checkRegistry()

in controllers/integrationsecret/integrationsecret_controller.go [212:256]


func checkRegistry(ctx context.Context, secret *corev1.Secret) error {
	rawConf := secret.Data[".dockerconfigjson"]

	if len(rawConf) == 0 {
		return fmt.Errorf("no .dockerconfigjson key in secret %s", secret.Name)
	}

	var conf registryConfig
	if err := json.Unmarshal(rawConf, &conf); err != nil {
		return fmt.Errorf("failed to unmarshal .dockerconfigjson: %w", err)
	}

	for url, auth := range conf.Auths {
		// for docker hub we need to use custom endpoint
		// see https://github.com/GoogleContainerTools/kaniko/blob/v1.19.0/README.md?plain=1#L540
		if url == "https://index.docker.io/v1/" {
			return checkDockerHub(ctx, auth.Username, auth.Password)
		}

		if !strings.HasPrefix(url, "https://") {
			url = "https://" + url
		}

		if strings.HasPrefix(url, "https://ghcr.io") {
			return checkGitHubRegistry(ctx, auth, url)
		}

		log := ctrl.LoggerFrom(ctx).WithValues(logKeyUrl, url+"/v2/")
		log.Info("Making request")

		// docker registry specification endpoint https://github.com/opencontainers/distribution-spec/blob/v1.0.1/spec.md#endpoints
		resp, err := newRequest(ctx, url).SetBasicAuth(auth.Username, auth.Password).Get("/v2/")
		if err != nil {
			return fmt.Errorf("%w", err)
		}

		if !resp.IsSuccess() {
			return fmt.Errorf("http status code %s", resp.Status())
		}

		return nil
	}

	return errors.New("no auths in .dockerconfigjson")
}