func downloadOCI()

in cmd/resource/utils.go [761:820]


func downloadOCI(endpoint, manifest, username, password, file string) error {
	fullName := fmt.Sprintf("%s/%s", endpoint, manifest)
	ctx := orascontext.Background()
	memoryStore := orascontent.NewMemoryStore()
	headers := http.Header{}
	headers.Set("User-Agent", "CloudFormation-Helm-Resource-Provider")
	var authorizerOpt []docker.AuthorizerOpt
	authorizerOpt = append(authorizerOpt, docker.WithAuthClient(http.DefaultClient), docker.WithAuthHeader(headers))
	if !IsZero(username) && !IsZero(password) {
		authorizerOpt = append(authorizerOpt, docker.WithAuthCreds(func(host string) (string, string, error) {
			host = endpoint
			return username, password, nil
		}))
	}
	authorizer := docker.NewDockerAuthorizer(authorizerOpt...)

	regHosts := func(host string) ([]docker.RegistryHost, error) {
		host = endpoint
		config := docker.RegistryHost{
			Client:       http.DefaultClient,
			Authorizer:   authorizer,
			Scheme:       "https",
			Path:         "/v2",
			Host:         endpoint,
			Header:       headers,
			Capabilities: docker.HostCapabilityPull | docker.HostCapabilityResolve,
		}
		return []docker.RegistryHost{config}, nil

	}

	resolver := docker.NewResolver(docker.ResolverOptions{
		Hosts:   regHosts,
		Headers: headers,
	})

	_, content, err := oras.Pull(ctx, resolver, fullName, memoryStore,
		oras.WithPullEmptyNameAllowed(),
		oras.WithAllowedMediaTypes(HelmKnownMediaTypes()))

	if err != nil {
		return genericError("Downloading", fmt.Errorf("pull failed %s, Error: %s", fullName, err))
	}

	if len(content) != 1 {
		return genericError("Checking downloaded content", fmt.Errorf("%s has invalid configuration", fullName))
	}

	_, bytes, ok := memoryStore.Get(content[0])
	if !ok {
		return err
	}

	err = ioutil.WriteFile(file, bytes, 0644)
	if err != nil {
		return genericError("Writing file", err)
	}
	log.Printf("Downloaded %s ", file)
	return nil
}