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

Fixes #140 authenticate to conjur using authn-iam #162

Merged
merged 18 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Fixes 167 Update cybr users unsuspend to v2 API (#168)
  • Loading branch information
infamousjoeg authored Sep 29, 2022
commit 5cb5078374974d096f5db7b4c29cda1894bc4f8f
12 changes: 6 additions & 6 deletions cmd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,21 @@ var unsuspendUserCmd = &cobra.Command{
Long: `Activates a suspended user. It does not activate an inactive user.

Example Usage:
$ cybr users unsuspend --username userName`,
$ cybr users unsuspend --id 9`,
Run: func(cmd *cobra.Command, args []string) {
client, err := pasapi.GetConfig()
if err != nil {
log.Fatalf("Failed to read configuration file. %s", err)
return
}

err = client.UnsuspendUser(Username)
err = client.UnsuspendUser(UserID)
if err != nil {
log.Fatalf("Failed to unsuspend user '%s'. %s", Username, err)
log.Fatalf("Failed to unsuspend user with id '%d'. %s", UserID, err)
return
}

fmt.Printf("Successfully unsuspended user '%s'\n", Username)
fmt.Printf("Successfully unsuspended user with id '%d'\n", UserID)
},
}

Expand Down Expand Up @@ -224,8 +224,8 @@ var addUserCmd = &cobra.Command{

func init() {
// unsuspend
unsuspendUserCmd.Flags().StringVarP(&Username, "username", "u", "", "The user you would like to unsuspend")
unsuspendUserCmd.MarkFlagRequired("username")
unsuspendUserCmd.Flags().IntVarP(&UserID, "id", "i", 0, "The ID of the user you wish to unsuspend")
unsuspendUserCmd.MarkFlagRequired("id")

// list
listUsersCmd.Flags().StringVarP(&Search, "search", "s", "", "Search for the username, first name or last name of a user")
Expand Down
6 changes: 0 additions & 6 deletions pkg/cybr/api/requests/unsuspenduser.go

This file was deleted.

13 changes: 4 additions & 9 deletions pkg/cybr/api/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"encoding/json"
"fmt"
"net/url"

"github.com/infamousjoeg/cybr-cli/pkg/cybr/api/queries"
"github.com/infamousjoeg/cybr-cli/pkg/cybr/api/requests"
Expand All @@ -12,17 +11,13 @@ import (
)

// UnsuspendUser activates a suspended user. It does not activate an inactive user.
func (c Client) UnsuspendUser(username string) error {
url := fmt.Sprintf("%s/PasswordVault/WebServices/PIMServices.svc/Users/%s", c.BaseURL, url.QueryEscape(username))
func (c Client) UnsuspendUser(userID int) error {
url := fmt.Sprintf("%s/PasswordVault/api/Users/%d/activate", c.BaseURL, userID)

body := requests.UnsuspendUser{
Suspended: false,
}

response, err := httpJson.Put(url, c.SessionToken, body, c.InsecureTLS, c.Logger)
response, err := httpJson.Post(url, c.SessionToken, nil, c.InsecureTLS, c.Logger)
if err != nil {
returnedError, _ := json.Marshal(response)
return fmt.Errorf("Failed to unsuspend user '%s'. %s. %s", username, string(returnedError), err)
return fmt.Errorf("Failed to unsuspend user with id '%d'. %s. %s", userID, string(returnedError), err)
}
return nil
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/cybr/api/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ import (
func TestUnsuspendUserSuccess(t *testing.T) {
client, err := defaultPASAPIClient(t)

err = client.UnsuspendUser(username)
userID := 1
err = client.UnsuspendUser(userID)
if err != nil {
t.Errorf("Failed to unsuspend user '%s'. %s", username, err)
t.Errorf("Failed to unsuspend user with id '%d'. %s", userID, err)
}
}

func TestUnsuspendUserInvalidUsername(t *testing.T) {
client, err := defaultPASAPIClient(t)

invalidUsername := "invalidUsername"
err = client.UnsuspendUser(invalidUsername)
invalidUserID := 999999
err = client.UnsuspendUser(invalidUserID)
if err == nil {
t.Errorf("Unsuspended user '%s' but user should not exist. This should never happen", invalidUsername)
t.Errorf("Unsuspended user with id '%d' but user should not exist. This should never happen", invalidUserID)
}
}

Expand Down