-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added applications commands to CLI (#11)
- Loading branch information
1 parent
a4cb5d2
commit d7fce98
Showing
5 changed files
with
179 additions
and
30 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,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) | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"version": "0.0.2-alpha", | ||
"version": "0.0.3-alpha", | ||
"go_version": "1.15.2" | ||
} |