MCPcopy
hub / github.com/perkeep/perkeep / getCredentials

Function getCredentials

cmd/pk-devimport/devimport.go:112–154  ·  view source on GitHub ↗

getCredentials returns the OAuth clientID and clientSecret found in the importer node of the given importerType.

(sh search.QueryDescriber, importerType string)

Source from the content-addressed store, hash-verified

110// getCredentials returns the OAuth clientID and clientSecret found in the
111// importer node of the given importerType.
112func getCredentials(sh search.QueryDescriber, importerType string) (string, string, error) {
113 var clientID, clientSecret string
114 res, err := sh.Query(context.TODO(), &search.SearchQuery{
115 Expression: "attr:camliNodeType:importer and attr:importerType:" + importerType,
116 Describe: &search.DescribeRequest{
117 Depth: 1,
118 },
119 })
120 if err != nil {
121 return clientID, clientSecret, err
122 }
123 if res.Describe == nil {
124 return clientID, clientSecret, errors.New("no importer node found")
125 }
126 var attrs url.Values
127 for _, resBlob := range res.Blobs {
128 blob := resBlob.Blob
129 desBlob, ok := res.Describe.Meta[blob.String()]
130 if !ok || desBlob.Permanode == nil {
131 continue
132 }
133 attrs = desBlob.Permanode.Attr
134 if attrs.Get("camliNodeType") != "importer" {
135 return clientID, clientSecret, errors.New("search result returned non importer node")
136 }
137 if t := attrs.Get("importerType"); t != importerType {
138 return clientID, clientSecret, fmt.Errorf("search result returned importer node of the wrong type: %v", t)
139 }
140 break
141 }
142 attrClientID, attrClientSecret := "authClientID", "authClientSecret"
143 attr := attrs[attrClientID]
144 if len(attr) != 1 {
145 return clientID, clientSecret, fmt.Errorf("no %v attribute", attrClientID)
146 }
147 clientID = attr[0]
148 attr = attrs[attrClientSecret]
149 if len(attr) != 1 {
150 return clientID, clientSecret, fmt.Errorf("no %v attribute", attrClientSecret)
151 }
152 clientSecret = attr[0]
153 return clientID, clientSecret, nil
154}
155
156func main() {
157 flag.Parse()

Callers 1

newImporterHostFunction · 0.85

Calls 3

QueryMethod · 0.65
GetMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected