Get config more directly
This commit is contained in:
@@ -63,6 +63,7 @@ var _migration string
|
|||||||
// Image is a Docker image build using buildkit.
|
// Image is a Docker image build using buildkit.
|
||||||
type Image struct {
|
type Image struct {
|
||||||
docker Client
|
docker Client
|
||||||
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annotate provides a description of the Image resource.
|
// Annotate provides a description of the Image resource.
|
||||||
@@ -331,22 +332,20 @@ func (is *ImageState) Annotate(a infer.Annotator) {
|
|||||||
|
|
||||||
// client produces a CLI client scoped to this resource and layered on top of
|
// client produces a CLI client scoped to this resource and layered on top of
|
||||||
// any host-level credentials.
|
// any host-level credentials.
|
||||||
func (i *Image) client(ctx context.Context, state ImageState, args ImageArgs) (Client, error) {
|
func (i *Image) client(_ context.Context, state ImageState, args ImageArgs) (Client, error) {
|
||||||
// Use our mock client, if it's set.
|
// Use our mock client, if it's set.
|
||||||
if i.docker != nil {
|
if i.docker != nil {
|
||||||
return i.docker, nil
|
return i.docker, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := infer.GetConfig[Config](ctx)
|
|
||||||
|
|
||||||
// We prefer auth from args, the provider, and state in that order. We
|
// We prefer auth from args, the provider, and state in that order. We
|
||||||
// build a slice in reverse order because wrap() will overwrite earlier
|
// build a slice in reverse order because wrap() will overwrite earlier
|
||||||
// entries with later ones.
|
// entries with later ones.
|
||||||
auths := []Registry{}
|
auths := []Registry{}
|
||||||
auths = append(auths, cfg.Registries...)
|
auths = append(auths, i.config.Registries...)
|
||||||
auths = append(auths, args.Registries...)
|
auths = append(auths, args.Registries...)
|
||||||
|
|
||||||
return wrap(cfg.host, auths...)
|
return wrap(i.config.host, auths...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check validates ImageArgs, sets defaults, and ensures our client is
|
// Check validates ImageArgs, sets defaults, and ensures our client is
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ var _indexExamples string
|
|||||||
// Index is an OCI index or manifest list on a remote registry.
|
// Index is an OCI index or manifest list on a remote registry.
|
||||||
type Index struct {
|
type Index struct {
|
||||||
docker Client
|
docker Client
|
||||||
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// IndexArgs instantiate an Index.
|
// IndexArgs instantiate an Index.
|
||||||
@@ -349,7 +350,7 @@ func (i *Index) Diff(
|
|||||||
// client produces a CLI client scoped to this resource and layered on top of
|
// client produces a CLI client scoped to this resource and layered on top of
|
||||||
// any host-level credentials.
|
// any host-level credentials.
|
||||||
func (i *Index) client(
|
func (i *Index) client(
|
||||||
ctx context.Context,
|
_ context.Context,
|
||||||
_ IndexState,
|
_ IndexState,
|
||||||
args IndexArgs,
|
args IndexArgs,
|
||||||
) (Client, error) {
|
) (Client, error) {
|
||||||
@@ -358,16 +359,14 @@ func (i *Index) client(
|
|||||||
return i.docker, nil
|
return i.docker, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := infer.GetConfig[Config](ctx)
|
|
||||||
|
|
||||||
// We prefer auth from args, the provider, and state in that order. We
|
// We prefer auth from args, the provider, and state in that order. We
|
||||||
// build a slice in reverse order because wrap() will overwrite earlier
|
// build a slice in reverse order because wrap() will overwrite earlier
|
||||||
// entries with later ones.
|
// entries with later ones.
|
||||||
auths := []Registry{}
|
auths := []Registry{}
|
||||||
auths = append(auths, cfg.Registries...)
|
auths = append(auths, i.config.Registries...)
|
||||||
if args.Registry != nil {
|
if args.Registry != nil {
|
||||||
auths = append(auths, *args.Registry)
|
auths = append(auths, *args.Registry)
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrap(cfg.host, auths...)
|
return wrap(i.config.host, auths...)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,8 @@ func (c *Config) Configure(ctx context.Context) error {
|
|||||||
|
|
||||||
// NewBuildxProvider returns a new buildx provider.
|
// NewBuildxProvider returns a new buildx provider.
|
||||||
func NewBuildxProvider(mock Client) provider.Provider {
|
func NewBuildxProvider(mock Client) provider.Provider {
|
||||||
|
config := &Config{}
|
||||||
|
|
||||||
prov := infer.Provider(
|
prov := infer.Provider(
|
||||||
infer.Options{
|
infer.Options{
|
||||||
Metadata: pschema.Metadata{
|
Metadata: pschema.Metadata{
|
||||||
@@ -111,13 +113,13 @@ func NewBuildxProvider(mock Client) provider.Provider {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Resources: []infer.InferredResource{
|
Resources: []infer.InferredResource{
|
||||||
infer.Resource(&Image{docker: mock}),
|
infer.Resource(&Image{docker: mock, config: config}),
|
||||||
infer.Resource(&Index{docker: mock}),
|
infer.Resource(&Index{docker: mock, config: config}),
|
||||||
},
|
},
|
||||||
ModuleMap: map[tokens.ModuleName]tokens.ModuleName{
|
ModuleMap: map[tokens.ModuleName]tokens.ModuleName{
|
||||||
"internal": "index",
|
"internal": "index",
|
||||||
},
|
},
|
||||||
Config: infer.Config(&Config{}),
|
Config: infer.Config(config),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user