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

Method setCredential

credhub/set.go:94–128  ·  view source on GitHub ↗
(name, credType string, value, cred interface{}, options ...SetOption)

Source from the content-addressed store, hash-verified

92}
93
94func (ch *CredHub) setCredential(name, credType string, value, cred interface{}, options ...SetOption) error {
95 request := &setRequest{
96 Name: name,
97 Type: credType,
98 Value: value,
99 }
100
101 serverVersion, err := ch.ServerVersion()
102 if err != nil {
103 return err
104 }
105 if serverVersion.Segments()[0] < 2 {
106 request.Mode = "overwrite"
107 }
108
109 for _, option := range options {
110 if err := option(&request.SetOptions); err != nil {
111 return err
112 }
113 }
114
115 if request.Metadata != nil && !supportsMetadata(serverVersion) {
116 return ServerDoesNotSupportMetadataError
117 }
118
119 resp, err := ch.Request(http.MethodPut, "/api/v1/data", nil, request, true)
120 if err != nil {
121 return err
122 }
123
124 defer resp.Body.Close()
125 defer io.Copy(io.Discard, resp.Body)
126
127 return json.NewDecoder(resp.Body).Decode(cred)
128}
129
130func supportsMetadata(v *version.Version) bool {
131 supportedVersion := version.Must(version.NewVersion("2.6.0"))

Callers 8

SetValueMethod · 0.95
SetJSONMethod · 0.95
SetPasswordMethod · 0.95
SetUserMethod · 0.95
SetCertificateMethod · 0.95
SetRSAMethod · 0.95
SetSSHMethod · 0.95
SetCredentialMethod · 0.95

Calls 3

ServerVersionMethod · 0.95
RequestMethod · 0.95
supportsMetadataFunction · 0.85

Tested by

no test coverage detected