From 4e212e53b6ac9b7c4aa0ba53e5da70c501254736 Mon Sep 17 00:00:00 2001 From: Nelson Isioma Date: Wed, 5 Mar 2025 19:43:09 +0100 Subject: [PATCH] wip 1 --- api/api.go | 66 +++---------------------------------------- api/auth.go | 6 ++-- api/client.go | 18 ++---------- api/comments.go | 8 +++--- api/favorites.go | 4 +-- api/folders.go | 12 ++++---- api/gpgkey.go | 4 +-- api/groups.go | 12 ++++---- api/healthcheck.go | 4 +-- api/permissions.go | 2 +- api/resource_types.go | 4 +-- api/resources.go | 12 ++++---- api/roles.go | 2 +- api/secrets.go | 2 +- api/setup.go | 4 +-- api/share.go | 8 +++--- api/users.go | 12 ++++---- 17 files changed, 54 insertions(+), 126 deletions(-) diff --git a/api/api.go b/api/api.go index 7a2f135..f8ee627 100644 --- a/api/api.go +++ b/api/api.go @@ -25,79 +25,21 @@ type APIHeader struct { Code int `json:"code"` } -// Deprecated: DoCustomRequest is deprecated and will be removed in a future release, use DoCustomRequestV5 instead. +// DoCustomRequest executes a custom request and returns an APIResponse. func (c *Client) DoCustomRequest(ctx context.Context, method, path, version string, body interface{}, opts interface{}) (*APIResponse, error) { _, response, err := c.DoCustomRequestAndReturnRawResponse(ctx, method, path, version, body, opts) return response, err } -// DoCustomRequestV5 executes a custom request and returns an APIResponse -func (c *Client) DoCustomRequestV5(ctx context.Context, method, path string, body interface{}, opts interface{}) (*APIResponse, error) { - _, response, err := c.DoCustomRequestAndReturnRawResponseV5(ctx, method, path, body, opts) - - return response, err -} - -// Deprecated: DoCustomRequestAndReturnRawResponse is deprecated and will be removed in a future release, use DoCustomRequestAndReturnRawResponseV5 instead. +// DoCustomRequestAndReturnRawResponse executes a custom request and returns an APIResponse and the Raw HTTP Response. func (c *Client) DoCustomRequestAndReturnRawResponse(ctx context.Context, method, path, version string, body interface{}, opts interface{}) (*http.Response, *APIResponse, error) { - firstTime := true -start: - u, err := generateURL(*c.baseURL, path, version, opts) - if err != nil { - return nil, nil, fmt.Errorf("Generating Path: %w", err) - } - - req, err := c.newRequest(method, u, body) - if err != nil { - return nil, nil, fmt.Errorf("Creating New Request: %w", err) - } - - var res APIResponse - r, err := c.do(ctx, req, &res) - if err != nil { - return r, &res, fmt.Errorf("Doing Request: %w", err) - } - - // Because of MFA i need to do the csrf token stuff here - if c.csrfToken.Name == "" { - for _, cookie := range r.Cookies() { - if cookie.Name == "csrfToken" { - c.csrfToken = *cookie - } - } - } - - if res.Header.Status == "success" { - return r, &res, nil - } else if res.Header.Status == "error" { - if res.Header.Code == 403 && strings.HasSuffix(res.Header.URL, "/mfa/verify/error.json") { - if !firstTime { - // if we are here this probably means that the MFA callback is broken, to prevent a infinite loop lets error here - return r, &res, fmt.Errorf("Got MFA challenge twice in a row, is your MFA Callback broken? Bailing to prevent loop...:") - } - if c.MFACallback != nil { - c.mfaToken, err = c.MFACallback(ctx, c, &res) - if err != nil { - return r, &res, fmt.Errorf("MFA Callback: %w", err) - } - // ok, we got the MFA challenge and the callback presumably handled it so we can retry the original request - firstTime = false - goto start - } else { - return r, &res, fmt.Errorf("Got MFA Challenge but the MFA callback is not defined") - } - } - return r, &res, fmt.Errorf("%w: Message: %v, Body: %v", ErrAPIResponseErrorStatusCode, res.Header.Message, string(res.Body)) - } else { - return r, &res, fmt.Errorf("%w: Message: %v, Body: %v", ErrAPIResponseUnknownStatusCode, res.Header.Message, string(res.Body)) - } + return c.DoCustomRequestAndReturnRawResponseV5(ctx, method, path, body, opts) } -// DoCustomRequestAndReturnRawResponseV5 executes a custom request and returns an APIResponse and the Raw HTTP Response func (c *Client) DoCustomRequestAndReturnRawResponseV5(ctx context.Context, method, path string, body interface{}, opts interface{}) (*http.Response, *APIResponse, error) { firstTime := true start: - u, err := generateBaseURL(*c.baseURL, path, opts) + u, err := generateURL(*c.baseURL, path, opts) if err != nil { return nil, nil, fmt.Errorf("Generating Path: %w", err) } diff --git a/api/auth.go b/api/auth.go index 128b1b3..1f41dd7 100644 --- a/api/auth.go +++ b/api/auth.go @@ -25,7 +25,7 @@ type GPGAuth struct { // CheckSession Check to see if you have a Valid Session func (c *Client) CheckSession(ctx context.Context) bool { - _, err := c.DoCustomRequestV5(ctx, "GET", "auth/is-authenticated.json", nil, nil) + _, err := c.DoCustomRequest(ctx, "GET", "auth/is-authenticated.json", nil, nil) return err == nil } @@ -99,7 +99,7 @@ func (c *Client) Login(ctx context.Context) error { } // Because of MFA, the custom Request Function now Fetches the CSRF token, we still need the user for his public key - apiMsg, err := c.DoCustomRequestV5(ctx, "GET", "/users/me.json", nil, nil) + apiMsg, err := c.DoCustomRequest(ctx, "GET", "/users/me.json", nil, nil) if err != nil { return fmt.Errorf("Getting CSRF Token: %w", err) } @@ -134,7 +134,7 @@ func (c *Client) Login(ctx context.Context) error { // Logout closes the current Session on the Passbolt server func (c *Client) Logout(ctx context.Context) error { - _, err := c.DoCustomRequestV5(ctx, "GET", "/auth/logout.json", nil, nil) + _, err := c.DoCustomRequest(ctx, "GET", "/auth/logout.json", nil, nil) if err != nil { return fmt.Errorf("Doing Logout Request: %w", err) } diff --git a/api/client.go b/api/client.go index 11d08ea..b373f52 100644 --- a/api/client.go +++ b/api/client.go @@ -169,21 +169,7 @@ func (c *Client) log(msg string, args ...interface{}) { fmt.Printf("[go-passbolt] "+msg+"\n", args...) } -func generateURL(base url.URL, p, version string, opt interface{}) (string, error) { - base.Path = path.Join(base.Path, p) - - vs, err := query.Values(opt) - if err != nil { - return "", fmt.Errorf("Getting URL Query Values: %w", err) - } - if version != "" { - vs.Add("api-version", version) - } - base.RawQuery = vs.Encode() - return base.String(), nil -} - -func generateBaseURL(base url.URL, p string, opt interface{}) (string, error) { +func generateURL(base url.URL, p string, opt interface{}) (string, error) { base.Path = path.Join(base.Path, p) vs, err := query.Values(opt) if err != nil { @@ -201,7 +187,7 @@ func (c *Client) GetUserID() string { // GetPublicKey gets the Public Key and Fingerprint of the Passbolt instance func (c *Client) GetPublicKey(ctx context.Context) (string, string, error) { - msg, err := c.DoCustomRequestV5(ctx, "GET", "/auth/verify.json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/auth/verify.json", nil, nil) if err != nil { return "", "", fmt.Errorf("Doing Request: %w", err) } diff --git a/api/comments.go b/api/comments.go index 2cc14b5..0ebe6b6 100644 --- a/api/comments.go +++ b/api/comments.go @@ -34,7 +34,7 @@ func (c *Client) GetComments(ctx context.Context, resourceID string, opts *GetCo if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "GET", "/comments/resource/"+resourceID+".json", nil, opts) + msg, err := c.DoCustomRequest(ctx, "GET", "/comments/resource/"+resourceID+".json", nil, opts) if err != nil { return nil, err } @@ -53,7 +53,7 @@ func (c *Client) CreateComment(ctx context.Context, resourceID string, comment C if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "POST", "/comments/resource/"+resourceID+".json", comment, nil) + msg, err := c.DoCustomRequest(ctx, "POST", "/comments/resource/"+resourceID+".json", comment, nil) if err != nil { return nil, err } @@ -71,7 +71,7 @@ func (c *Client) UpdateComment(ctx context.Context, commentID string, comment Co if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "PUT", "/comments/"+commentID+".json", comment, nil) + msg, err := c.DoCustomRequest(ctx, "PUT", "/comments/"+commentID+".json", comment, nil) if err != nil { return nil, err } @@ -89,7 +89,7 @@ func (c *Client) DeleteComment(ctx context.Context, commentID string) error { if err != nil { return fmt.Errorf("Checking ID format: %w", err) } - _, err = c.DoCustomRequestV5(ctx, "DELETE", "/comments/"+commentID+".json", nil, nil) + _, err = c.DoCustomRequest(ctx, "DELETE", "/comments/"+commentID+".json", nil, nil) if err != nil { return err } diff --git a/api/favorites.go b/api/favorites.go index c939478..d77bdaa 100644 --- a/api/favorites.go +++ b/api/favorites.go @@ -21,7 +21,7 @@ func (c *Client) CreateFavorite(ctx context.Context, resourceID string) (*Favori if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "POST", "/favorites/resource/"+resourceID+".json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "POST", "/favorites/resource/"+resourceID+".json", nil, nil) if err != nil { return nil, err } @@ -40,7 +40,7 @@ func (c *Client) DeleteFavorite(ctx context.Context, favoriteID string) error { if err != nil { return fmt.Errorf("Checking ID format: %w", err) } - _, err = c.DoCustomRequestV5(ctx, "DELETE", "/favorites/"+favoriteID+".json", nil, nil) + _, err = c.DoCustomRequest(ctx, "DELETE", "/favorites/"+favoriteID+".json", nil, nil) if err != nil { return err } diff --git a/api/folders.go b/api/folders.go index 91c0625..8450060 100644 --- a/api/folders.go +++ b/api/folders.go @@ -55,7 +55,7 @@ type GetFolderOptions struct { // GetFolders gets all Folders from the Passboltserver func (c *Client) GetFolders(ctx context.Context, opts *GetFoldersOptions) ([]Folder, error) { - msg, err := c.DoCustomRequestV5(ctx, "GET", "/folders.json", nil, opts) + msg, err := c.DoCustomRequest(ctx, "GET", "/folders.json", nil, opts) if err != nil { return nil, err } @@ -70,7 +70,7 @@ func (c *Client) GetFolders(ctx context.Context, opts *GetFoldersOptions) ([]Fol // CreateFolder Creates a new Passbolt Folder func (c *Client) CreateFolder(ctx context.Context, folder Folder) (*Folder, error) { - msg, err := c.DoCustomRequestV5(ctx, "POST", "/folders.json", folder, nil) + msg, err := c.DoCustomRequest(ctx, "POST", "/folders.json", folder, nil) if err != nil { return nil, err } @@ -88,7 +88,7 @@ func (c *Client) GetFolder(ctx context.Context, folderID string, opts *GetFolder if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "GET", "/folders/"+folderID+".json", nil, opts) + msg, err := c.DoCustomRequest(ctx, "GET", "/folders/"+folderID+".json", nil, opts) if err != nil { return nil, err } @@ -107,7 +107,7 @@ func (c *Client) UpdateFolder(ctx context.Context, folderID string, folder Folde if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "PUT", "/folders/"+folderID+".json", folder, nil) + msg, err := c.DoCustomRequest(ctx, "PUT", "/folders/"+folderID+".json", folder, nil) if err != nil { return nil, err } @@ -125,7 +125,7 @@ func (c *Client) DeleteFolder(ctx context.Context, folderID string) error { if err != nil { return fmt.Errorf("Checking ID format: %w", err) } - _, err = c.DoCustomRequestV5(ctx, "DELETE", "/folders/"+folderID+".json", nil, nil) + _, err = c.DoCustomRequest(ctx, "DELETE", "/folders/"+folderID+".json", nil, nil) if err != nil { return err } @@ -138,7 +138,7 @@ func (c *Client) MoveFolder(ctx context.Context, folderID, folderParentID string if err != nil { return fmt.Errorf("Checking ID format: %w", err) } - _, err = c.DoCustomRequestV5(ctx, "PUT", "/move/folder/"+folderID+".json", Folder{ + _, err = c.DoCustomRequest(ctx, "PUT", "/move/folder/"+folderID+".json", Folder{ FolderParentID: folderParentID, }, nil) if err != nil { diff --git a/api/gpgkey.go b/api/gpgkey.go index 43bcfa1..c247a40 100644 --- a/api/gpgkey.go +++ b/api/gpgkey.go @@ -29,7 +29,7 @@ type GetGPGKeysOptions struct { // GetGPGKeys gets all Passbolt GPGKeys func (c *Client) GetGPGKeys(ctx context.Context, opts *GetGPGKeysOptions) ([]GPGKey, error) { - msg, err := c.DoCustomRequestV5(ctx, "GET", "/gpgkeys.json", nil, opts) + msg, err := c.DoCustomRequest(ctx, "GET", "/gpgkeys.json", nil, opts) if err != nil { return nil, err } @@ -48,7 +48,7 @@ func (c *Client) GetGPGKey(ctx context.Context, gpgkeyID string) (*GPGKey, error if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "GET", "/gpgkeys/"+gpgkeyID+".json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/gpgkeys/"+gpgkeyID+".json", nil, nil) if err != nil { return nil, err } diff --git a/api/groups.go b/api/groups.go index 9b84d48..f3c1b60 100644 --- a/api/groups.go +++ b/api/groups.go @@ -96,7 +96,7 @@ type UpdateGroupDryRunSecretsNeeded struct { // GetGroups gets all Passbolt Groups func (c *Client) GetGroups(ctx context.Context, opts *GetGroupsOptions) ([]Group, error) { - msg, err := c.DoCustomRequestV5(ctx, "GET", "/groups.json", nil, opts) + msg, err := c.DoCustomRequest(ctx, "GET", "/groups.json", nil, opts) if err != nil { return nil, err } @@ -111,7 +111,7 @@ func (c *Client) GetGroups(ctx context.Context, opts *GetGroupsOptions) ([]Group // CreateGroup Creates a new Passbolt Group func (c *Client) CreateGroup(ctx context.Context, group Group) (*Group, error) { - msg, err := c.DoCustomRequestV5(ctx, "POST", "/groups.json", group, nil) + msg, err := c.DoCustomRequest(ctx, "POST", "/groups.json", group, nil) if err != nil { return nil, err } @@ -129,7 +129,7 @@ func (c *Client) GetGroup(ctx context.Context, groupID string) (*Group, error) { if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "GET", "/groups/"+groupID+".json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/groups/"+groupID+".json", nil, nil) if err != nil { return nil, err } @@ -148,7 +148,7 @@ func (c *Client) UpdateGroup(ctx context.Context, groupID string, update GroupUp if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "PUT", "/groups/"+groupID+".json", update, nil) + msg, err := c.DoCustomRequest(ctx, "PUT", "/groups/"+groupID+".json", update, nil) if err != nil { return nil, err } @@ -166,7 +166,7 @@ func (c *Client) UpdateGroupDryRun(ctx context.Context, groupID string, update G if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "PUT", "/groups/"+groupID+"/dry-run.json", update, nil) + msg, err := c.DoCustomRequest(ctx, "PUT", "/groups/"+groupID+"/dry-run.json", update, nil) if err != nil { return nil, err } @@ -184,7 +184,7 @@ func (c *Client) DeleteGroup(ctx context.Context, groupID string) error { if err != nil { return fmt.Errorf("Checking ID format: %w", err) } - _, err = c.DoCustomRequestV5(ctx, "DELETE", "/groups/"+groupID+".json", nil, nil) + _, err = c.DoCustomRequest(ctx, "DELETE", "/groups/"+groupID+".json", nil, nil) if err != nil { return err } diff --git a/api/healthcheck.go b/api/healthcheck.go index 9a16bbe..1030c54 100644 --- a/api/healthcheck.go +++ b/api/healthcheck.go @@ -7,7 +7,7 @@ import ( // PerformHealthCheck performs a Health Check func (c *Client) PerformHealthCheck(ctx context.Context) (json.RawMessage, error) { - msg, err := c.DoCustomRequestV5(ctx, "GET", "/healthcheck.json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/healthcheck.json", nil, nil) if err != nil { return nil, err } @@ -17,7 +17,7 @@ func (c *Client) PerformHealthCheck(ctx context.Context) (json.RawMessage, error // GetHealthCheckStatus gets the Server Status func (c *Client) GetHealthCheckStatus(ctx context.Context) (string, error) { - msg, err := c.DoCustomRequestV5(ctx, "GET", "/healthcheck/status.json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/healthcheck/status.json", nil, nil) if err != nil { return "", err } diff --git a/api/permissions.go b/api/permissions.go index 2288003..19cc78b 100644 --- a/api/permissions.go +++ b/api/permissions.go @@ -26,7 +26,7 @@ func (c *Client) GetResourcePermissions(ctx context.Context, resourceID string) if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "GET", "/permissions/resource/"+resourceID+".json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/permissions/resource/"+resourceID+".json", nil, nil) if err != nil { return nil, err } diff --git a/api/resource_types.go b/api/resource_types.go index 49eb1ec..cd8e119 100644 --- a/api/resource_types.go +++ b/api/resource_types.go @@ -27,7 +27,7 @@ type GetResourceTypesOptions struct { // GetResourceTypes gets all Passbolt Resource Types func (c *Client) GetResourceTypes(ctx context.Context, opts *GetResourceTypesOptions) ([]ResourceType, error) { - msg, err := c.DoCustomRequestV5(ctx, "GET", "/resource-types.json", nil, opts) + msg, err := c.DoCustomRequest(ctx, "GET", "/resource-types.json", nil, opts) if err != nil { return nil, err } @@ -46,7 +46,7 @@ func (c *Client) GetResourceType(ctx context.Context, typeID string) (*ResourceT if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "GET", "/resource-types/"+typeID+".json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/resource-types/"+typeID+".json", nil, nil) if err != nil { return nil, err } diff --git a/api/resources.go b/api/resources.go index 54295d4..aa2a9c3 100644 --- a/api/resources.go +++ b/api/resources.go @@ -62,7 +62,7 @@ type GetResourcesOptions struct { // GetResources gets all Passbolt Resources func (c *Client) GetResources(ctx context.Context, opts *GetResourcesOptions) ([]Resource, error) { - msg, err := c.DoCustomRequestV5(ctx, "GET", "/resources.json", nil, opts) + msg, err := c.DoCustomRequest(ctx, "GET", "/resources.json", nil, opts) if err != nil { return nil, err } @@ -77,7 +77,7 @@ func (c *Client) GetResources(ctx context.Context, opts *GetResourcesOptions) ([ // CreateResource Creates a new Passbolt Resource func (c *Client) CreateResource(ctx context.Context, resource Resource) (*Resource, error) { - msg, err := c.DoCustomRequestV5(ctx, "POST", "/resources.json", resource, nil) + msg, err := c.DoCustomRequest(ctx, "POST", "/resources.json", resource, nil) if err != nil { return nil, err } @@ -95,7 +95,7 @@ func (c *Client) GetResource(ctx context.Context, resourceID string) (*Resource, if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "GET", "/resources/"+resourceID+".json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/resources/"+resourceID+".json", nil, nil) if err != nil { return nil, err } @@ -114,7 +114,7 @@ func (c *Client) UpdateResource(ctx context.Context, resourceID string, resource if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "PUT", "/resources/"+resourceID+".json", resource, nil) + msg, err := c.DoCustomRequest(ctx, "PUT", "/resources/"+resourceID+".json", resource, nil) if err != nil { return nil, err } @@ -132,7 +132,7 @@ func (c *Client) DeleteResource(ctx context.Context, resourceID string) error { if err != nil { return fmt.Errorf("Checking ID format: %w", err) } - _, err = c.DoCustomRequestV5(ctx, "DELETE", "/resources/"+resourceID+".json", nil, nil) + _, err = c.DoCustomRequest(ctx, "DELETE", "/resources/"+resourceID+".json", nil, nil) if err != nil { return err } @@ -145,7 +145,7 @@ func (c *Client) MoveResource(ctx context.Context, resourceID, folderParentID st if err != nil { return fmt.Errorf("Checking ID format: %w", err) } - _, err = c.DoCustomRequestV5(ctx, "PUT", "/move/resource/"+resourceID+".json", Resource{ + _, err = c.DoCustomRequest(ctx, "PUT", "/move/resource/"+resourceID+".json", Resource{ FolderParentID: folderParentID, }, nil) if err != nil { diff --git a/api/roles.go b/api/roles.go index fa3f3d6..0d194d5 100644 --- a/api/roles.go +++ b/api/roles.go @@ -41,7 +41,7 @@ type URL struct { // GetRoles gets all Passbolt Roles func (c *Client) GetRoles(ctx context.Context) ([]Role, error) { - msg, err := c.DoCustomRequestV5(ctx, "GET", "/roles.json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/roles.json", nil, nil) if err != nil { return nil, err } diff --git a/api/secrets.go b/api/secrets.go index 595c064..6547a67 100644 --- a/api/secrets.go +++ b/api/secrets.go @@ -47,7 +47,7 @@ func (c *Client) GetSecret(ctx context.Context, resourceID string) (*Secret, err if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "GET", "/secrets/resource/"+resourceID+".json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/secrets/resource/"+resourceID+".json", nil, nil) if err != nil { return nil, err } diff --git a/api/setup.go b/api/setup.go index 86b2c80..5ef2e36 100644 --- a/api/setup.go +++ b/api/setup.go @@ -30,7 +30,7 @@ func (c *Client) SetupInstall(ctx context.Context, userID, token string) (*Setup if err != nil { return nil, fmt.Errorf("Checking Token format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "GET", "/setup/install/"+userID+"/"+token+".json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/setup/install/"+userID+"/"+token+".json", nil, nil) if err != nil { return nil, err } @@ -49,7 +49,7 @@ func (c *Client) SetupComplete(ctx context.Context, userID string, request Setup if err != nil { return fmt.Errorf("Checking ID format: %w", err) } - _, err = c.DoCustomRequestV5(ctx, "POST", "/setup/complete/"+userID+".json", request, nil) + _, err = c.DoCustomRequest(ctx, "POST", "/setup/complete/"+userID+".json", request, nil) if err != nil { return err } diff --git a/api/share.go b/api/share.go index c78ddfa..100f7d8 100644 --- a/api/share.go +++ b/api/share.go @@ -47,7 +47,7 @@ type SearchAROsOptions struct { // SearchAROs gets all Passbolt AROs func (c *Client) SearchAROs(ctx context.Context, opts SearchAROsOptions) ([]ARO, error) { //set is_new to true in permission - msg, err := c.DoCustomRequestV5(ctx, "GET", "/share/search-aros.json", nil, opts) + msg, err := c.DoCustomRequest(ctx, "GET", "/share/search-aros.json", nil, opts) if err != nil { return nil, err } @@ -66,7 +66,7 @@ func (c *Client) ShareResource(ctx context.Context, resourceID string, shareRequ if err != nil { return fmt.Errorf("Checking ID format: %w", err) } - _, err = c.DoCustomRequestV5(ctx, "PUT", "/share/resource/"+resourceID+".json", shareRequest, nil) + _, err = c.DoCustomRequest(ctx, "PUT", "/share/resource/"+resourceID+".json", shareRequest, nil) if err != nil { return err } @@ -81,7 +81,7 @@ func (c *Client) ShareFolder(ctx context.Context, folderID string, permissions [ return fmt.Errorf("Checking ID format: %w", err) } f := Folder{Permissions: permissions} - _, err = c.DoCustomRequestV5(ctx, "PUT", "/share/folder/"+folderID+".json", f, nil) + _, err = c.DoCustomRequest(ctx, "PUT", "/share/folder/"+folderID+".json", f, nil) if err != nil { return err } @@ -95,7 +95,7 @@ func (c *Client) SimulateShareResource(ctx context.Context, resourceID string, s if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "POST", "/share/simulate/resource/"+resourceID+".json", shareRequest, nil) + msg, err := c.DoCustomRequest(ctx, "POST", "/share/simulate/resource/"+resourceID+".json", shareRequest, nil) if err != nil { return nil, err } diff --git a/api/users.go b/api/users.go index 26c4487..3e70186 100644 --- a/api/users.go +++ b/api/users.go @@ -48,7 +48,7 @@ type GetUsersOptions struct { // GetUsers gets all Passbolt Users func (c *Client) GetUsers(ctx context.Context, opts *GetUsersOptions) ([]User, error) { - msg, err := c.DoCustomRequestV5(ctx, "GET", "/users.json", nil, opts) + msg, err := c.DoCustomRequest(ctx, "GET", "/users.json", nil, opts) if err != nil { return nil, err } @@ -63,7 +63,7 @@ func (c *Client) GetUsers(ctx context.Context, opts *GetUsersOptions) ([]User, e // CreateUser Creates a new Passbolt User func (c *Client) CreateUser(ctx context.Context, user User) (*User, error) { - msg, err := c.DoCustomRequestV5(ctx, "POST", "/users.json", user, nil) + msg, err := c.DoCustomRequest(ctx, "POST", "/users.json", user, nil) if err != nil { return nil, err } @@ -86,7 +86,7 @@ func (c *Client) GetUser(ctx context.Context, userID string) (*User, error) { if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "GET", "/users/"+userID+".json", nil, nil) + msg, err := c.DoCustomRequest(ctx, "GET", "/users/"+userID+".json", nil, nil) if err != nil { return nil, err } @@ -105,7 +105,7 @@ func (c *Client) UpdateUser(ctx context.Context, userID string, user User) (*Use if err != nil { return nil, fmt.Errorf("Checking ID format: %w", err) } - msg, err := c.DoCustomRequestV5(ctx, "PUT", "/users/"+userID+".json", user, nil) + msg, err := c.DoCustomRequest(ctx, "PUT", "/users/"+userID+".json", user, nil) if err != nil { return nil, err } @@ -123,7 +123,7 @@ func (c *Client) DeleteUser(ctx context.Context, userID string) error { if err != nil { return fmt.Errorf("Checking ID format: %w", err) } - _, err = c.DoCustomRequestV5(ctx, "DELETE", "/users/"+userID+".json", nil, nil) + _, err = c.DoCustomRequest(ctx, "DELETE", "/users/"+userID+".json", nil, nil) if err != nil { return err } @@ -136,7 +136,7 @@ func (c *Client) DeleteUserDryrun(ctx context.Context, userID string) error { if err != nil { return fmt.Errorf("Checking ID format: %w", err) } - _, err = c.DoCustomRequestV5(ctx, "DELETE", "/users/"+userID+"/dry-run.json", nil, nil) + _, err = c.DoCustomRequest(ctx, "DELETE", "/users/"+userID+"/dry-run.json", nil, nil) if err != nil { return err }