2018-11-20 13:54:02 +02:00
|
|
|
package jira
|
|
|
|
|
2020-05-03 15:38:32 +02:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
)
|
2018-11-20 13:54:02 +02:00
|
|
|
|
2020-05-14 17:18:31 +02:00
|
|
|
// PermissionSchemeService handles permissionschemes for the Jira instance / API.
|
2018-11-20 13:54:02 +02:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-group-Permissionscheme
|
2018-11-20 13:54:02 +02:00
|
|
|
type PermissionSchemeService struct {
|
|
|
|
client *Client
|
|
|
|
}
|
|
|
|
type PermissionSchemes struct {
|
|
|
|
PermissionSchemes []PermissionScheme `json:"permissionSchemes" structs:"permissionSchemes"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Permission struct {
|
|
|
|
ID int `json:"id" structs:"id"`
|
|
|
|
Self string `json:"expand" structs:"expand"`
|
|
|
|
Holder Holder `json:"holder" structs:"holder"`
|
|
|
|
Name string `json:"permission" structs:"permission"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Holder struct {
|
|
|
|
Type string `json:"type" structs:"type"`
|
|
|
|
Parameter string `json:"parameter" structs:"parameter"`
|
|
|
|
Expand string `json:"expand" structs:"expand"`
|
|
|
|
}
|
|
|
|
|
2020-05-03 15:38:32 +02:00
|
|
|
// GetListWithContext returns a list of all permission schemes
|
2018-11-20 15:34:04 +02:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-permissionscheme-get
|
2020-05-03 15:38:32 +02:00
|
|
|
func (s *PermissionSchemeService) GetListWithContext(ctx context.Context) (*PermissionSchemes, *Response, error) {
|
2018-11-20 13:54:02 +02:00
|
|
|
apiEndpoint := "/rest/api/3/permissionscheme"
|
2020-05-03 15:38:32 +02:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
2018-11-20 13:54:02 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
pss := new(PermissionSchemes)
|
|
|
|
resp, err := s.client.Do(req, &pss)
|
|
|
|
if err != nil {
|
|
|
|
jerr := NewJiraError(resp, err)
|
|
|
|
return nil, resp, jerr
|
|
|
|
}
|
|
|
|
|
|
|
|
return pss, resp, nil
|
|
|
|
}
|
|
|
|
|
2020-05-03 15:38:32 +02:00
|
|
|
// GetList wraps GetListWithContext using the background context.
|
|
|
|
func (s *PermissionSchemeService) GetList() (*PermissionSchemes, *Response, error) {
|
|
|
|
return s.GetListWithContext(context.Background())
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetWithContext returns a full representation of the permission scheme for the schemeID
|
2018-11-20 15:34:04 +02:00
|
|
|
//
|
2020-05-14 17:18:31 +02:00
|
|
|
// Jira API docs: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-api-3-permissionscheme-schemeId-get
|
2020-05-03 15:38:32 +02:00
|
|
|
func (s *PermissionSchemeService) GetWithContext(ctx context.Context, schemeID int) (*PermissionScheme, *Response, error) {
|
2018-11-20 13:54:02 +02:00
|
|
|
apiEndpoint := fmt.Sprintf("/rest/api/3/permissionscheme/%d", schemeID)
|
2020-05-03 15:38:32 +02:00
|
|
|
req, err := s.client.NewRequestWithContext(ctx, "GET", apiEndpoint, nil)
|
2018-11-20 13:54:02 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ps := new(PermissionScheme)
|
|
|
|
resp, err := s.client.Do(req, ps)
|
|
|
|
if err != nil {
|
|
|
|
jerr := NewJiraError(resp, err)
|
|
|
|
return nil, resp, jerr
|
|
|
|
}
|
2019-05-09 13:11:55 +02:00
|
|
|
if ps.Self == "" {
|
style: Fix staticcheck (static analysis) errors for this library (#283)
* style: Fix staticcheck errors for "error strings should not be capitalized (ST1005)"
staticcheck is a static analysis tool for go.
It reports several "error strings should not be capitalized (ST1005)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "printf-style function with dynamic format ... (SA1006)"
staticcheck is a static analysis tool for go.
It reports several "printf-style function with dynamic format string and no further arguments should use print-style function instead (SA1006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "type X is unused (U1000)"
staticcheck is a static analysis tool for go.
It reports several "type X is unused (U1000)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "should use X instead (S1003 & SA6005)"
staticcheck is a static analysis tool for go.
It reports several
- should use !bytes.Contains(b, []byte(`"password":"bar"`)) instead (S1003)
- should use strings.EqualFold instead (SA6005)
messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "unnecessary use of fmt.Sprintf (S1039)"
staticcheck is a static analysis tool for go.
It report several "unnecessary use of fmt.Sprintf (S1039)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "this value of X is never used (SA4006)"
staticcheck is a static analysis tool for go.
It report several "this value of X is never used (SA4006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "redundant return statement (S1023)"
staticcheck is a static analysis tool for go.
It report several "redundant return statement (S1023)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "possible nil pointer dereference (SA5011)"
staticcheck is a static analysis tool for go.
It report several
file.go:Line:character: possible nil pointer dereference (SA5011)
file.go:Line:character: this check suggests that the pointer can be nil
messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
* style: Fix staticcheck errors for "this value of X is never used (SA4006)"
staticcheck is a static analysis tool for go.
It report several "this value of X is never used (SA4006)" messages.
Here, we fix it to be more compliant with the go coding styleguide.
Related: #280
2020-05-02 23:08:01 +02:00
|
|
|
return nil, resp, fmt.Errorf("no permissionscheme with ID %d found", schemeID)
|
2019-05-09 13:11:55 +02:00
|
|
|
}
|
2018-11-20 13:54:02 +02:00
|
|
|
|
|
|
|
return ps, resp, nil
|
|
|
|
}
|
2020-05-03 15:38:32 +02:00
|
|
|
|
|
|
|
// Get wraps GetWithContext using the background context.
|
|
|
|
func (s *PermissionSchemeService) Get(schemeID int) (*PermissionScheme, *Response, error) {
|
|
|
|
return s.GetWithContext(context.Background(), schemeID)
|
|
|
|
}
|