Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.1.0 beta release #63

Merged
merged 33 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f8625a6
Do not list unless prompted to list (#21)
AndrewCopeland Jan 8, 2021
d5dd264
Push current README changes for review
infamousjoeg Jan 8, 2021
6a5ba00
Fix typo to resolve issue #23 (#24)
AndrewCopeland Jan 8, 2021
a1abeec
modify the application CMD for authn-<action> (#25)
AndrewCopeland Jan 8, 2021
26fa9fe
Fix unit tests (#26)
AndrewCopeland Jan 8, 2021
06fb635
fix dev example
infamousjoeg Jan 8, 2021
a2f1710
Added code of conduct, contributing, updated readme
infamousjoeg Jan 9, 2021
99eaf76
v0.0.4-alpha
infamousjoeg Jan 11, 2021
7c167ea
Conjur commands (#27)
AndrewCopeland Jan 11, 2021
bb3b27e
Update conjur.go
infamousjoeg Jan 11, 2021
8f8a584
Merge branch 'dev' of https://github.com/infamousjoeg/pas-api-go into…
infamousjoeg Jan 11, 2021
bea2fbb
Safe members (#29)
AndrewCopeland Jan 11, 2021
e0fde5c
Number of Days will not be omitted when 0
AndrewCopeland Jan 12, 2021
f3aefd7
Dev creating application flow (#34)
AndrewCopeland Jan 12, 2021
e3f0d02
Merge branch 'main' into dev
AndrewCopeland Jan 12, 2021
33706b4
v0.0.5-alpha Ready for Release (#35)
infamousjoeg Jan 13, 2021
389cb05
Add new line to commands #33 (#39)
AndrewCopeland Jan 13, 2021
43aea0e
#38 Add cybr conjur logoff command (#40)
AndrewCopeland Jan 13, 2021
1dc2342
#44 refactor api tests (#45)
AndrewCopeland Jan 14, 2021
f8c0e92
Add #37 add verbose v006 (#41)
AndrewCopeland Jan 15, 2021
6c5dbc3
Fix #42 RADIUS authentication support for push, append, challenge/res…
infamousjoeg Jan 15, 2021
9b3901d
#30 Unsuspend a user from failed logon attempts (#43)
AndrewCopeland Jan 15, 2021
0c2cbfd
Merge branch 'main' into v006
infamousjoeg Jan 15, 2021
02f5804
Add logger to user api pkg
AndrewCopeland Jan 15, 2021
1116688
Remove duplicate tests
AndrewCopeland Jan 15, 2021
55ea054
Implement client.GetLogger() function so null logger cannot be returned
AndrewCopeland Jan 15, 2021
be45d70
Fix 52 conjur logon fail (#53)
AndrewCopeland Jan 20, 2021
6d6557d
Fix #52 conjur logon fail (#54)
AndrewCopeland Jan 27, 2021
f5bc894
Fix #32 add cybr logon --non-interactive (#56)
AndrewCopeland Jan 28, 2021
bebf180
#49 add account actions (#57)
AndrewCopeland Jan 28, 2021
c833c82
Add ability to auto generate docs (#61)
AndrewCopeland Jan 28, 2021
2f0c61e
Fix #31 users cmds v0.1.0 (#55)
AndrewCopeland Jan 28, 2021
3057760
prep for v0.1.0-beta release (#62)
infamousjoeg Jan 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add #37 add verbose v006 (#41)
* Added logger to httpjson package

* Create logger interface and implement interface for CMD logging

* When init pas client also init with logger depending on --verbose flag

* Add logger to the PAS apis

* Do not log added account password. Implemented secrets in logger that will be scrubed when logging

* Scrub the password by creating a new logger with secrets
  • Loading branch information
AndrewCopeland authored Jan 15, 2021
commit f8c0e9286f85c8a5907d5d582c8f3190e98910d7
8 changes: 4 additions & 4 deletions cmd/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var listAccountsCmd = &cobra.Command{
Example Usage:
$ cybr accounts list`,
Run: func(cmd *cobra.Command, args []string) {
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand Down Expand Up @@ -109,7 +109,7 @@ var getAccountsCmd = &cobra.Command{
Example Usage:
$ cybr accounts get -i 24_1`,
Run: func(cmd *cobra.Command, args []string) {
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand Down Expand Up @@ -165,7 +165,7 @@ var addAccountsCmd = &cobra.Command{
Example Usage:
$ cybr accounts add -s SafeName -p platformID -u username -a 10.0.0.1 -t password -s SuperSecret`,
Run: func(cmd *cobra.Command, args []string) {
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand Down Expand Up @@ -209,7 +209,7 @@ var deleteAccountsCmd = &cobra.Command{
Example Usage:
$ cybr accounts delete 24_1`,
Run: func(cmd *cobra.Command, args []string) {
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand Down
12 changes: 6 additions & 6 deletions cmd/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var listApplicationsCmd = &cobra.Command{
$ cybr applications list`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand All @@ -91,7 +91,7 @@ var listMethodsCmd = &cobra.Command{
$ cybr applications list-authn -a AppID`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand All @@ -115,7 +115,7 @@ var addApplicationCmd = &cobra.Command{
Example Usage:
$ cybr applications add -a AppID -l "\\"`,
Run: func(cmd *cobra.Command, args []string) {
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand Down Expand Up @@ -155,7 +155,7 @@ var deleteApplicationCmd = &cobra.Command{
Example Usage:
$ cybr applications delete -a AppID`,
Run: func(cmd *cobra.Command, args []string) {
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand All @@ -179,7 +179,7 @@ var addApplicationAuthenticationMethodCmd = &cobra.Command{
Example Usage:
$ cybr applications add-authn -a AppID -t path -v /some/path`,
Run: func(cmd *cobra.Command, args []string) {
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand Down Expand Up @@ -212,7 +212,7 @@ var deleteApplicationAuthenticationMethodCmd = &cobra.Command{
Example Usage:
$ cybr applications delete-authn -a AppID -i 1`,
Run: func(cmd *cobra.Command, args []string) {
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand Down
2 changes: 1 addition & 1 deletion cmd/logoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var logoffCmd = &cobra.Command{
$ cybr logoff`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import (
"fmt"
"os"

"github.com/infamousjoeg/cybr-cli/pkg/logger"
"github.com/spf13/cobra"
)

var cfgFile string

var (
// Verbose logging
Verbose bool
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "cybr",
Expand All @@ -28,7 +34,16 @@ func Execute() {
}
}

func getLogger() logger.CMD {
return logger.CMD{
LoggerEnabled: Verbose,
LogHeaderEnabled: true,
LogBodyEnabled: true,
}
}

func init() {
rootCmd.PersistentFlags().BoolVar(&Verbose, "verbose", false, "To enable verbose logging")
// cobra.OnInitialize(initConfig)

// Here you will define your flags and configuration settings.
Expand Down
14 changes: 7 additions & 7 deletions cmd/safes.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var listSafesCmd = &cobra.Command{
$ cybr safes list`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand All @@ -121,7 +121,7 @@ var listMembersCmd = &cobra.Command{
Aliases: []string{"list-member"},
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand All @@ -147,7 +147,7 @@ var addMembersCmd = &cobra.Command{
$ cybr safes add-member -s SafeName -m MemberName --retrieve-account`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand Down Expand Up @@ -251,7 +251,7 @@ var removeMembersCmd = &cobra.Command{
$ cybr safes remove-member -s SafeName -m MemberName`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand All @@ -278,7 +278,7 @@ var addSafeCmd = &cobra.Command{
$ cybr safes add -s SafeName -d Description --cpm ManagingCPM --days 0`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand Down Expand Up @@ -314,7 +314,7 @@ var deleteSafeCmd = &cobra.Command{
$ cybr safes delete -s SafeName`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand All @@ -339,7 +339,7 @@ var updateSafeCmd = &cobra.Command{
$ cybr safes update -t TargetSafeName -s NewSafeName -d NewDesc`,
Run: func(cmd *cobra.Command, args []string) {
// Get config file written to local file system
client, err := pasapi.GetConfig()
client, err := pasapi.GetConfigWithLogger(getLogger())
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
Expand Down
11 changes: 7 additions & 4 deletions pkg/cybr/api/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type AddAccountRequest struct {
// ListAccounts CyberArk user has access to
func (c Client) ListAccounts(query *ListAccountQueryParams) (*ListAccountResponse, error) {
url := fmt.Sprintf("%s/PasswordVault/api/Accounts%s", c.BaseURL, httpJson.GetURLQuery(query))
response, err := httpJson.Get(url, c.SessionToken, c.InsecureTLS)
response, err := httpJson.Get(url, c.SessionToken, c.InsecureTLS, c.Logger)
if err != nil {
return &ListAccountResponse{}, fmt.Errorf("Failed to list accounts. %s", err)
}
Expand All @@ -76,7 +76,7 @@ func (c Client) ListAccounts(query *ListAccountQueryParams) (*ListAccountRespons
// GetAccount details for specific account
func (c Client) GetAccount(accountID string) (*GetAccountResponse, error) {
url := fmt.Sprintf("%s/PasswordVault/api/Accounts/%s", c.BaseURL, accountID)
response, err := httpJson.Get(url, c.SessionToken, c.InsecureTLS)
response, err := httpJson.Get(url, c.SessionToken, c.InsecureTLS, c.Logger)
if err != nil {
return &GetAccountResponse{}, fmt.Errorf("Failed to get account. %s", err)
}
Expand All @@ -90,7 +90,10 @@ func (c Client) GetAccount(accountID string) (*GetAccountResponse, error) {
// AddAccount to cyberark
func (c Client) AddAccount(account AddAccountRequest) (*GetAccountResponse, error) {
url := fmt.Sprintf("%s/PasswordVault/api/Accounts", c.BaseURL)
response, err := httpJson.Post(url, c.SessionToken, account, c.InsecureTLS)
logger := c.Logger.AddSecret(account.Secret)
response, err := httpJson.Post(url, c.SessionToken, account, c.InsecureTLS, logger)
logger = logger.ClearSecrets()

if err != nil {
returnedError, _ := json.Marshal(response)
return &GetAccountResponse{}, fmt.Errorf("Failed to add account. %s. %s", string(returnedError), err)
Expand All @@ -105,7 +108,7 @@ func (c Client) AddAccount(account AddAccountRequest) (*GetAccountResponse, erro
// DeleteAccount from cyberark
func (c Client) DeleteAccount(accountID string) error {
url := fmt.Sprintf("%s/PasswordVault/api/Accounts/%s", c.BaseURL, accountID)
response, err := httpJson.Delete(url, c.SessionToken, c.InsecureTLS)
response, err := httpJson.Delete(url, c.SessionToken, c.InsecureTLS, c.Logger)
if err != nil {
returnedError, _ := json.Marshal(response)
return fmt.Errorf("Failed to delete account '%s'. %s. %s", accountID, string(returnedError), err)
Expand Down
12 changes: 6 additions & 6 deletions pkg/cybr/api/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ListApplication struct {
// ListApplications returns all Application Identities setup in PAS
func (c Client) ListApplications(location string) (*ListApplicationsResponse, error) {
url := fmt.Sprintf("%s/PasswordVault/WebServices/PIMServices.svc/Applications?Location=%s", c.BaseURL, location)
response, err := httpJson.Get(url, c.SessionToken, c.InsecureTLS)
response, err := httpJson.Get(url, c.SessionToken, c.InsecureTLS, c.Logger)
if err != nil {
return &ListApplicationsResponse{}, fmt.Errorf("Error listing applications in location '%s'. %s", location, err)
}
Expand Down Expand Up @@ -62,7 +62,7 @@ type ListAuthentication struct {
// ListApplicationAuthenticationMethods returns all auth methods for a specific Application Identity
func (c Client) ListApplicationAuthenticationMethods(appID string) (*ListApplicationAuthenticationMethodsResponse, error) {
url := fmt.Sprintf("%s/PasswordVault/WebServices/PIMServices.svc/Applications/%s/Authentications", c.BaseURL, appID)
response, err := httpJson.Get(url, c.SessionToken, c.InsecureTLS)
response, err := httpJson.Get(url, c.SessionToken, c.InsecureTLS, c.Logger)
if err != nil {
return &ListApplicationAuthenticationMethodsResponse{}, fmt.Errorf("Error listing application's '%s' authentication methods. %s", appID, err)
}
Expand Down Expand Up @@ -95,7 +95,7 @@ type Application struct {
// AddApplication add an applications to PAS
func (c Client) AddApplication(application AddApplicationRequest) error {
url := fmt.Sprintf("%s/PasswordVault/WebServices/PIMServices.svc/Applications", c.BaseURL)
response, err := httpJson.Post(url, c.SessionToken, application, c.InsecureTLS)
response, err := httpJson.Post(url, c.SessionToken, application, c.InsecureTLS, c.Logger)
if err != nil {
returnedError, _ := json.Marshal(response)
return fmt.Errorf("Error adding application '%s' authentication methods. %s. %s", application.Application.AppID, string(returnedError), err)
Expand All @@ -106,7 +106,7 @@ func (c Client) AddApplication(application AddApplicationRequest) error {
// DeleteApplication delete an applications to PAS
func (c Client) DeleteApplication(appID string) error {
url := fmt.Sprintf("%s/PasswordVault/WebServices/PIMServices.svc/Applications/%s", c.BaseURL, url.QueryEscape(appID))
response, err := httpJson.Delete(url, c.SessionToken, c.InsecureTLS)
response, err := httpJson.Delete(url, c.SessionToken, c.InsecureTLS, c.Logger)
if err != nil {
returnedError, _ := json.Marshal(response)
return fmt.Errorf("Error deleting application '%s' authentication methods. %s. %s", appID, string(returnedError), err)
Expand All @@ -130,7 +130,7 @@ type ApplicationAuthenticationMethod struct {
// AddApplicationAuthenticationMethod add authentication method to an application
func (c Client) AddApplicationAuthenticationMethod(appID string, authenticationMethod AddApplicationAuthenticationRequest) error {
url := fmt.Sprintf("%s/PasswordVault/WebServices/PIMServices.svc/Applications/%s/Authentications/", c.BaseURL, url.QueryEscape(appID))
response, err := httpJson.Post(url, c.SessionToken, authenticationMethod, c.InsecureTLS)
response, err := httpJson.Post(url, c.SessionToken, authenticationMethod, c.InsecureTLS, c.Logger)
if err != nil {
returnedError, _ := json.Marshal(response)
return fmt.Errorf("Error adding application authentication method to '%s'. %s. %s", appID, string(returnedError), err)
Expand All @@ -141,7 +141,7 @@ func (c Client) AddApplicationAuthenticationMethod(appID string, authenticationM
// DeleteApplicationAuthenticationMethod delete an applications authentication method
func (c Client) DeleteApplicationAuthenticationMethod(appID string, authnMethodID string) error {
url := fmt.Sprintf("%s/PasswordVault/WebServices/PIMServices.svc/Applications/%s/Authentications/%s", c.BaseURL, url.QueryEscape(appID), url.QueryEscape(authnMethodID))
response, err := httpJson.Delete(url, c.SessionToken, c.InsecureTLS)
response, err := httpJson.Delete(url, c.SessionToken, c.InsecureTLS, c.Logger)
if err != nil {
returnedError, _ := json.Marshal(response)
return fmt.Errorf("Error deleting application '%s' authentication methods. %s. %s", appID, string(returnedError), err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cybr/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (c *Client) Logon(req LogonRequest) error {
}

url := fmt.Sprintf("%s/PasswordVault/api/auth/%s/logon", c.BaseURL, c.AuthType)
token, err := httpJson.SendRequestRaw(url, "POST", "", req, c.InsecureTLS)
token, err := httpJson.SendRequestRaw(url, "POST", "", req, c.InsecureTLS, c.Logger)
if err != nil {
return fmt.Errorf("Failed to authenticate to the PAS REST API. %s", err)
}
Expand All @@ -37,7 +37,7 @@ func (c *Client) Logon(req LogonRequest) error {
func (c Client) Logoff() error {
// Set URL for request
url := fmt.Sprintf("%s/PasswordVault/api/auth/logoff", c.BaseURL)
_, err := httpJson.Post(url, c.SessionToken, nil, c.InsecureTLS)
_, err := httpJson.Post(url, c.SessionToken, nil, c.InsecureTLS, c.Logger)
if err != nil {
return fmt.Errorf("Unable to logoff PAS REST API Web Service. %s", err)
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/cybr/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/gob"
"fmt"
"os"

"github.com/infamousjoeg/cybr-cli/pkg/logger"
)

// Client contains the data necessary for requests to pass successfully
Expand All @@ -12,6 +14,7 @@ type Client struct {
AuthType string
InsecureTLS bool
SessionToken string
Logger logger.Logger
}

func getUserHomeDir() (string, error) {
Expand Down Expand Up @@ -97,6 +100,13 @@ func GetConfig() (Client, error) {
return client, nil
}

// GetConfigWithLogger is the same as GetConfig except it also sets the logger
func GetConfigWithLogger(logger logger.Logger) (Client, error) {
client, err := GetConfig()
client.Logger = logger
return client, err
}

// RemoveConfig file on the local filesystem
func (c *Client) RemoveConfig() error {
// Get user home directory
Expand Down
Loading