Skip to content

Commit

Permalink
fixed ecr test, cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
thejosephstevens committed Oct 16, 2024
1 parent cc7356d commit 2a3f985
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions oci/auth/login/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package login

import (
"fmt"
"time"

"github.com/google/go-containerregistry/pkg/authn"
Expand All @@ -32,13 +33,20 @@ func cacheObject[T authn.Authenticator](store cache.Expirable[cache.StoreObject[

err := store.Set(obj)
if err != nil {
fmt.Println("error setting object", err)
return err
}
fmt.Println("object set")

return store.SetExpiration(obj, expiresAt)
}

func getObjectFromCache[T authn.Authenticator](cache cache.Expirable[cache.StoreObject[T]], key string) (T, bool, error) {
val, exists, err := cache.GetByKey(key)
keys, err := cache.ListKeys()
if err != nil {
return val.Object, false, err
}
fmt.Println("keys", keys)
return val.Object, exists, err
}
6 changes: 6 additions & 0 deletions oci/auth/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,17 @@ func (m *Manager) Login(ctx context.Context, url string, ref name.Reference, opt

switch provider {
case oci.ProviderAWS:
fmt.Println("logging in to AWS ECR")
auth, expiresAt, err := m.ecr.LoginWithExpiry(ctx, opts.AwsAutoLogin, url)
fmt.Println("auth", auth)
fmt.Println("expiresAt", expiresAt)
fmt.Println("err", err)
if err != nil {
return nil, err
}
fmt.Println("opts.cache", opts.Cache)
if opts.Cache != nil {
fmt.Println("caching auth object")
err := cacheObject(opts.Cache, auth, key, expiresAt)
if err != nil {
logr.FromContextOrDiscard(ctx).Error(err, "failed to cache auth object")
Expand Down
2 changes: 1 addition & 1 deletion oci/auth/login/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestLogin_WithCache(t *testing.T) {
}{
{
name: "ecr",
responseBody: fmt.Sprintf(`{"authorizationData": [{"authorizationToken": "c29tZS1rZXk6c29tZS1zZWNyZXQ=","expiresAt": "%s"}]}`, timestamp.Format(time.RFC3339)),
responseBody: fmt.Sprintf(`{"authorizationData": [{"authorizationToken": "c29tZS1rZXk6c29tZS1zZWNyZXQ=","expiresAt": %d}]}`, timestamp.Unix()),
providerOpts: ProviderOptions{AwsAutoLogin: true},
beforeFunc: func(serverURL string, mgr *Manager, image *string) {
// Create ECR client and configure the manager.
Expand Down

0 comments on commit 2a3f985

Please sign in to comment.