diff --git a/README.md b/README.md index 910406b..6636cae 100644 --- a/README.md +++ b/README.md @@ -6,28 +6,31 @@ ## Table of Contents - [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 @@ -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. @@ -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 @@ -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 diff --git a/cmd/applications.go b/cmd/applications.go new file mode 100644 index 0000000..749311c --- /dev/null +++ b/cmd/applications.go @@ -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) +} diff --git a/cmd/safes.go b/cmd/safes.go index 41f151b..74e8098 100644 --- a/cmd/safes.go +++ b/cmd/safes.go @@ -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. @@ -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) } diff --git a/pkg/cybr/version.go b/pkg/cybr/version.go index 0e8b379..050f610 100644 --- a/pkg/cybr/version.go +++ b/pkg/cybr/version.go @@ -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. diff --git a/release.json b/release.json index ba92b0d..1eee8a0 100644 --- a/release.json +++ b/release.json @@ -1,4 +1,4 @@ { - "version": "0.0.2-alpha", + "version": "0.0.3-alpha", "go_version": "1.15.2" } \ No newline at end of file