MCPcopy Create free account
hub / github.com/hashicorp/vault / parseNamespaceCount

Method parseNamespaceCount

command/operator_usage.go:224–264  ·  view source on GitHub ↗

TODO: provide a function in the API module for doing this conversion?

(rawVal interface{})

Source from the content-addressed store, hash-verified

222
223// TODO: provide a function in the API module for doing this conversion?
224func (c *OperatorUsageCommand) parseNamespaceCount(rawVal interface{}) (UsageResponse, error) {
225 var ret UsageResponse
226
227 val, ok := rawVal.(map[string]interface{})
228 if !ok {
229 return ret, errors.New("value is not a map")
230 }
231
232 ret.namespacePath, ok = val["namespace_path"].(string)
233 if !ok {
234 return ret, errors.New("bad namespace path")
235 }
236
237 counts, ok := val["counts"].(map[string]interface{})
238 if !ok {
239 return ret, errors.New("missing counts")
240 }
241
242 ret.entityCount, ok = jsonNumberOK(counts, "entity_clients")
243 if !ok {
244 return ret, errors.New("missing entity_clients")
245 }
246
247 ret.tokenCount, ok = jsonNumberOK(counts, "non_entity_clients")
248 if !ok {
249 return ret, errors.New("missing non_entity_clients")
250 }
251
252 // don't error if the secret syncs key is missing
253 ret.secretSyncs, _ = jsonNumberOK(counts, "secret_syncs")
254
255 // don't error if acme clients is missing
256 ret.acmeCount, _ = jsonNumberOK(counts, "acme_clients")
257
258 ret.clientCount, ok = jsonNumberOK(counts, "clients")
259 if !ok {
260 return ret, errors.New("missing clients")
261 }
262
263 return ret, nil
264}
265
266func (c *OperatorUsageCommand) namespacesOutput(data map[string]interface{}) []string {
267 byNs, ok := data["by_namespace"].([]interface{})

Callers 1

namespacesOutputMethod · 0.95

Calls 1

jsonNumberOKFunction · 0.85

Tested by

no test coverage detected