| 417 | } |
| 418 | |
| 419 | func getKeepService(ctx context.Context, flags *RootFlags, keepCmd *KeepCmd) (*keepapi.Service, error) { |
| 420 | if keepCmd.ServiceAccount != "" { |
| 421 | if keepCmd.Impersonate == "" { |
| 422 | return nil, fmt.Errorf("--impersonate is required when using --service-account") |
| 423 | } |
| 424 | return keepServiceWithServiceAccount(ctx, keepCmd.ServiceAccount, keepCmd.Impersonate) |
| 425 | } |
| 426 | |
| 427 | account, err := requireAccount(flags) |
| 428 | if err != nil { |
| 429 | return nil, err |
| 430 | } |
| 431 | |
| 432 | serviceAccounts, err := commandServiceAccountStore(ctx) |
| 433 | if err != nil { |
| 434 | return nil, err |
| 435 | } |
| 436 | file, exists, err := serviceAccounts.Existing(account, true) |
| 437 | if err != nil { |
| 438 | return nil, err |
| 439 | } |
| 440 | if exists { |
| 441 | return keepServiceWithServiceAccount(ctx, file.Path, account) |
| 442 | } |
| 443 | |
| 444 | return nil, usage("Keep is Workspace-only and requires a service account. Configure it with: gog auth service-account set <email> --key <service-account.json> (or legacy: gog auth keep <email> --key <service-account.json>)") |
| 445 | } |