()
| 92 | } |
| 93 | |
| 94 | func Example() { |
| 95 | _ = func() { |
| 96 | // CredHub server at https://example.com, using UAA Password grant |
| 97 | ch, err := credhub.New("https://example.com", |
| 98 | credhub.CaCerts(string("--- BEGIN ---\nroot-certificate\n--- END ---")), |
| 99 | credhub.Auth(auth.UaaPassword("credhub_cli", "", "username", "password")), |
| 100 | ) |
| 101 | |
| 102 | // We'll be working with a certificate stored at "/my-certificates/the-cert" |
| 103 | path := "/my-certificates/" |
| 104 | name := "the-cert" |
| 105 | |
| 106 | // If the certificate already exists, delete it |
| 107 | cert, err := ch.GetLatestCertificate(path + name) |
| 108 | if err == nil { |
| 109 | ch.Delete(cert.Name) |
| 110 | } |
| 111 | |
| 112 | // Generate a new certificate |
| 113 | gen := generate.Certificate{ |
| 114 | CommonName: "pivotal", |
| 115 | KeyLength: 2048, |
| 116 | } |
| 117 | cert, err = ch.GenerateCertificate(path+name, gen, credhub.NoOverwrite) |
| 118 | if err != nil { |
| 119 | panic("couldn't generate certificate") |
| 120 | } |
| 121 | |
| 122 | // Use the generated certificate's values to create a new certificate |
| 123 | dupCert, err := ch.SetCertificate(path+"dup-cert", cert.Value) |
| 124 | if err != nil { |
| 125 | panic("couldn't create certificate") |
| 126 | } |
| 127 | |
| 128 | if dupCert.Value.Certificate != cert.Value.Certificate { |
| 129 | panic("certs don't match") |
| 130 | } |
| 131 | |
| 132 | // List all credentials in "/my-certificates" |
| 133 | creds, err := ch.FindByPath(path) |
| 134 | if err != nil { |
| 135 | panic("couldn't list certificates") |
| 136 | } |
| 137 | |
| 138 | fmt.Println("Found the following credentials in " + path + ":") |
| 139 | for _, cred := range creds.Credentials { |
| 140 | fmt.Println(cred.Name) |
| 141 | } |
| 142 | // Sample Output: |
| 143 | // Found the following credentials in /my-certificates: |
| 144 | // /my-certificates/dup-cert |
| 145 | // /my-certificates/the-cert |
| 146 | } |
| 147 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…