@@ -11,12 +11,12 @@ import (
11
11
"strings"
12
12
13
13
"github.com/defenseunicorns/pkg/helpers/v2"
14
- "github.com/docker/cli/cli/config"
15
- "github.com/docker/cli/cli/config/configfile"
16
14
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
17
15
"oras.land/oras-go/v2/registry"
18
16
"oras.land/oras-go/v2/registry/remote"
19
17
"oras.land/oras-go/v2/registry/remote/auth"
18
+ "oras.land/oras-go/v2/registry/remote/credentials"
19
+ "oras.land/oras-go/v2/registry/remote/retry"
20
20
)
21
21
22
22
const (
@@ -136,56 +136,20 @@ func (o *OrasRemote) setRepository(ref registry.Reference) error {
136
136
ref .Registry = "ghcr.io"
137
137
ref .Repository = "defenseunicorns/packages/" + ref .Repository
138
138
}
139
- client , err := o .createAuthClient (ref )
139
+ storeOpts := credentials.StoreOptions {}
140
+ credStore , err := credentials .NewStoreFromDocker (storeOpts )
140
141
if err != nil {
141
- return err
142
+ return fmt . Errorf ( "failed to get credentials: %w" , err )
142
143
}
144
+ client := & auth.Client {
145
+ Client : retry .DefaultClient ,
146
+ Cache : auth .NewCache (),
147
+ Credential : credentials .Credential (credStore ),
148
+ }
149
+ o .log .Debug ("gathering credentials from default Docker config file" , "credentials_configured" , credStore .IsAuthConfigured ())
143
150
144
151
o .repo .Reference = ref
145
152
o .repo .Client = client
146
153
147
154
return nil
148
155
}
149
-
150
- // createAuthClient returns an auth client for the given reference.
151
- //
152
- // The credentials are pulled using Docker's default credential store.
153
- //
154
- // TODO: instead of using Docker's cred store, should use the new one from ORAS to remove that dep
155
- func (o * OrasRemote ) createAuthClient (ref registry.Reference ) (* auth.Client , error ) {
156
-
157
- client := o .repo .Client .(* auth.Client )
158
- o .log .Debug (fmt .Sprintf ("Loading docker config file from default config location: %s for %s" , config .Dir (), ref ))
159
- cfg , err := config .Load (config .Dir ())
160
- if err != nil {
161
- return nil , err
162
- }
163
- if ! cfg .ContainsAuth () {
164
- o .log .Debug ("no docker config file found" )
165
- return client , nil
166
- }
167
-
168
- configs := []* configfile.ConfigFile {cfg }
169
-
170
- var key = ref .Registry
171
- if key == "registry-1.docker.io" {
172
- // Docker stores its credentials under the following key, otherwise credentials use the registry URL
173
- key = "https://index.docker.io/v1/"
174
- }
175
-
176
- authConf , err := configs [0 ].GetCredentialsStore (key ).Get (key )
177
- if err != nil {
178
- return nil , fmt .Errorf ("unable to get credentials for %s: %w" , key , err )
179
- }
180
-
181
- cred := auth.Credential {
182
- Username : authConf .Username ,
183
- Password : authConf .Password ,
184
- AccessToken : authConf .RegistryToken ,
185
- RefreshToken : authConf .IdentityToken ,
186
- }
187
-
188
- client .Credential = auth .StaticCredential (ref .Registry , cred )
189
-
190
- return client , nil
191
- }
0 commit comments