-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
2,120 additions
and
805 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright 2021 The Gort Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/getgort/gort/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
bundleVersionsUse = "versions" | ||
bundleVersionsShort = "Lists installed bundle versions." | ||
bundleVersionsLong = "List all versions of an installed bundle." | ||
bundleVersionsUsage = `Usage: gort bundle versions [OPTIONS] NAME | ||
Lists installed versions of a bundle. | ||
All versions of the specified bundle are listed, along | ||
with their status ("Enabled", "Disabled", "Incompatible") | ||
Options: | ||
--help Show this message and exit. | ||
` | ||
) | ||
|
||
// TODO: Support incompatible flag | ||
// -x, --incompatible Lists only incompatible bundle versions | ||
|
||
// GetBundleVersionsCmd is a command | ||
func GetBundleVersionsCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: bundleVersionsUse, | ||
Short: bundleVersionsShort, | ||
Long: bundleVersionsLong, | ||
RunE: bundleVersionsCmd, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
|
||
cmd.SetUsageTemplate(bundleVersionsUsage) | ||
|
||
return cmd | ||
} | ||
|
||
func bundleVersionsCmd(cmd *cobra.Command, args []string) error { | ||
const format = "%-12s%-12s%-12s\n" | ||
|
||
gortClient, err := client.Connect(FlagGortProfile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bundles, err := gortClient.BundleListVersions(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf(format, "BUNDLE", "VERSION", "STATUS") | ||
|
||
for _, b := range bundles { | ||
if b.Version == "" { | ||
b.Version = "-" | ||
} | ||
|
||
status := "Disabled" | ||
if b.Enabled { | ||
status = "Enabled" | ||
} | ||
// TODO: Determine whether bundles are incompatible | ||
|
||
fmt.Printf(format, b.Name, b.Version, status) | ||
|
||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2021 The Gort Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/getgort/gort/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
permissionListUse = "list" | ||
permissionListShort = "List all permissions installed" | ||
permissionListLong = "Lists all permissions installed, and their currently enabled version, if any." | ||
permissionListUsage = `Usage: | ||
gort permission list [flags] | ||
Flags: | ||
-h, --help Show this message and exit | ||
Global Flags: | ||
-P, --profile string The Gort profile within the config file to use | ||
` | ||
) | ||
|
||
// GetPermissionListCmd is a command | ||
func GetPermissionListCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: permissionListUse, | ||
Short: permissionListShort, | ||
Long: permissionListLong, | ||
RunE: permissionListCmd, | ||
} | ||
|
||
cmd.SetUsageTemplate(permissionListUsage) | ||
|
||
return cmd | ||
} | ||
|
||
func permissionListCmd(cmd *cobra.Command, args []string) error { | ||
const format = "%-12s\n" | ||
|
||
gortClient, err := client.Connect(FlagGortProfile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bundles, err := gortClient.BundleList() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf(format, "NAME") | ||
|
||
for _, b := range bundles { | ||
for _, p := range b.Permissions { | ||
fmt.Printf(format, fmt.Sprintf("%v-%v", b.Name, p)) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2021 The Gort Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cli | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
permissionUse = "permission" | ||
permissionShort = "Perform operations on permissions" | ||
permissionLong = "Allows you to perform permission administration." | ||
) | ||
|
||
// GetPermissionCmd permission | ||
func GetPermissionCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: permissionUse, | ||
Short: permissionShort, | ||
Long: permissionLong, | ||
} | ||
|
||
cmd.AddCommand(GetPermissionListCmd()) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2021 The Gort Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/getgort/gort/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
roleInfoUse = "info" | ||
roleInfoShort = "Retrieve information about an existing role" | ||
roleInfoLong = "Retrieve information about an existing role." | ||
roleInfoUsage = `Usage: | ||
gort role info [flags] role_name [version] | ||
Flags: | ||
-h, --help Show this message and exit | ||
Global Flags: | ||
-P, --profile string The Gort profile within the config file to use | ||
` | ||
) | ||
|
||
// GetRoleInfoCmd is a command | ||
func GetRoleInfoCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: roleInfoUse, | ||
Short: roleInfoShort, | ||
Long: roleInfoLong, | ||
RunE: roleInfoCmd, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
|
||
cmd.SetUsageTemplate(roleInfoUsage) | ||
|
||
return cmd | ||
} | ||
|
||
func roleInfoCmd(cmd *cobra.Command, args []string) error { | ||
gortClient, err := client.Connect(FlagGortProfile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rolename := args[0] | ||
|
||
role, err := gortClient.RoleGet(rolename) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
const format = `Name %s | ||
Permissions %s | ||
Groups %s | ||
` | ||
|
||
fmt.Printf(format, | ||
role.Name, | ||
strings.Join(role.Permissions.Strings(), ", "), | ||
strings.Join(groupNames(role.Groups), ", ")) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.