forked from vmware-tanzu/tanzu-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventory_plugin_group.go
152 lines (131 loc) · 6.37 KB
/
inventory_plugin_group.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// Copyright 2023 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package main
import (
"github.com/spf13/cobra"
"github.com/vmware-tanzu/tanzu-cli/cmd/plugin/builder/imgpkg"
"github.com/vmware-tanzu/tanzu-cli/cmd/plugin/builder/inventory"
"github.com/vmware-tanzu/tanzu-cli/pkg/cli"
)
// newInventoryPluginCmd creates a new command for plugin inventory operations.
func newInventoryPluginGroupCmd() *cobra.Command {
var inventoryPluginCmd = &cobra.Command{
Use: "plugin-group",
Short: "Plugin-Group Inventory Operations",
}
inventoryPluginCmd.SetUsageFunc(cli.SubCmdUsageFunc)
inventoryPluginCmd.AddCommand(
newInventoryPluginGroupAddCmd(),
newInventoryPluginGroupActivateCmd(),
newInventoryPluginGroupDeactivateCmd(),
)
return inventoryPluginCmd
}
type inventoryPluginGroupAddFlags struct {
GroupName string
Repository string
InventoryImageTag string
ManifestFile string
Publisher string
Vendor string
DeactivatePluginGroup bool
Override bool
}
func newInventoryPluginGroupAddCmd() *cobra.Command {
var ipgaFlags = &inventoryPluginGroupAddFlags{}
var pluginGroupAddCmd = &cobra.Command{
Use: "add",
Short: "Add the plugin-group to the inventory database available on the remote repository",
SilenceUsage: true,
Example: ``,
RunE: func(cmd *cobra.Command, args []string) error {
pgaOptions := inventory.InventoryPluginGroupUpdateOptions{
GroupName: ipgaFlags.GroupName,
Repository: ipgaFlags.Repository,
InventoryImageTag: ipgaFlags.InventoryImageTag,
PluginGroupManifestFile: ipgaFlags.ManifestFile,
Vendor: ipgaFlags.Vendor,
Publisher: ipgaFlags.Publisher,
DeactivatePluginGroup: ipgaFlags.DeactivatePluginGroup,
Override: ipgaFlags.Override,
ImgpkgOptions: imgpkg.NewImgpkgCLIWrapper(),
}
return pgaOptions.PluginGroupAdd()
},
}
pluginGroupAddCmd.Flags().StringVarP(&ipgaFlags.GroupName, "name", "", "", "name of the plugin group")
pluginGroupAddCmd.Flags().StringVarP(&ipgaFlags.Repository, "repository", "", "", "repository to publish plugin inventory image")
pluginGroupAddCmd.Flags().StringVarP(&ipgaFlags.InventoryImageTag, "plugin-inventory-image-tag", "", "latest", "tag to which plugin inventory image needs to be published")
pluginGroupAddCmd.Flags().StringVarP(&ipgaFlags.ManifestFile, "manifest", "", "", "manifest file specifying plugin-group details that needs to be processed")
pluginGroupAddCmd.Flags().StringVarP(&ipgaFlags.Vendor, "vendor", "", "", "name of the vendor")
pluginGroupAddCmd.Flags().StringVarP(&ipgaFlags.Publisher, "publisher", "", "", "name of the publisher")
pluginGroupAddCmd.Flags().BoolVarP(&ipgaFlags.DeactivatePluginGroup, "deactivate", "", false, "mark plugin-group as deactivated")
pluginGroupAddCmd.Flags().BoolVarP(&ipgaFlags.Override, "override", "", false, "override the plugin-group if already exists")
_ = pluginGroupAddCmd.MarkFlagRequired("name")
_ = pluginGroupAddCmd.MarkFlagRequired("repository")
_ = pluginGroupAddCmd.MarkFlagRequired("vendor")
_ = pluginGroupAddCmd.MarkFlagRequired("publisher")
_ = pluginGroupAddCmd.MarkFlagRequired("manifest")
return pluginGroupAddCmd
}
type inventoryPluginGroupActivateDeactivateFlags struct {
GroupName string
Repository string
InventoryImageTag string
ManifestFile string
Publisher string
Vendor string
}
func newInventoryPluginGroupActivateCmd() *cobra.Command {
pluginGroupActivateCmd, flags := getPluginGroupActivateDeactivateBaseCmd()
pluginGroupActivateCmd.Use = "activate"
pluginGroupActivateCmd.Short = "Activate the existing plugin-group in the inventory database available on the remote repository"
pluginGroupActivateCmd.Example = ""
pluginGroupActivateCmd.RunE = func(cmd *cobra.Command, args []string) error {
pguOptions := inventory.InventoryPluginGroupUpdateOptions{
GroupName: flags.GroupName,
Repository: flags.Repository,
InventoryImageTag: flags.InventoryImageTag,
Vendor: flags.Vendor,
Publisher: flags.Publisher,
DeactivatePluginGroup: false,
ImgpkgOptions: imgpkg.NewImgpkgCLIWrapper(),
}
return pguOptions.UpdatePluginGroupActivationState()
}
return pluginGroupActivateCmd
}
func newInventoryPluginGroupDeactivateCmd() *cobra.Command {
pluginGroupDeactivateCmd, flags := getPluginGroupActivateDeactivateBaseCmd()
pluginGroupDeactivateCmd.Use = "deactivate"
pluginGroupDeactivateCmd.Short = "Deactivate the existing plugin-group in the inventory database available on the remote repository"
pluginGroupDeactivateCmd.Example = ""
pluginGroupDeactivateCmd.RunE = func(cmd *cobra.Command, args []string) error {
pguOptions := inventory.InventoryPluginGroupUpdateOptions{
GroupName: flags.GroupName,
Repository: flags.Repository,
InventoryImageTag: flags.InventoryImageTag,
Vendor: flags.Vendor,
Publisher: flags.Publisher,
DeactivatePluginGroup: true,
ImgpkgOptions: imgpkg.NewImgpkgCLIWrapper(),
}
return pguOptions.UpdatePluginGroupActivationState()
}
return pluginGroupDeactivateCmd
}
func getPluginGroupActivateDeactivateBaseCmd() (*cobra.Command, *inventoryPluginGroupActivateDeactivateFlags) { //nolint:dupl
var flags = &inventoryPluginGroupActivateDeactivateFlags{}
var activateDeactivateCmd = &cobra.Command{}
activateDeactivateCmd.SilenceUsage = true
activateDeactivateCmd.Flags().StringVarP(&flags.GroupName, "name", "", "", "name of the plugin group")
activateDeactivateCmd.Flags().StringVarP(&flags.Repository, "repository", "", "", "repository to publish plugin inventory image")
activateDeactivateCmd.Flags().StringVarP(&flags.InventoryImageTag, "plugin-inventory-image-tag", "", "latest", "tag to which plugin inventory image needs to be published")
activateDeactivateCmd.Flags().StringVarP(&flags.Vendor, "vendor", "", "", "name of the vendor")
activateDeactivateCmd.Flags().StringVarP(&flags.Publisher, "publisher", "", "", "name of the publisher")
_ = activateDeactivateCmd.MarkFlagRequired("name")
_ = activateDeactivateCmd.MarkFlagRequired("repository")
_ = activateDeactivateCmd.MarkFlagRequired("vendor")
_ = activateDeactivateCmd.MarkFlagRequired("publisher")
return activateDeactivateCmd, flags
}