Skip to content

Commit b95e7ca

Browse files
authored
feat: iam commands (#135)
1 parent a610653 commit b95e7ca

File tree

19 files changed

+1258
-34
lines changed

19 files changed

+1258
-34
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- `company iam list` command
13+
- `company iam list users` command
14+
- `company iam list groups` command
15+
- `company iam list serviceaccounts` command
1216
- marketplace apply: add version to multipart request metadata if present in the item
1317
- add command `miactl marketplace list-versions`
1418
- mark as alpha the features:

docs/30_commands.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,90 @@ Available flags for the command:
102102
- `--insecure-skip-tls-verify`, to disallow the check the validity of the certificate of the remote endpoint
103103
- `--context`, to specify a different context from the currently selected one
104104

105+
### iam
106+
107+
The `company iam` subcommands are used for managing the RBAC permissions associated with a company. Only
108+
**Company Owners** can modify, add or remove RBAC authorization to the company.
109+
110+
#### list
111+
112+
The `company iam list` subcommand allows you to view the list of all the different identity associated with the Company
113+
specified in the current context. The output will show the **names**, **types** and **permissions** associated with
114+
them.
115+
116+
Usage:
117+
118+
```sh
119+
miactl company iam list [flags]
120+
```
121+
122+
Available flags for the command:
123+
124+
- `--groups`, filter IAM entities to show only groups. Mutally exclusive with `users` and `serviceAccounts`
125+
- `--serviceAccounts`, filter IAM entities to show only service accounts. Mutally exclusive with `users` and `groups`
126+
- `--users`, filter IAM entities to show only users. Mutally exclusive with `groups` and `serviceAccounts`
127+
- `--endpoint`, to set the Console endpoint (default is `https://console.cloud.mia-platform.eu`)
128+
- `--certificate-authority`, to provide the path to a custom CA certificate
129+
- `--insecure-skip-tls-verify`, to disallow the check the validity of the certificate of the remote endpoint
130+
- `--context`, to specify a different context from the currently selected one
131+
- `--company-id`, to set the ID of the desired Company
132+
133+
##### users
134+
135+
The `company iam list users` subcommand allows you to view the list of all users that have access to your company
136+
directly or via one or more groups.
137+
138+
Usage:
139+
140+
```sh
141+
miactl company iam list users [flags]
142+
```
143+
144+
Available flags for the command:
145+
146+
- `--endpoint`, to set the Console endpoint (default is `https://console.cloud.mia-platform.eu`)
147+
- `--certificate-authority`, to provide the path to a custom CA certificate
148+
- `--insecure-skip-tls-verify`, to disallow the check the validity of the certificate of the remote endpoint
149+
- `--context`, to specify a different context from the currently selected one
150+
- `--company-id`, to set the ID of the desired Company
151+
152+
##### groups
153+
154+
The `company iam list groups` subcommand allows you to view the list of all groups that are available in your company.
155+
156+
Usage:
157+
158+
```sh
159+
miactl company iam list groups [flags]
160+
```
161+
162+
Available flags for the command:
163+
164+
- `--endpoint`, to set the Console endpoint (default is `https://console.cloud.mia-platform.eu`)
165+
- `--certificate-authority`, to provide the path to a custom CA certificate
166+
- `--insecure-skip-tls-verify`, to disallow the check the validity of the certificate of the remote endpoint
167+
- `--context`, to specify a different context from the currently selected one
168+
- `--company-id`, to set the ID of the desired Company
169+
170+
##### serviceaccounts
171+
172+
The `company iam list serviceaccounts` subcommand allows you to view the list of all service accounts that are available
173+
in your company.
174+
175+
Usage:
176+
177+
```sh
178+
miactl company iam list serviceaccounts [flags]
179+
```
180+
181+
Available flags for the command:
182+
183+
- `--endpoint`, to set the Console endpoint (default is `https://console.cloud.mia-platform.eu`)
184+
- `--certificate-authority`, to provide the path to a custom CA certificate
185+
- `--insecure-skip-tls-verify`, to disallow the check the validity of the certificate of the remote endpoint
186+
- `--context`, to specify a different context from the currently selected one
187+
- `--company-id`, to set the ID of the desired Company
188+
105189
## project
106190

107191
This command allows you to manage `miactl` Projects.
@@ -306,7 +390,7 @@ pods available in the current context and then the logs of all their containers
306390
Usage:
307391

308392
```sh
309-
miactl runtime logs POD-QUERY [flags]
393+
miactl runtime logs POD-QUERY [flags]
310394
```
311395

312396
Available flags for the command:

internal/client/transport.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package client
1818
import (
1919
"net/http"
2020

21+
"github.com/mia-platform/miactl/internal/logger"
2122
"github.com/mia-platform/miactl/internal/transport"
22-
"github.com/mia-platform/miactl/internal/util"
2323
"golang.org/x/oauth2"
2424
)
2525

@@ -60,7 +60,7 @@ func transportForConfig(config *Config) (http.RoundTripper, error) {
6060
Insecure: config.Insecure,
6161
CAFile: config.CAFile,
6262
},
63-
Verbose: util.LogLevel >= 5,
63+
Verbose: logger.LogLevel >= 5,
6464
}
6565

