()
| 10 | ) |
| 11 | |
| 12 | func ExampleCredHub() { |
| 13 | _ = func() { |
| 14 | // Use a CredHub server on "https://example.com" using UAA password grant |
| 15 | ch, err := credhub.New("https://example.com", |
| 16 | credhub.SkipTLSValidation(true), |
| 17 | credhub.Auth(auth.UaaPassword("credhub_cli", "", "username", "password"))) |
| 18 | |
| 19 | if err != nil { |
| 20 | panic("credhub client configured incorrectly: " + err.Error()) |
| 21 | } |
| 22 | |
| 23 | authUrl, err := ch.AuthURL() |
| 24 | if err != nil { |
| 25 | panic("couldn't fetch authurl") |
| 26 | } |
| 27 | |
| 28 | fmt.Println("CredHub server: ", ch.ApiURL) |
| 29 | fmt.Println("Auth server: ", authUrl) |
| 30 | |
| 31 | // Retrieve a password stored at "/my/password" |
| 32 | password, err := ch.GetLatestPassword("/my/password") |
| 33 | if err != nil { |
| 34 | panic("password not found") |
| 35 | } |
| 36 | |
| 37 | fmt.Println("My password: ", password.Value) |
| 38 | |
| 39 | // Manually refresh the access token |
| 40 | uaa, ok := ch.Auth.(*auth.OAuthStrategy) // This works because we authenticated with auth.UaaPasswordGrant |
| 41 | if !ok { |
| 42 | panic("not using uaa") |
| 43 | } |
| 44 | |
| 45 | fmt.Println("Old access token: ", uaa.AccessToken()) |
| 46 | |
| 47 | uaa.Refresh() // For demo purposes only, tokens will be automatically refreshed by auth.OAuthStrategy |
| 48 | |
| 49 | fmt.Println("New access token:", uaa.AccessToken()) |
| 50 | // Sample Output: |
| 51 | // CredHub server: https://example.com |
| 52 | // Auth server: https://uaa.example.com |
| 53 | // My password: random-password |
| 54 | // Old access token: some-access-token |
| 55 | // New access token: new-access-token |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func ExampleNew() { |
| 60 | _ = func() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…