Skip to content

Commit

Permalink
Added applications commands to CLI (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
infamousjoeg authored Oct 6, 2020
1 parent a4cb5d2 commit d7fce98
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 30 deletions.
97 changes: 71 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@
## Table of Contents <!-- omit in toc -->

- [Usage](#usage)
- [Command-Line Interface (CLI)](#command-line-interface-cli)
- [logon](#logon)
- [logoff](#logoff)
- [safes](#safes)
- [list](#list)
- [member list](#member-list)
- [version](#version)
- [help](#help)
- [Install from Source](#install-from-source)
- [Docker Container](#docker-container)
- [Run Container Indefinitely](#run-container-indefinitely)
- [Run Container Ephemerally (Recommended)](#run-container-ephemerally-recommended)
- [One-Time Use](#one-time-use)
- [One-Time Use w/ Saved Config](#one-time-use-w-saved-config)
- [Using with jq](#using-with-jq)
- [Application](#application)
- [Import into project](#import-into-project)
- [Logon to the PAS REST API Web Service](#logon-to-the-pas-rest-api-web-service)
- [Call functions by referencing `pasapi` and "dot-referencing"](#call-functions-by-referencing-pasapi-and-dot-referencing)
- [Command-Line Interface (CLI)](#command-line-interface-cli)
- [logon](#logon)
- [logoff](#logoff)
- [safes](#safes)
- [list](#list)
- [member list](#member-list)
- [applications](#applications)
- [list](#list-1)
- [methods list](#methods-list)
- [version](#version)
- [help](#help)
- [Install from Source](#install-from-source)
- [Docker Container](#docker-container)
- [Run Container Indefinitely](#run-container-indefinitely)
- [Run Container Ephemerally (Recommended)](#run-container-ephemerally-recommended)
- [One-Time Use](#one-time-use)
- [One-Time Use w/ Saved Config](#one-time-use-w-saved-config)
- [Using with jq](#using-with-jq)
- [Application](#application)
- [Import into project](#import-into-project)
- [Logon to the PAS REST API Web Service](#logon-to-the-pas-rest-api-web-service)
- [Call functions by referencing `pasapi` and "dot-referencing"](#call-functions-by-referencing-pasapi-and-dot-referencing)
- [Required Environment Variables](#required-environment-variables)
- [Testing](#testing)
- [Successful Output](#successful-output)
- [Successful Output](#successful-output)

## Usage

Expand All @@ -39,6 +42,11 @@
$ cybr logon -u username -a cyberark-or-ldap -b https://pvwa.example.com
```

__Required Options:__
* `-u` or `--username`
* `-a` or `--auth-type`
* `-b` or `--base-url`

Logon to the PAS REST API as the username you provide using the authentication method you choose. At this time, only `cyberark` and `ldap` authentication methods are supported.

Upon successful logon, a file will be created in your user's home directory at `.cybr/config`. It is an encoded file that cannot be read in plain-text. This holds your current session information.
Expand Down Expand Up @@ -75,10 +83,46 @@ List all safes the username you are logged on as has access to read.
$ cybr safes member list -s SafeName
```

Required Option: `-s` or `--safe`
__Required Option:__ `-s` or `--safe`

List all safe members on the safe given.

#### applications

```shell
$ cybr applications
```

List all applications the username you are logged on as has access to read.

```shell
$ cybr applications -l \\Applications
```

__Optional Option:__ `-l` or `--location`

List only applications located within \Applications the username you are logged on as has access to read.

##### list

```shell
$ cybr applications list
```

__Optional Option:__ `-l` or `--location`

List all applications the username you are logged on as has access to read.

##### methods list

```shell
$ cybr applications methods list -a AppID
```

__Required Option:__ `-a` or `--app-id`

List all authentication methods configured for the application identity given.

#### version

```shell
Expand Down Expand Up @@ -110,11 +154,12 @@ Usage:
cybr [command]

Available Commands:
help Help about any command
logoff Logoff the PAS REST API
logon Logon to PAS REST API
safes Safe actions for PAS REST API
version Display current version
applications Applications actions for PAS REST API
help Help about any command
logoff Logoff the PAS REST API
logon Logon to PAS REST API
safes Safe actions for PAS REST API
version Display current version

Flags:
-h, --help help for cybr
Expand Down
104 changes: 104 additions & 0 deletions cmd/applications.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package cmd

import (
"log"

pasapi "github.com/infamousjoeg/cybr-cli/pkg/cybr/api"
"github.com/infamousjoeg/cybr-cli/pkg/cybr/helpers/prettyprint"
"github.com/spf13/cobra"
)

var (
// AppID is the application identity to filter on
AppID string
// Location is the folder location the Application is located in
Location string
)

var applicationsCmd = &cobra.Command{
Use: "applications",
Short: "Applications actions for PAS REST API",
Long: `All applications actions that can be taken via PAS REST API.
Example Usage:
List All Applications at Root: $ cybr applications list
List All Applications at \Applications: $ cybr applications list -l \\Applications
List All Authentication Methods: $ cybr applications methods list -a AppID`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
}
// List All Safes
apps, err := client.ListApplications(Location)
if err != nil {
log.Fatalf("Failed to retrieve a list of all applications. %s", err)
return
}
// Pretty print returned object as JSON blob
prettyprint.PrintJSON(apps)
},
}

var listApplicationsCmd = &cobra.Command{
Use: "list",
Short: "List all applications",
Long: `List all applications the logged on user can read from PAS REST API.
Example Usage:
$ cybr applications list`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
}
// List All Safes
apps, err := client.ListApplications(Location)
if err != nil {
log.Fatalf("Failed to retrieve a list of all applications. %s", err)
return
}
// Pretty print returned object as JSON blob
prettyprint.PrintJSON(apps)
},
}

var listMethodsCmd = &cobra.Command{
Use: "methods list",
Short: "List all authn methods on a specific application",
Long: `List all authentication methods on a specific application
that the user logged on can read from PAS REST API.
Example Usage:
$ cybr applications methods list -a AppID`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
}
// List all Safe Members for specific safe ""
methods, err := client.ListApplicationAuthenticationMethods(AppID)
if err != nil {
log.Fatalf("Failed to retrieve a list of all application methods for %s. %s", Safe, err)
return
}
// Pretty print returned object as JSON blob
prettyprint.PrintJSON(methods)
},
}

func init() {
listApplicationsCmd.Flags().StringVarP(&Location, "location", "l", "\\", "Location of the application in EPV")
listMethodsCmd.Flags().StringVarP(&AppID, "app-id", "a", "", "Application identity to filter request on")
listMethodsCmd.MarkFlagRequired("app-id")
applicationsCmd.Flags().StringVarP(&Location, "location", "l", "\\", "Location of the application in EPV")
applicationsCmd.AddCommand(listApplicationsCmd)
applicationsCmd.AddCommand(listMethodsCmd)
rootCmd.AddCommand(applicationsCmd)
}
4 changes: 2 additions & 2 deletions cmd/safes.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var safesCmd = &cobra.Command{
},
}

var listCmd = &cobra.Command{
var listSafesCmd = &cobra.Command{
Use: "list",
Short: "List all safes",
Long: `List all safes the logged on user can read from PAS REST API.
Expand Down Expand Up @@ -91,7 +91,7 @@ var listMembersCmd = &cobra.Command{
func init() {
listMembersCmd.Flags().StringVarP(&Safe, "safe", "s", "", "Safe name to filter request on")
listMembersCmd.MarkFlagRequired("safe")
safesCmd.AddCommand(listCmd)
safesCmd.AddCommand(listSafesCmd)
safesCmd.AddCommand(listMembersCmd)
rootCmd.AddCommand(safesCmd)
}
2 changes: 1 addition & 1 deletion pkg/cybr/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cybr
import "fmt"

// Version field is a SemVer that should indicate the baked-in version of conceal
var Version = "0.0.2"
var Version = "0.0.3"

// Tag field denotes the specific build type for the broker. It may be replaced by compile-time variables if needed to
// provide the git commit information in the final binary.
Expand Down
2 changes: 1 addition & 1 deletion release.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "0.0.2-alpha",
"version": "0.0.3-alpha",
"go_version": "1.15.2"
}

0 comments on commit d7fce98

Please sign in to comment.