6666
if authProvider != nil {

internal/clioptions/clioptions.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import (
2323

2424
"github.com/mia-platform/miactl/internal/cliconfig"
2525
"github.com/mia-platform/miactl/internal/client"
26-
"github.com/mia-platform/miactl/internal/util"
26+
"github.com/mia-platform/miactl/internal/logger"
27+
2728
"github.com/spf13/cobra"
2829
"github.com/spf13/pflag"
2930
)
@@ -66,6 +67,10 @@ type CLIOptions struct {
6667

6768
// OutputFormat describes the output format of some commands. Can be json or yaml.
6869
OutputFormat string
70+
71+
ShowUsers bool
72+
ShowGroups bool
73+
ShowServiceAccounts bool
6974
}
7075

7176
// NewCLIOptions return a new CLIOptions instance
@@ -77,7 +82,7 @@ func (o *CLIOptions) AddGlobalFlags(flags *pflag.FlagSet) {
7782
locator := cliconfig.NewConfigPathLocator()
7883
configFilePathDescription := fmt.Sprintf("path to the config file default to %s", locator.DefaultConfigPath())
7984
flags.StringVarP(&o.MiactlConfig, "config", "c", "", configFilePathDescription)
80-
flags.IntVarP(&util.LogLevel, "verbose", "v", 0, "increase the verbosity of the cli output")
85+
flags.IntVarP(&logger.LogLevel, "verbose", "v", 0, "increase the verbosity of the cli output")
8186
}
8287

8388
func (o *CLIOptions) AddConnectionFlags(flags *pflag.FlagSet) {
@@ -174,6 +179,12 @@ func (o *CLIOptions) AddOutputFormatFlag(flags *pflag.FlagSet, defaultVal string
174179
flags.StringVarP(&o.OutputFormat, "output", "o", defaultVal, "Output format. Allowed values: json, yaml")
175180
}
176181

182+
func (o *CLIOptions) AddIAMListFlags(flags *pflag.FlagSet) {
183+
flags.BoolVar(&o.ShowUsers, "users", false, "Filter IAM entities to show only users. Mutally exclusive with groups and serviceAccounts")
184+
flags.BoolVar(&o.ShowGroups, "groups", false, "Filter IAM entities to show only groups. Mutally exclusive with users and serviceAccounts")
185+
flags.BoolVar(&o.ShowServiceAccounts, "serviceAccounts", false, "Filter IAM entities to show only service accounts. Mutally exclusive with users and groups")
186+
}
187+
177188
func (o *CLIOptions) ToRESTConfig() (*client.Config, error) {
178189
locator := cliconfig.NewConfigPathLocator()
179190
locator.ExplicitPath = o.MiactlConfig

internal/cmd/company.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ func CompanyCmd(options *clioptions.CLIOptions) *cobra.Command {
3333
options.AddContextFlags(flags)
3434

3535
// add sub commands
36-
cmd.AddCommand(company.ListCmd(options))
36+
cmd.AddCommand(
37+
company.ListCmd(options),
38+
company.IAMCmd(options),
39+
)
3740

3841
return cmd
3942
}

internal/cmd/company/iam.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright Mia srl
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package company
17+
18+
import (
19+
"github.com/mia-platform/miactl/internal/clioptions"
20+
"github.com/mia-platform/miactl/internal/cmd/company/iam"
21+
"github.com/spf13/cobra"
22+
)
23+
24+
func IAMCmd(o *clioptions.CLIOptions) *cobra.Command {
25+
cmd := &cobra.Command{
26+
Use: "iam",
27+
Short: "Manage Mia-Platform IAM for a company",
28+
Long: `A Company Owner user can manager the access to the company directly to a user,
29+
via a group or through service accounts.`,
30+
}
31+
32+
// add cmd flags
33+
flags := cmd.PersistentFlags()
34+
o.AddConnectionFlags(flags)
35+
o.AddContextFlags(flags)
36+
o.AddCompanyFlags(flags)
37+
38+
cmd.AddCommand(
39+
iam.ListCmd(o),
40+
)
41+
42+
return cmd
43+
}

0 commit comments

Comments
 (0)