mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-09 17:48:20 +00:00
feat: deprecating api-version query parameter
This commit is contained in:
parent
b919c3e09d
commit
c3c816d42c
19 changed files with 130 additions and 57 deletions
66
api/api.go
66
api/api.go
|
@ -25,13 +25,20 @@ type APIHeader struct {
|
|||
Code int `json:"code"`
|
||||
}
|
||||
|
||||
// DoCustomRequest Executes a Custom Request and returns a APIResponse
|
||||
// Deprecated: DoCustomRequest is deprecated and will be removed in a future release, use DoCustomRequestV5 instead.
|
||||
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
|
||||
}
|
||||
|
||||
// DoCustomRequestAndReturnRawResponse Executes a Custom Request and returns a APIResponse and the Raw HTTP Response
|
||||
// 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.
|
||||
func (c *Client) DoCustomRequestAndReturnRawResponse(ctx context.Context, method, path, version string, body interface{}, opts interface{}) (*http.Response, *APIResponse, error) {
|
||||
firstTime := true
|
||||
start:
|
||||
|
@ -85,3 +92,58 @@ start:
|
|||
return r, &res, fmt.Errorf("%w: Message: %v, Body: %v", ErrAPIResponseUnknownStatusCode, res.Header.Message, string(res.Body))
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
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 an 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))
|
||||
}
|
||||
}
|
||||
|
|
10
api/auth.go
10
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.DoCustomRequest(ctx, "GET", "auth/is-authenticated.json", "v2", nil, nil)
|
||||
_, err := c.DoCustomRequestV5(ctx, "GET", "auth/is-authenticated.json", nil, nil)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ func (c *Client) Login(ctx context.Context) error {
|
|||
}
|
||||
data := Login{&GPGAuth{KeyID: privateKeyObj.GetFingerprint()}}
|
||||
|
||||
res, _, err := c.DoCustomRequestAndReturnRawResponse(ctx, "POST", "/auth/login.json", "v2", data, nil)
|
||||
res, _, err := c.DoCustomRequestAndReturnRawResponseV5(ctx, "POST", "/auth/login.json", data, nil)
|
||||
if err != nil && !strings.Contains(err.Error(), "Error API JSON Response Status: Message: The authentication failed.") {
|
||||
return fmt.Errorf("Doing Stage 1 Request: %w", err)
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func (c *Client) Login(ctx context.Context) error {
|
|||
|
||||
data.Auth.Token = string(authToken)
|
||||
|
||||
res, _, err = c.DoCustomRequestAndReturnRawResponse(ctx, "POST", "/auth/login.json", "v2", data, nil)
|
||||
res, _, err = c.DoCustomRequestAndReturnRawResponseV5(ctx, "POST", "/auth/login.json", data, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Doing Stage 2 Request: %w", err)
|
||||
}
|
||||
|
@ -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.DoCustomRequest(ctx, "GET", "/users/me.json", "v2", nil, nil)
|
||||
apiMsg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "GET", "/auth/logout.json", "v2", nil, nil)
|
||||
_, err := c.DoCustomRequestV5(ctx, "GET", "/auth/logout.json", nil, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Doing Logout Request: %w", err)
|
||||
}
|
||||
|
|
|
@ -183,6 +183,17 @@ func generateURL(base url.URL, p, version string, opt interface{}) (string, erro
|
|||
return base.String(), nil
|
||||
}
|
||||
|
||||
func generateBaseURL(base url.URL, p 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)
|
||||
}
|
||||
base.RawQuery = vs.Encode()
|
||||
|
||||
return base.String(), nil
|
||||
}
|
||||
|
||||
// GetUserID Gets the ID of the Current User
|
||||
func (c *Client) GetUserID() string {
|
||||
return c.userID
|
||||
|
@ -190,7 +201,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.DoCustomRequest(ctx, "GET", "/auth/verify.json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(ctx, "GET", "/auth/verify.json", nil, nil)
|
||||
if err != nil {
|
||||
return "", "", fmt.Errorf("Doing Request: %w", err)
|
||||
}
|
||||
|
|
|
@ -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.DoCustomRequest(ctx, "GET", "/comments/resource/"+resourceID+".json", "v2", nil, opts)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "POST", "/comments/resource/"+resourceID+".json", "v2", comment, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "PUT", "/comments/"+commentID+".json", "v2", comment, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "DELETE", "/comments/"+commentID+".json", "v2", nil, nil)
|
||||
_, err = c.DoCustomRequestV5(ctx, "DELETE", "/comments/"+commentID+".json", nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -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.DoCustomRequest(ctx, "POST", "/favorites/resource/"+resourceID+".json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "DELETE", "/favorites/"+favoriteID+".json", "v2", nil, nil)
|
||||
_, err = c.DoCustomRequestV5(ctx, "DELETE", "/favorites/"+favoriteID+".json", nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -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.DoCustomRequest(ctx, "GET", "/folders.json", "v2", nil, opts)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "POST", "/folders.json", "v2", folder, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "GET", "/folders/"+folderID+".json", "v2", nil, opts)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "PUT", "/folders/"+folderID+".json", "v2", folder, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "DELETE", "/folders/"+folderID+".json", "v2", nil, nil)
|
||||
_, err = c.DoCustomRequestV5(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.DoCustomRequest(ctx, "PUT", "/move/folder/"+folderID+".json", "v2", Folder{
|
||||
_, err = c.DoCustomRequestV5(ctx, "PUT", "/move/folder/"+folderID+".json", Folder{
|
||||
FolderParentID: folderParentID,
|
||||
}, nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -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.DoCustomRequest(ctx, "GET", "/gpgkeys.json", "v2", nil, opts)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "GET", "/gpgkeys/"+gpgkeyID+".json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(ctx, "GET", "/gpgkeys/"+gpgkeyID+".json", nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
//Group is a Group
|
||||
// Group is a Group
|
||||
type Group struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
|
@ -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.DoCustomRequest(ctx, "GET", "/groups.json", "v2", nil, opts)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "POST", "/groups.json", "v2", group, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "GET", "/groups/"+groupID+".json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "PUT", "/groups/"+groupID+".json", "v2", update, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "PUT", "/groups/"+groupID+"/dry-run.json", "v2", update, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "DELETE", "/groups/"+groupID+".json", "v2", nil, nil)
|
||||
_, err = c.DoCustomRequestV5(ctx, "DELETE", "/groups/"+groupID+".json", nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
// PerformHealthCheck performs a Health Check
|
||||
func (c *Client) PerformHealthCheck(ctx context.Context) (json.RawMessage, error) {
|
||||
msg, err := c.DoCustomRequest(ctx, "GET", "/healthcheck.json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "GET", "/healthcheck/status.json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(ctx, "GET", "/healthcheck/status.json", nil, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -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.DoCustomRequest(ctx, "GET", "/permissions/resource/"+resourceID+".json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(ctx, "GET", "/permissions/resource/"+resourceID+".json", nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -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.DoCustomRequest(ctx, "GET", "/resource-types.json", "v2", nil, opts)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "GET", "/resource-types/"+typeID+".json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(ctx, "GET", "/resource-types/"+typeID+".json", nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -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.DoCustomRequest(ctx, "GET", "/resources.json", "v2", nil, opts)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "POST", "/resources.json", "v2", resource, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "GET", "/resources/"+resourceID+".json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "PUT", "/resources/"+resourceID+".json", "v2", resource, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "DELETE", "/resources/"+resourceID+".json", "v2", nil, nil)
|
||||
_, err = c.DoCustomRequestV5(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.DoCustomRequest(ctx, "PUT", "/move/resource/"+resourceID+".json", "v2", Resource{
|
||||
_, err = c.DoCustomRequestV5(ctx, "PUT", "/move/resource/"+resourceID+".json", Resource{
|
||||
FolderParentID: folderParentID,
|
||||
}, nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
)
|
||||
|
||||
//Role is a Role
|
||||
// Role is a Role
|
||||
type Role struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
|
@ -41,7 +41,7 @@ type URL struct {
|
|||
|
||||
// GetRoles gets all Passbolt Roles
|
||||
func (c *Client) GetRoles(ctx context.Context) ([]Role, error) {
|
||||
msg, err := c.DoCustomRequest(ctx, "GET", "/roles.json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(ctx, "GET", "/roles.json", nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -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.DoCustomRequest(ctx, "GET", "/secrets/resource/"+resourceID+".json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(ctx, "GET", "/secrets/resource/"+resourceID+".json", nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -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.DoCustomRequest(ctx, "GET", "/setup/install/"+userID+"/"+token+".json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "POST", "/setup/complete/"+userID+".json", "v2", request, nil)
|
||||
_, err = c.DoCustomRequestV5(ctx, "POST", "/setup/complete/"+userID+".json", request, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -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.DoCustomRequest(ctx, "GET", "/share/search-aros.json", "v2", nil, opts)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "PUT", "/share/resource/"+resourceID+".json", "v2", shareRequest, nil)
|
||||
_, err = c.DoCustomRequestV5(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.DoCustomRequest(ctx, "PUT", "/share/folder/"+folderID+".json", "v2", f, nil)
|
||||
_, err = c.DoCustomRequestV5(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.DoCustomRequest(ctx, "POST", "/share/simulate/resource/"+resourceID+".json", "v2", shareRequest, nil)
|
||||
msg, err := c.DoCustomRequestV5(ctx, "POST", "/share/simulate/resource/"+resourceID+".json", shareRequest, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
12
api/users.go
12
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.DoCustomRequest(ctx, "GET", "/users.json", "v2", nil, opts)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "POST", "/users.json", "v2", user, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "GET", "/users/"+userID+".json", "v2", nil, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "PUT", "/users/"+userID+".json", "v2", user, nil)
|
||||
msg, err := c.DoCustomRequestV5(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.DoCustomRequest(ctx, "DELETE", "/users/"+userID+".json", "v2", nil, nil)
|
||||
_, err = c.DoCustomRequestV5(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.DoCustomRequest(ctx, "DELETE", "/users/"+userID+"/dry-run.json", "v2", nil, nil)
|
||||
_, err = c.DoCustomRequestV5(ctx, "DELETE", "/users/"+userID+"/dry-run.json", nil, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ func (c *Client) VerifyServer(ctx context.Context, token, encToken string) error
|
|||
KeyID: privateKeyObj.GetFingerprint(),
|
||||
},
|
||||
}
|
||||
raw, _, err := c.DoCustomRequestAndReturnRawResponse(ctx, "POST", "/auth/verify.json", "v2", data, nil)
|
||||
raw, _, err := c.DoCustomRequestAndReturnRawResponseV5(ctx, "POST", "/auth/verify.json", data, nil)
|
||||
if err != nil && !strings.Contains(err.Error(), "The authentication failed.") {
|
||||
return fmt.Errorf("Sending Verification Challenge: %w", err)
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func AddMFACallbackTOTP(c *api.Client, retrys uint, retryDelay, offset time.Dura
|
|||
TOTP: code,
|
||||
}
|
||||
var raw *http.Response
|
||||
raw, _, err = c.DoCustomRequestAndReturnRawResponse(ctx, "POST", "mfa/verify/totp.json", "v2", req, nil)
|
||||
raw, _, err = c.DoCustomRequestAndReturnRawResponseV5(ctx, "POST", "mfa/verify/totp.json", req, nil)
|
||||
if err != nil {
|
||||
if errors.Unwrap(err) != api.ErrAPIResponseErrorStatusCode {
|
||||
return http.Cookie{}, fmt.Errorf("Doing MFA Challenge Response: %w", err)
|
||||
|
|
Loading…
Add table
Reference in a new issue