MCPcopy Create free account
hub / github.com/cloudfoundry/credhub-cli / Example

Function Example

credhub/example_test.go:94–147  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

92}
93
94func 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}

Callers

nothing calls this directly

Calls 9

NewFunction · 0.92
CaCertsFunction · 0.92
AuthFunction · 0.92
UaaPasswordFunction · 0.92
GetLatestCertificateMethod · 0.80
DeleteMethod · 0.80
GenerateCertificateMethod · 0.80
SetCertificateMethod · 0.80
FindByPathMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…