|
| 1 | +// Copyright (c) 2015-2024 MinIO, Inc. |
| 2 | +// |
| 3 | +// This file is part of MinIO Object Storage stack |
| 4 | +// |
| 5 | +// This program is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU Affero General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// This program is distributed in the hope that it will be useful |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU Affero General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU Affero General Public License |
| 16 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +package cmd |
| 19 | + |
| 20 | +import ( |
| 21 | + "github.com/minio/cli" |
| 22 | +) |
| 23 | + |
| 24 | +var adminAccesskeyCreateFlags = []cli.Flag{ |
| 25 | + cli.StringFlag{ |
| 26 | + Name: "access-key", |
| 27 | + Usage: "set an access key for the account", |
| 28 | + }, |
| 29 | + cli.StringFlag{ |
| 30 | + Name: "secret-key", |
| 31 | + Usage: "set a secret key for the account", |
| 32 | + }, |
| 33 | + cli.StringFlag{ |
| 34 | + Name: "policy", |
| 35 | + Usage: "path to a JSON policy file", |
| 36 | + }, |
| 37 | + cli.StringFlag{ |
| 38 | + Name: "name", |
| 39 | + Usage: "friendly name for the account", |
| 40 | + }, |
| 41 | + cli.StringFlag{ |
| 42 | + Name: "description", |
| 43 | + Usage: "description for the account", |
| 44 | + }, |
| 45 | + cli.StringFlag{ |
| 46 | + Name: "expiry-duration", |
| 47 | + Usage: "duration before the access key expires", |
| 48 | + }, |
| 49 | + cli.StringFlag{ |
| 50 | + Name: "expiry", |
| 51 | + Usage: "expiry date for the access key", |
| 52 | + }, |
| 53 | +} |
| 54 | + |
| 55 | +var adminAccesskeyCreateCmd = cli.Command{ |
| 56 | + Name: "create", |
| 57 | + Usage: "create access key pairs for users", |
| 58 | + Action: mainAdminAccesskeyCreate, |
| 59 | + Before: setGlobalsFromContext, |
| 60 | + Flags: append(adminAccesskeyCreateFlags, globalFlags...), |
| 61 | + OnUsageError: onUsageError, |
| 62 | + CustomHelpTemplate: `NAME: |
| 63 | + {{.HelpName}} - {{.Usage}} |
| 64 | +
|
| 65 | +USAGE: |
| 66 | + {{.HelpName}} [FLAGS] [TARGET] |
| 67 | +
|
| 68 | +FLAGS: |
| 69 | + {{range .VisibleFlags}}{{.}} |
| 70 | + {{end}} |
| 71 | +EXAMPLES: |
| 72 | + 1. Create a new access key pair with the same policy as the authenticated user |
| 73 | + {{.Prompt}} {{.HelpName}} myminio/ |
| 74 | +
|
| 75 | + 2. Create a new access key pair with custom access key and secret key |
| 76 | + {{.Prompt}} {{.HelpName}} myminio/ --access-key myaccesskey --secret-key mysecretkey |
| 77 | +
|
| 78 | + 3. Create a new access key pair for user 'tester' that expires in 1 day |
| 79 | + {{.Prompt}} {{.HelpName}} myminio/ tester --expiry-duration 24h |
| 80 | +
|
| 81 | + 4. Create a new access key pair for authenticated user that expires on 2025-01-01 |
| 82 | + {{.Prompt}} {{.HelpName}} --expiry 2025-01-01 |
| 83 | +
|
| 84 | + 5. Create a new access key pair for user 'tester' with a custom policy |
| 85 | + {{.Prompt}} {{.HelpName}} myminio/ tester --policy /path/to/policy.json |
| 86 | +
|
| 87 | + 6. Create a new access key pair for user 'tester' with a custom name and description |
| 88 | + {{.Prompt}} {{.HelpName}} myminio/ tester --name "Tester's Access Key" --description "Access key for tester" |
| 89 | +`, |
| 90 | +} |
| 91 | + |
| 92 | +func mainAdminAccesskeyCreate(ctx *cli.Context) error { |
| 93 | + return commonAccesskeyCreate(ctx, false) |
| 94 | +} |
0 commit comments