mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-10 01:48:22 +00:00
wip 1
This commit is contained in:
parent
437e062894
commit
4e212e53b6
17 changed files with 54 additions and 126 deletions
66
api/api.go
66
api/api.go
|
@ -25,79 +25,21 @@ type APIHeader struct {
|
||||||
Code int `json:"code"`
|
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) {
|
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)
|
_, response, err := c.DoCustomRequestAndReturnRawResponse(ctx, method, path, version, body, opts)
|
||||||
return response, err
|
return response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DoCustomRequestV5 executes a custom request and returns an APIResponse
|
// DoCustomRequestAndReturnRawResponse executes a custom request and returns an APIResponse and the Raw HTTP Response.
|
||||||
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) {
|
func (c *Client) DoCustomRequestAndReturnRawResponse(ctx context.Context, method, path, version string, body interface{}, opts interface{}) (*http.Response, *APIResponse, error) {
|
||||||
firstTime := true
|
return c.DoCustomRequestAndReturnRawResponseV5(ctx, method, path, body, opts)
|
||||||
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))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
func (c *Client) DoCustomRequestAndReturnRawResponseV5(ctx context.Context, method, path string, body interface{}, opts interface{}) (*http.Response, *APIResponse, error) {
|
||||||
firstTime := true
|
firstTime := true
|
||||||
start:
|
start:
|
||||||
u, err := generateBaseURL(*c.baseURL, path, opts)
|
u, err := generateURL(*c.baseURL, path, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("Generating Path: %w", err)
|
return nil, nil, fmt.Errorf("Generating Path: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ type GPGAuth struct {
|
||||||
|
|
||||||
// CheckSession Check to see if you have a Valid Session
|
// CheckSession Check to see if you have a Valid Session
|
||||||
func (c *Client) CheckSession(ctx context.Context) bool {
|
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
|
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
|
// 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 {
|
if err != nil {
|
||||||
return fmt.Errorf("Getting CSRF Token: %w", err)
|
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
|
// Logout closes the current Session on the Passbolt server
|
||||||
func (c *Client) Logout(ctx context.Context) error {
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("Doing Logout Request: %w", err)
|
return fmt.Errorf("Doing Logout Request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,21 +169,7 @@ func (c *Client) log(msg string, args ...interface{}) {
|
||||||
fmt.Printf("[go-passbolt] "+msg+"\n", args...)
|
fmt.Printf("[go-passbolt] "+msg+"\n", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateURL(base url.URL, p, version 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 {
|
|
||||||
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) {
|
|
||||||
base.Path = path.Join(base.Path, p)
|
base.Path = path.Join(base.Path, p)
|
||||||
vs, err := query.Values(opt)
|
vs, err := query.Values(opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -201,7 +187,7 @@ func (c *Client) GetUserID() string {
|
||||||
|
|
||||||
// GetPublicKey gets the Public Key and Fingerprint of the Passbolt instance
|
// GetPublicKey gets the Public Key and Fingerprint of the Passbolt instance
|
||||||
func (c *Client) GetPublicKey(ctx context.Context) (string, string, error) {
|
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 {
|
if err != nil {
|
||||||
return "", "", fmt.Errorf("Doing Request: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ func (c *Client) CreateComment(ctx context.Context, resourceID string, comment C
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ func (c *Client) UpdateComment(ctx context.Context, commentID string, comment Co
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ func (c *Client) DeleteComment(ctx context.Context, commentID string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ func (c *Client) CreateFavorite(ctx context.Context, resourceID string) (*Favori
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ func (c *Client) DeleteFavorite(ctx context.Context, favoriteID string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ type GetFolderOptions struct {
|
||||||
|
|
||||||
// GetFolders gets all Folders from the Passboltserver
|
// GetFolders gets all Folders from the Passboltserver
|
||||||
func (c *Client) GetFolders(ctx context.Context, opts *GetFoldersOptions) ([]Folder, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func (c *Client) GetFolders(ctx context.Context, opts *GetFoldersOptions) ([]Fol
|
||||||
|
|
||||||
// CreateFolder Creates a new Passbolt Folder
|
// CreateFolder Creates a new Passbolt Folder
|
||||||
func (c *Client) CreateFolder(ctx context.Context, folder Folder) (*Folder, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ func (c *Client) GetFolder(ctx context.Context, folderID string, opts *GetFolder
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ func (c *Client) UpdateFolder(ctx context.Context, folderID string, folder Folde
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ func (c *Client) DeleteFolder(ctx context.Context, folderID string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ func (c *Client) MoveFolder(ctx context.Context, folderID, folderParentID string
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
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,
|
FolderParentID: folderParentID,
|
||||||
}, nil)
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -29,7 +29,7 @@ type GetGPGKeysOptions struct {
|
||||||
|
|
||||||
// GetGPGKeys gets all Passbolt GPGKeys
|
// GetGPGKeys gets all Passbolt GPGKeys
|
||||||
func (c *Client) GetGPGKeys(ctx context.Context, opts *GetGPGKeysOptions) ([]GPGKey, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func (c *Client) GetGPGKey(ctx context.Context, gpgkeyID string) (*GPGKey, error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ type UpdateGroupDryRunSecretsNeeded struct {
|
||||||
|
|
||||||
// GetGroups gets all Passbolt Groups
|
// GetGroups gets all Passbolt Groups
|
||||||
func (c *Client) GetGroups(ctx context.Context, opts *GetGroupsOptions) ([]Group, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ func (c *Client) GetGroups(ctx context.Context, opts *GetGroupsOptions) ([]Group
|
||||||
|
|
||||||
// CreateGroup Creates a new Passbolt Group
|
// CreateGroup Creates a new Passbolt Group
|
||||||
func (c *Client) CreateGroup(ctx context.Context, group Group) (*Group, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ func (c *Client) GetGroup(ctx context.Context, groupID string) (*Group, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ func (c *Client) UpdateGroup(ctx context.Context, groupID string, update GroupUp
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ func (c *Client) UpdateGroupDryRun(ctx context.Context, groupID string, update G
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ func (c *Client) DeleteGroup(ctx context.Context, groupID string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
// PerformHealthCheck performs a Health Check
|
// PerformHealthCheck performs a Health Check
|
||||||
func (c *Client) PerformHealthCheck(ctx context.Context) (json.RawMessage, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func (c *Client) PerformHealthCheck(ctx context.Context) (json.RawMessage, error
|
||||||
|
|
||||||
// GetHealthCheckStatus gets the Server Status
|
// GetHealthCheckStatus gets the Server Status
|
||||||
func (c *Client) GetHealthCheckStatus(ctx context.Context) (string, error) {
|
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 {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ func (c *Client) GetResourcePermissions(ctx context.Context, resourceID string)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ type GetResourceTypesOptions struct {
|
||||||
|
|
||||||
// GetResourceTypes gets all Passbolt Resource Types
|
// GetResourceTypes gets all Passbolt Resource Types
|
||||||
func (c *Client) GetResourceTypes(ctx context.Context, opts *GetResourceTypesOptions) ([]ResourceType, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func (c *Client) GetResourceType(ctx context.Context, typeID string) (*ResourceT
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ type GetResourcesOptions struct {
|
||||||
|
|
||||||
// GetResources gets all Passbolt Resources
|
// GetResources gets all Passbolt Resources
|
||||||
func (c *Client) GetResources(ctx context.Context, opts *GetResourcesOptions) ([]Resource, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ func (c *Client) GetResources(ctx context.Context, opts *GetResourcesOptions) ([
|
||||||
|
|
||||||
// CreateResource Creates a new Passbolt Resource
|
// CreateResource Creates a new Passbolt Resource
|
||||||
func (c *Client) CreateResource(ctx context.Context, resource Resource) (*Resource, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ func (c *Client) GetResource(ctx context.Context, resourceID string) (*Resource,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ func (c *Client) UpdateResource(ctx context.Context, resourceID string, resource
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ func (c *Client) DeleteResource(ctx context.Context, resourceID string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ func (c *Client) MoveResource(ctx context.Context, resourceID, folderParentID st
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
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,
|
FolderParentID: folderParentID,
|
||||||
}, nil)
|
}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -41,7 +41,7 @@ type URL struct {
|
||||||
|
|
||||||
// GetRoles gets all Passbolt Roles
|
// GetRoles gets all Passbolt Roles
|
||||||
func (c *Client) GetRoles(ctx context.Context) ([]Role, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (c *Client) GetSecret(ctx context.Context, resourceID string) (*Secret, err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (c *Client) SetupInstall(ctx context.Context, userID, token string) (*Setup
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking Token format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ func (c *Client) SetupComplete(ctx context.Context, userID string, request Setup
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ type SearchAROsOptions struct {
|
||||||
// SearchAROs gets all Passbolt AROs
|
// SearchAROs gets all Passbolt AROs
|
||||||
func (c *Client) SearchAROs(ctx context.Context, opts SearchAROsOptions) ([]ARO, error) {
|
func (c *Client) SearchAROs(ctx context.Context, opts SearchAROsOptions) ([]ARO, error) {
|
||||||
//set is_new to true in permission
|
//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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func (c *Client) ShareResource(ctx context.Context, resourceID string, shareRequ
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ func (c *Client) ShareFolder(ctx context.Context, folderID string, permissions [
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
return fmt.Errorf("Checking ID format: %w", err)
|
||||||
}
|
}
|
||||||
f := Folder{Permissions: permissions}
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ func (c *Client) SimulateShareResource(ctx context.Context, resourceID string, s
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
12
api/users.go
12
api/users.go
|
@ -48,7 +48,7 @@ type GetUsersOptions struct {
|
||||||
|
|
||||||
// GetUsers gets all Passbolt Users
|
// GetUsers gets all Passbolt Users
|
||||||
func (c *Client) GetUsers(ctx context.Context, opts *GetUsersOptions) ([]User, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func (c *Client) GetUsers(ctx context.Context, opts *GetUsersOptions) ([]User, e
|
||||||
|
|
||||||
// CreateUser Creates a new Passbolt User
|
// CreateUser Creates a new Passbolt User
|
||||||
func (c *Client) CreateUser(ctx context.Context, user User) (*User, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ func (c *Client) GetUser(ctx context.Context, userID string) (*User, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ func (c *Client) UpdateUser(ctx context.Context, userID string, user User) (*Use
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ func (c *Client) DeleteUser(ctx context.Context, userID string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ func (c *Client) DeleteUserDryrun(ctx context.Context, userID string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Checking ID format: %w", err)
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue