Skip to content

Commit

Permalink
Merge branch 'v0.8.0-alpha.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
clockworksoul committed Jul 13, 2021
2 parents ca7100c + c5c5eb2 commit 05b1709
Show file tree
Hide file tree
Showing 39 changed files with 2,120 additions and 805 deletions.
4 changes: 2 additions & 2 deletions adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ func TriggerCommand(ctx context.Context, rawCommand string, id RequestorIdentity
"arg": cmdInput.Parameters,
}

perms, err := da.UserPermissions(ctx, id.GortUser.Username)
perms, err := da.UserPermissionList(ctx, id.GortUser.Username)
if err != nil {
da.RequestError(ctx, request, err)
telemetry.Errors().WithError(err).Commit(ctx)
Expand All @@ -463,7 +463,7 @@ func TriggerCommand(ctx context.Context, rawCommand string, id RequestorIdentity
return nil, fmt.Errorf("user permission load error: %w", err)
}

allowed, err := auth.EvaluateCommandEntry(perms, cmdEntry, env)
allowed, err := auth.EvaluateCommandEntry(perms.Strings(), cmdEntry, env)
if err != nil {
da.RequestError(ctx, request, err)
telemetry.Errors().WithError(err).Commit(ctx)
Expand Down
91 changes: 91 additions & 0 deletions cli/bundle-versions.go
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
}
1 change: 1 addition & 0 deletions cli/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func GetBundleCmd() *cobra.Command {
cmd.AddCommand(GetBundleListCmd())
cmd.AddCommand(GetBundleUninstallCmd())
cmd.AddCommand(GetBundleYamlCmd())
cmd.AddCommand(GetBundleVersionsCmd())

return cmd
}
45 changes: 44 additions & 1 deletion cli/hidden-command.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
hiddenCommandLong = `Provides information about a command.
If no command is specified, this will list all commands installed in Gort.
If a command is specified, this will return information about the specified command.
`
hiddenCommandUsage = `Usage:
!gort:help [flags] [command]
Expand All @@ -46,6 +48,7 @@ func GetHiddenCommandCmd() *cobra.Command {
Short: hiddenCommandShort,
Long: hiddenCommandLong,
RunE: hiddenCommandCmd,
Args: cobra.RangeArgs(0, 1),
}

cmd.SetUsageTemplate(hiddenCommandUsage)
Expand All @@ -59,6 +62,46 @@ func hiddenCommandCmd(cmd *cobra.Command, args []string) error {
return err
}

if len(args) == 0 {
return listAllCommands(gortClient)
}

return detailCommand(gortClient, args[0])
}

func detailCommand(gortClient *client.GortClient, command string) error {
bundles, err := gortClient.BundleList()
if err != nil {
return err
}

var found bool
for _, b := range bundles {
for k := range b.Commands {
cmdName := fmt.Sprintf("%s:%s", b.Name, k)
if cmdName == command || k == command {
fmt.Println(cmdName)
fmt.Println("==")
if len(b.LongDescription) > 0 {
fmt.Println(b.LongDescription)
} else if len(b.Description) > 0 {
fmt.Println(b.Description)
}
fmt.Println()
fmt.Printf("Type `%v --help` for more information.\n", k)
found = true
}
}
}

if !found {
return fmt.Errorf("command not found: %v", command)
}

return nil
}

func listAllCommands(gortClient *client.GortClient) error {
bundles, err := gortClient.BundleList()
if err != nil {
return err
Expand All @@ -69,7 +112,7 @@ func hiddenCommandCmd(cmd *cobra.Command, args []string) error {
cmds := []string{}

for _, b := range bundles {
for k, _ := range b.Commands {
for k := range b.Commands {
cmds = append(cmds, fmt.Sprintf("- %s:%s", b.Name, k))
}
}
Expand Down
77 changes: 77 additions & 0 deletions cli/permission-list.go
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
}
40 changes: 40 additions & 0 deletions cli/permission.go
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
}
81 changes: 81 additions & 0 deletions cli/role-info.go
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
}
1 change: 1 addition & 0 deletions cli/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func GetRoleCmd() *cobra.Command {
cmd.AddCommand(GetRoleCreateCmd())
cmd.AddCommand(GetRoleDeleteCmd())
cmd.AddCommand(GetRoleGrantCmd())
cmd.AddCommand(GetRoleInfoCmd())
cmd.AddCommand(GetRoleListCmd())
cmd.AddCommand(GetRoleRevokeCmd())

Expand Down
Loading

0 comments on commit 05b1709

Please sign in to comment.