| 42 | } |
| 43 | |
| 44 | func inspectAPIKey(client apiKeyInspector, key string) (isAdmin bool, stringACLs []string, err error) { |
| 45 | // Admin API keys are special: they can list keys but aren't themselves retrievable via GET /1/keys/{key}. |
| 46 | // So we use ListAPIKeys() as the admin-key check and skip GetAPIKey() in that case. |
| 47 | if _, err := client.ListAPIKeys(); err == nil { |
| 48 | return true, nil, nil |
| 49 | } |
| 50 | |
| 51 | apiKey, err := client.GetAPIKey(client.NewAPIGetAPIKeyRequest(key)) |
| 52 | if err != nil { |
| 53 | return false, nil, errors.New("invalid application credentials") |
| 54 | } |
| 55 | if len(apiKey.Acl) == 0 { |
| 56 | return false, nil, errors.New("the provided API key has no ACLs") |
| 57 | } |
| 58 | |
| 59 | for _, a := range apiKey.Acl { |
| 60 | stringACLs = append(stringACLs, string(a)) |
| 61 | } |
| 62 | |
| 63 | return false, stringACLs, nil |
| 64 | } |
| 65 | |
| 66 | // AddOptions represents the options for the add command |
| 67 | type AddOptions struct { |