Skip to content
This repository has been archived by the owner on Apr 7, 2024. It is now read-only.

Commit

Permalink
resovled comments
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 committed Apr 27, 2023
1 parent edfb375 commit c734dc8
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,60 +22,68 @@ import (
)

func ExampleNewStoreFromDocker() {
ds, err := credentials.NewStoreFromDocker(credentials.StoreOptions{AllowPlaintextPut: true})
ds, err := credentials.NewStoreFromDocker(credentials.StoreOptions{
AllowPlaintextPut: true,
})
if err != nil {
panic(err)
}

ctx := context.Background()
// save credentials into the store
err = ds.Put(context.Background(), "localhost:8080",
err = ds.Put(ctx, "localhost:5000",
auth.Credential{
Username: "username-example",
Password: "password-example"})
Password: "password-example",
})
if err != nil {
panic(err)
}

// get credentials from the store
cred, err := ds.Get(context.Background(), "localhost:8080")
cred, err := ds.Get(ctx, "localhost:5000")
if err != nil {
panic(err)
}
fmt.Println(cred)

// delete the credentials from the store
err = ds.Delete(context.Background(), "localhost:8080")
err = ds.Delete(ctx, "localhost:5000")
if err != nil {
panic(err)
}
}

func ExampleNewStoreWithFallbacks() {
primaryStore, err := credentials.NewStore("example/path/config.json", credentials.StoreOptions{AllowPlaintextPut: true})
func ExampleNewStoreWithFallbacks_configAsPrimaryStoreDockerAsFallback() {
primaryStore, err := credentials.NewStore("example/path/config.json", credentials.StoreOptions{
AllowPlaintextPut: true,
})
if err != nil {
panic(err)
}
fallbackStore, err := credentials.NewStoreFromDocker(credentials.StoreOptions{})
sf := credentials.NewStoreWithFallbacks(primaryStore, fallbackStore)

ctx := context.Background()
// save credentials into the store
err = sf.Put(context.Background(), "localhost:8080",
err = sf.Put(ctx, "localhost:5000",
auth.Credential{
Username: "username-example",
Password: "password-example"})
Password: "password-example",
})
if err != nil {
panic(err)
}

// get credentials from the store
cred, err := sf.Get(context.Background(), "localhost:8080")
cred, err := sf.Get(ctx, "localhost:5000")
if err != nil {
panic(err)
}
fmt.Println(cred)

// delete the credentials from the store
err = sf.Delete(context.Background(), "localhost:8080")
err = sf.Delete(ctx, "localhost:5000")
if err != nil {
panic(err)
}
Expand Down

0 comments on commit c734dc8

Please sign in to comment.