|
| 1 | +// SPDX-FileCopyrightText: 2026 SUSE LLC |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +package gpg |
| 6 | + |
| 7 | +import ( |
| 8 | + "github.com/spf13/cobra" |
| 9 | + "github.com/uyuni-project/uyuni-tools/shared/api" |
| 10 | + . "github.com/uyuni-project/uyuni-tools/shared/l10n" |
| 11 | + "github.com/uyuni-project/uyuni-tools/shared/types" |
| 12 | + "github.com/uyuni-project/uyuni-tools/shared/utils" |
| 13 | +) |
| 14 | + |
| 15 | +type apiFlags struct { |
| 16 | + api.ConnectionDetails `mapstructure:"api"` |
| 17 | +} |
| 18 | + |
| 19 | +func NewCommand(globalFlags *types.GlobalFlags) *cobra.Command { |
| 20 | + var flags apiFlags |
| 21 | + |
| 22 | + gpgCmd := &cobra.Command{ |
| 23 | + Use: "gpg", |
| 24 | + Short: L("GPG key management commands"), |
| 25 | + } |
| 26 | + |
| 27 | + gpgUploadKeyCmd := &cobra.Command{ |
| 28 | + Use: "upload [path or URL]", |
| 29 | + Short: L("Upload a GPG key to the server"), |
| 30 | + Long: L(`Uploads an armored GPG key to the server from a local file or a remote URL.`), |
| 31 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 32 | + return utils.CommandHelper(globalFlags, cmd, args, &flags, nil, runGpgKeyUpload) |
| 33 | + }, |
| 34 | + Args: cobra.ExactArgs(1), |
| 35 | + } |
| 36 | + |
| 37 | + gpgListKeysCmd := &cobra.Command{ |
| 38 | + Use: "list", |
| 39 | + Short: L("List all GPG keys on the server"), |
| 40 | + Long: L(`Retrieves a list of registered and/or previously uploaded GPG keys.`), |
| 41 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 42 | + return utils.CommandHelper(globalFlags, cmd, args, &flags, nil, runGpgKeyList) |
| 43 | + }, |
| 44 | + } |
| 45 | + |
| 46 | + gpgRemoveKeyCmd := &cobra.Command{ |
| 47 | + Use: "remove [fingerprint]", |
| 48 | + Short: L("Remove a GPG key from the server"), |
| 49 | + Long: L(`Removes a key identified by its fingerprint from the server's GPG keyring.`), |
| 50 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 51 | + return utils.CommandHelper(globalFlags, cmd, args, &flags, nil, runGpgKeyRemove) |
| 52 | + }, |
| 53 | + Args: cobra.ExactArgs(1), |
| 54 | + } |
| 55 | + |
| 56 | + gpgCmd.AddCommand(gpgUploadKeyCmd) |
| 57 | + gpgCmd.AddCommand(gpgListKeysCmd) |
| 58 | + gpgCmd.AddCommand(gpgRemoveKeyCmd) |
| 59 | + api.AddAPIFlags(gpgCmd) |
| 60 | + |
| 61 | + return gpgCmd |
| 62 | +} |
0 commit comments