forked from notaryproject/notation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sylvia Lei <[email protected]>
- Loading branch information
Showing
15 changed files
with
157 additions
and
699 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"oras.land/oras-go/v2/registry/remote/auth" | ||
) | ||
|
||
func TestSecureFlagOpts_Credential(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
opts *SecureFlagOpts | ||
want auth.Credential | ||
}{ | ||
{ | ||
name: "Username and password", | ||
opts: &SecureFlagOpts{ | ||
Username: "username", | ||
Password: "password", | ||
}, | ||
want: auth.Credential{ | ||
Username: "username", | ||
Password: "password", | ||
}, | ||
}, | ||
{ | ||
name: "Username only", | ||
opts: &SecureFlagOpts{ | ||
Username: "username", | ||
}, | ||
want: auth.Credential{ | ||
Username: "username", | ||
}, | ||
}, | ||
{ | ||
name: "Password only", | ||
opts: &SecureFlagOpts{ | ||
Password: "token", | ||
}, | ||
want: auth.Credential{ | ||
RefreshToken: "token", | ||
}, | ||
}, | ||
{ | ||
name: "Empty username and password", | ||
opts: &SecureFlagOpts{ | ||
Username: "", | ||
Password: "", | ||
}, | ||
want: auth.EmptyCredential, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := tt.opts.Credential(); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("SecureFlagOpts.Credential() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package auth | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/notaryproject/notation-go/dir" | ||
credentials "github.com/oras-project/oras-credentials-go" | ||
) | ||
|
||
// NewCredentialsStore returns a new credentials store from the settings in the | ||
// configuration file. | ||
func NewCredentialsStore() (credentials.Store, error) { | ||
configPath, err := dir.ConfigFS().SysPath(dir.PathConfigFile) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to load config file: %w", err) | ||
} | ||
|
||
opts := credentials.StoreOptions{AllowPlaintextPut: false} | ||
primaryStore, err := credentials.NewStore(configPath, opts) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create credential store from config file: %w", err) | ||
} | ||
|
||
fallbackStore, err := credentials.NewStoreFromDocker(opts) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create credential store from docker config file: %w", err) | ||
} | ||
return credentials.NewStoreWithFallbacks(primaryStore, fallbackStore), nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.