|
| 1 | +// Copyright 2020 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package spaces |
| 16 | + |
| 17 | +import ( |
| 18 | + "internal/apiclient" |
| 19 | + "internal/client/spaces" |
| 20 | + "internal/clilog" |
| 21 | + |
| 22 | + "github.com/spf13/cobra" |
| 23 | +) |
| 24 | + |
| 25 | +// SetViewerCmd to set role on env |
| 26 | +var SetViewerCmd = &cobra.Command{ |
| 27 | + Use: "setviewer", |
| 28 | + Short: "Set Space Content Viewer role for a member on a Space", |
| 29 | + Long: "Set Space Content Viewer role for a member on a Space", |
| 30 | + Args: func(cmd *cobra.Command, args []string) (err error) { |
| 31 | + apiclient.SetRegion(region) |
| 32 | + return apiclient.SetApigeeOrg(org) |
| 33 | + }, |
| 34 | + RunE: func(cmd *cobra.Command, args []string) (err error) { |
| 35 | + cmd.SilenceUsage = true |
| 36 | + |
| 37 | + err = spaces.SetIAM(space, memberName, "viewer", memberType) |
| 38 | + if err != nil { |
| 39 | + return err |
| 40 | + } |
| 41 | + clilog.Info.Printf("Member \"%s\" granted access to \"roles/apigee.spaceContentViewer\" role in space \"%s\"\n", memberName, space) |
| 42 | + return nil |
| 43 | + }, |
| 44 | + Example: `Set Space Viewer role for user in a space: ` + GetExample(3), |
| 45 | +} |
| 46 | + |
| 47 | +func init() { |
| 48 | + SetViewerCmd.Flags().StringVarP(&space, "space", "", |
| 49 | + "", "Space name.") |
| 50 | + SetViewerCmd.Flags().StringVarP(&memberName, "name", "n", |
| 51 | + "", "Member Name, example Service Account Name") |
| 52 | + SetViewerCmd.Flags().StringVarP(&memberType, "member-type", "m", |
| 53 | + "serviceAccount", "memberType must be serviceAccount, user or group") |
| 54 | + |
| 55 | + _ = SetViewerCmd.MarkFlagRequired("space") |
| 56 | + _ = SetViewerCmd.MarkFlagRequired("name") |
| 57 | +} |
| 58 | + |
0 commit comments