Skip to content

Commit

Permalink
v1.0.10-beta Release (#147)
Browse files Browse the repository at this point in the history
* Fix code scanning issues (#145)

* Fix #143 add usergroup filtering to cybr safes list (#146)

* Add query param support to cybr safes list-members

* fix go-lint issue

* Add FilteredSafes func & --user --group cmd args

* Update README

* rm & ignore .dccache

* Bump version from 1.0.9-beta -> 1.0.10-beta

* Update binaries to current
  • Loading branch information
infamousjoeg authored Apr 22, 2022
1 parent ded06e1 commit 5d68868
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 36 deletions.
1 change: 0 additions & 1 deletion .dccache

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
# Dependency directories (remove the comment below to include it)
# vendor/

.DS_Store
.DS_Store
.dccache
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Current products supported:
- [AWS CloudShell](#aws-cloudshell)
- [Install from Source](#install-from-source)
- [Usage](#usage)
- [Documentation](#documentation)
- [Autocomplete](#autocomplete)
- [Example Source Code](#example-source-code)
- [Logon to the PAS REST API Web Service](#logon-to-the-pas-rest-api-web-service)
Expand Down Expand Up @@ -68,6 +69,8 @@ $ cybr help
* `$ cybr help` for top-level commands list
* `$ cybr [command] -h` for specific command details and sub-commands list

### Documentation

All commands are documentated [in the docs/ directory](docs/cybr.md).

## Autocomplete
Expand Down
Binary file modified bin/cybr
Binary file not shown.
Binary file modified bin/darwin_arm64_cybr
Binary file not shown.
Binary file modified bin/linux_cybr
Binary file not shown.
Binary file modified bin/windows_cybr.exe
Binary file not shown.
68 changes: 65 additions & 3 deletions cmd/safes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"

pasapi "github.com/infamousjoeg/cybr-cli/pkg/cybr/api"
"github.com/infamousjoeg/cybr-cli/pkg/cybr/api/queries"
"github.com/infamousjoeg/cybr-cli/pkg/cybr/api/requests"
"github.com/infamousjoeg/cybr-cli/pkg/cybr/helpers/prettyprint"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -86,6 +87,10 @@ var (
Role string
// RolePermissions contain the pre-defined safe permissions of defined role
RolePermissions []requests.PermissionKeyValue
// User is the user to search for as a safe member
User string
// Group is the group to search for as a safe member
Group string
)

var safesCmd = &cobra.Command{
Expand All @@ -95,6 +100,8 @@ var safesCmd = &cobra.Command{
Example Usage:
List All Safes: $ cybr safes list
List All Safes with Safe Member: $ cybr safes list -u UserName
List All Safes with Safe Member: $ cybr safes list -g GroupName
List Safe Members: $ cybr safes member list -s SafeName
Add Safe: $ cybr safes add -s SafeName -d Description --cpm ManagingCPM --days 0`,
Aliases: []string{"safe"},
Expand All @@ -106,14 +113,39 @@ var listSafesCmd = &cobra.Command{
Long: `List all safes the logged on user can read from PAS REST API.
Example Usage:
$ cybr safes list`,
$ cybr safes list
$ cybr safes list -u UserName
$ cybr safes list -g GroupName`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
}

if User != "" {
safeNames, err := client.FilterSafes("memberType eq user AND includePredefinedUsers eq true", User)
if err != nil {
log.Fatalf("Failed to list safes for user %s. %s", User, err)
return
}
for _, safeName := range safeNames {
fmt.Println(safeName)
}
return
} else if Group != "" {
safeNames, err := client.FilterSafes("memberType eq group AND includePredefinedUsers eq true", Group)
if err != nil {
log.Fatalf("Failed to list safes for group %s. %s", Group, err)
return
}
for _, safeName := range safeNames {
fmt.Println(safeName)
}
return
}

// List All Safes
safes, err := client.ListSafes()
if err != nil {
Expand All @@ -132,7 +164,9 @@ var listMembersCmd = &cobra.Command{
the user logged on can read from PAS REST API.
Example Usage:
$ cybr safes list-members -s SafeName`,
$ cybr safes list-members -s SafeName
$ cybr safes list-members -s SafeName -u UserName
$ cybr safes list-members -s SafeName -g GroupName`,
Aliases: []string{"list-member"},
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
Expand All @@ -141,8 +175,28 @@ var listMembersCmd = &cobra.Command{
log.Fatalf("Failed to read configuration file. %s", err)
return
}

if User != "" && Group != "" {
Filter = "includePredefinedUsers eq true"
Search = fmt.Sprintf("%s %s", User, Group)
} else if User != "" {
Filter = "memberType eq user AND includePredefinedUsers eq true"
Search = User
} else if Group != "" {
Filter = "memberType eq group AND includePredefinedUsers eq true"
Search = Group
}

query := &queries.ListSafeMembers{
Search: Search,
Sort: Sort,
Offset: Offset,
Limit: Limit,
Filter: Filter,
}

// Add a safe with the configuration options given via CLI subcommands
members, err := client.ListSafeMembers(Safe)
members, err := client.ListSafeMembers(Safe, query)
if err != nil {
log.Fatalf("Failed to retrieve a list of all safe members for %s. %s", Safe, err)
return
Expand Down Expand Up @@ -430,7 +484,15 @@ var updateSafeCmd = &cobra.Command{
}

func init() {
listSafesCmd.Flags().StringVarP(&User, "user", "u", "", "Username to filter request on")
listSafesCmd.Flags().StringVarP(&Group, "group", "g", "", "Group to filter request on")

listMembersCmd.Flags().StringVarP(&Safe, "safe", "s", "", "Safe name to filter request on")
listMembersCmd.Flags().StringVarP(&User, "user", "u", "", "Username to filter request on")
listMembersCmd.Flags().StringVarP(&Group, "group", "g", "", "Group to filter request on")
listMembersCmd.Flags().StringVarP(&Sort, "sort", "r", "", "Property or properties by which to sort returned safes, followed by asc (default) or desc to control sort direction. Separate multiple properties with commas, up to a maximum of three properties")
listMembersCmd.Flags().IntVarP(&Offset, "offset", "o", 0, "Offset of the first safe that is returned in the collection of results")
listMembersCmd.Flags().IntVarP(&Limit, "limit", "l", 0, "Maximum number of returned safes. If not specified, the default value is 50. The maximum number that can be specified is 1000")
listMembersCmd.MarkFlagRequired("safe")

addSafeCmd.Flags().StringVarP(&SafeName, "safe", "s", "", "Safe name to create")
Expand Down
6 changes: 4 additions & 2 deletions pkg/cybr/api/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func TestAddAndDeleteAccountSuccess(t *testing.T) {
UserName: "add-account-test",
PlatformID: "UnixSSH",
SecretType: "password",
Secret: "superSecret",
// file deepcode ignore HardcodedPassword/test: dummy secret for testing
Secret: "superSecret",
}

addedAccount, err := client.AddAccount(account)
Expand All @@ -100,7 +101,8 @@ func TestAddAccountInvalidSafeName(t *testing.T) {
UserName: "add-account-test",
PlatformID: "UnixSSH",
SecretType: "password",
Secret: "superSecret",
// file deepcode ignore HardcodedPassword/test: dummy secret for testing
Secret: "superSecret",
}

_, err = client.AddAccount(account)
Expand Down
10 changes: 10 additions & 0 deletions pkg/cybr/api/queries/listsafemembers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package queries

// ListSafeMembers represents valid query parameters when listing safe members
type ListSafeMembers struct {
Search string `query_key:"search"`
Sort string `query_key:"sort"`
Offset int `query_key:"offset"`
Limit int `query_key:"limit"`
Filter string `query_key:"filter"`
}
Loading

0 comments on commit 5d68868

Please sign in to comment.