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

Function getAllCredentialsForPath

commands/export.go:40–82  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

38}
39
40func getAllCredentialsForPath(path string) ([]credentials.Credential, error) {
41 cfg := config.ReadConfig()
42 credhubClient, err := initializeCredhubClient(cfg)
43
44 if err != nil {
45 return nil, err
46 }
47
48 allPaths, err := credhubClient.FindByPath(path)
49
50 if err != nil {
51 return nil, err
52 }
53
54 credentials := make([]credentials.Credential, len(allPaths.Credentials))
55 for i, baseCred := range allPaths.Credentials {
56 credential, err := credhubClient.GetLatestVersion(baseCred.Name)
57
58 if err != nil {
59 return nil, err
60 }
61
62 if credential.Type == "certificate" {
63 certMetadata, err := credhubClient.GetCertificateMetadataByName(credential.Name)
64
65 if err != nil {
66 return nil, err
67 }
68 signedBy := certMetadata.SignedBy
69
70 if signedBy != "" && signedBy != credential.Name {
71 if cert, ok := credential.Value.(map[string]interface{}); ok {
72 cert["ca_name"] = signedBy
73 delete(cert, "ca")
74 credential.Value = cert
75 }
76 }
77 }
78 credentials[i] = credential
79 }
80
81 return credentials, nil
82}

Callers 1

ExecuteMethod · 0.85

Calls 5

ReadConfigFunction · 0.92
initializeCredhubClientFunction · 0.85
FindByPathMethod · 0.80
GetLatestVersionMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…