2019-02-21 15:08:30 +00:00
|
|
|
// Copyright 2019 Sorint.lab
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
package client
|
2019-02-21 15:08:30 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2022-02-22 14:01:29 +00:00
|
|
|
"agola.io/agola/internal/errors"
|
2022-02-21 11:19:55 +00:00
|
|
|
"agola.io/agola/internal/util"
|
2019-07-31 13:39:07 +00:00
|
|
|
csapitypes "agola.io/agola/services/configstore/api/types"
|
|
|
|
cstypes "agola.io/agola/services/configstore/types"
|
2019-02-21 15:08:30 +00:00
|
|
|
)
|
|
|
|
|
2019-04-08 10:28:15 +00:00
|
|
|
var jsonContent = http.Header{"Content-Type": []string{"application/json"}}
|
2019-02-21 15:08:30 +00:00
|
|
|
|
|
|
|
type Client struct {
|
|
|
|
url string
|
|
|
|
client *http.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewClient initializes and returns a API client.
|
|
|
|
func NewClient(url string) *Client {
|
|
|
|
return &Client{
|
|
|
|
url: strings.TrimSuffix(url, "/"),
|
|
|
|
client: &http.Client{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetHTTPClient replaces default http.Client with user given one.
|
|
|
|
func (c *Client) SetHTTPClient(client *http.Client) {
|
|
|
|
c.client = client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) doRequest(ctx context.Context, method, path string, query url.Values, header http.Header, ibody io.Reader) (*http.Response, error) {
|
|
|
|
u, err := url.Parse(c.url + "/api/v1alpha" + path)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
u.RawQuery = query.Encode()
|
|
|
|
|
|
|
|
req, err := http.NewRequest(method, u.String(), ibody)
|
|
|
|
req = req.WithContext(ctx)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
for k, v := range header {
|
|
|
|
req.Header[k] = v
|
|
|
|
}
|
|
|
|
|
2022-02-22 14:01:29 +00:00
|
|
|
res, err := c.client.Do(req)
|
|
|
|
|
|
|
|
return res, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) getResponse(ctx context.Context, method, path string, query url.Values, header http.Header, ibody io.Reader) (*http.Response, error) {
|
|
|
|
resp, err := c.doRequest(ctx, method, path, query, header, ibody)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
if err := util.ErrFromRemote(resp); err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) getParsedResponse(ctx context.Context, method, path string, query url.Values, header http.Header, ibody io.Reader, obj interface{}) (*http.Response, error) {
|
|
|
|
resp, err := c.getResponse(ctx, method, path, query, header, ibody)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
d := json.NewDecoder(resp.Body)
|
|
|
|
|
2022-02-22 14:01:29 +00:00
|
|
|
return resp, errors.WithStack(d.Decode(obj))
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProjectGroup(ctx context.Context, projectGroupRef string) (*csapitypes.ProjectGroup, *http.Response, error) {
|
|
|
|
projectGroup := new(csapitypes.ProjectGroup)
|
2019-04-02 09:07:39 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s", url.PathEscape(projectGroupRef)), nil, jsonContent, nil, projectGroup)
|
2022-02-22 14:01:29 +00:00
|
|
|
return projectGroup, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProjectGroupSubgroups(ctx context.Context, projectGroupRef string) ([]*csapitypes.ProjectGroup, *http.Response, error) {
|
|
|
|
projectGroups := []*csapitypes.ProjectGroup{}
|
2019-04-02 09:07:39 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/subgroups", url.PathEscape(projectGroupRef)), nil, jsonContent, nil, &projectGroups)
|
2022-02-22 14:01:29 +00:00
|
|
|
return projectGroups, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProjectGroupProjects(ctx context.Context, projectGroupRef string) ([]*csapitypes.Project, *http.Response, error) {
|
|
|
|
projects := []*csapitypes.Project{}
|
2019-04-02 09:07:39 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/projects", url.PathEscape(projectGroupRef)), nil, jsonContent, nil, &projects)
|
2022-02-22 14:01:29 +00:00
|
|
|
return projects, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateProjectGroup(ctx context.Context, projectGroup *cstypes.ProjectGroup) (*csapitypes.ProjectGroup, *http.Response, error) {
|
2019-03-14 13:36:18 +00:00
|
|
|
pj, err := json.Marshal(projectGroup)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resProjectGroup := new(csapitypes.ProjectGroup)
|
2019-04-30 15:09:26 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", "/projectgroups", nil, jsonContent, bytes.NewReader(pj), resProjectGroup)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resProjectGroup, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateProjectGroup(ctx context.Context, projectGroupRef string, projectGroup *cstypes.ProjectGroup) (*csapitypes.ProjectGroup, *http.Response, error) {
|
2019-05-14 15:53:48 +00:00
|
|
|
pj, err := json.Marshal(projectGroup)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-05-14 15:53:48 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resProjectGroup := new(csapitypes.ProjectGroup)
|
2019-05-14 15:53:48 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/projectgroups/%s", url.PathEscape(projectGroupRef)), nil, jsonContent, bytes.NewReader(pj), resProjectGroup)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resProjectGroup, resp, errors.WithStack(err)
|
2019-05-14 15:53:48 +00:00
|
|
|
}
|
|
|
|
|
2019-05-12 22:23:57 +00:00
|
|
|
func (c *Client) DeleteProjectGroup(ctx context.Context, projectGroupRef string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projectgroups/%s", url.PathEscape(projectGroupRef)), nil, jsonContent, nil)
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProject(ctx context.Context, projectRef string) (*csapitypes.Project, *http.Response, error) {
|
|
|
|
project := new(csapitypes.Project)
|
2019-04-02 09:07:39 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projects/%s", url.PathEscape(projectRef)), nil, jsonContent, nil, project)
|
2022-02-22 14:01:29 +00:00
|
|
|
return project, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateProject(ctx context.Context, project *cstypes.Project) (*csapitypes.Project, *http.Response, error) {
|
2019-02-21 15:08:30 +00:00
|
|
|
pj, err := json.Marshal(project)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resProject := new(csapitypes.Project)
|
2019-04-30 15:09:26 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", "/projects", nil, jsonContent, bytes.NewReader(pj), resProject)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resProject, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateProject(ctx context.Context, projectRef string, project *cstypes.Project) (*csapitypes.Project, *http.Response, error) {
|
2019-05-09 13:33:57 +00:00
|
|
|
pj, err := json.Marshal(project)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-05-09 13:33:57 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resProject := new(csapitypes.Project)
|
2019-05-09 13:33:57 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/projects/%s", url.PathEscape(projectRef)), nil, jsonContent, bytes.NewReader(pj), resProject)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resProject, resp, errors.WithStack(err)
|
2019-05-09 13:33:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 09:07:39 +00:00
|
|
|
func (c *Client) DeleteProject(ctx context.Context, projectRef string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projects/%s", url.PathEscape(projectRef)), nil, jsonContent, nil)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProjectGroupSecrets(ctx context.Context, projectGroupRef string, tree bool) ([]*csapitypes.Secret, *http.Response, error) {
|
2019-03-14 13:36:18 +00:00
|
|
|
q := url.Values{}
|
|
|
|
if tree {
|
|
|
|
q.Add("tree", "")
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
secrets := []*csapitypes.Secret{}
|
2019-03-14 13:36:18 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/secrets", url.PathEscape(projectGroupRef)), q, jsonContent, nil, &secrets)
|
2022-02-22 14:01:29 +00:00
|
|
|
return secrets, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProjectSecrets(ctx context.Context, projectRef string, tree bool) ([]*csapitypes.Secret, *http.Response, error) {
|
2019-03-14 13:36:18 +00:00
|
|
|
q := url.Values{}
|
|
|
|
if tree {
|
|
|
|
q.Add("tree", "")
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
secrets := []*csapitypes.Secret{}
|
2019-03-14 13:36:18 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projects/%s/secrets", url.PathEscape(projectRef)), q, jsonContent, nil, &secrets)
|
2022-02-22 14:01:29 +00:00
|
|
|
return secrets, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateProjectGroupSecret(ctx context.Context, projectGroupRef string, secret *cstypes.Secret) (*csapitypes.Secret, *http.Response, error) {
|
2019-03-14 13:36:18 +00:00
|
|
|
pj, err := json.Marshal(secret)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resSecret := new(csapitypes.Secret)
|
2019-04-30 14:28:01 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projectgroups/%s/secrets", url.PathEscape(projectGroupRef)), nil, jsonContent, bytes.NewReader(pj), resSecret)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resSecret, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateProjectSecret(ctx context.Context, projectRef string, secret *cstypes.Secret) (*csapitypes.Secret, *http.Response, error) {
|
2019-03-14 13:36:18 +00:00
|
|
|
pj, err := json.Marshal(secret)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resSecret := new(csapitypes.Secret)
|
2019-04-30 14:28:01 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projects/%s/secrets", url.PathEscape(projectRef)), nil, jsonContent, bytes.NewReader(pj), resSecret)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resSecret, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateProjectGroupSecret(ctx context.Context, projectGroupRef, secretName string, secret *cstypes.Secret) (*csapitypes.Secret, *http.Response, error) {
|
2019-07-08 08:32:32 +00:00
|
|
|
pj, err := json.Marshal(secret)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-07-08 08:32:32 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resSecret := new(csapitypes.Secret)
|
2019-07-08 08:32:32 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/projectgroups/%s/secrets/%s", url.PathEscape(projectGroupRef), secretName), nil, jsonContent, bytes.NewReader(pj), resSecret)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resSecret, resp, errors.WithStack(err)
|
2019-07-08 08:32:32 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateProjectSecret(ctx context.Context, projectRef, secretName string, secret *cstypes.Secret) (*csapitypes.Secret, *http.Response, error) {
|
2019-07-08 08:32:32 +00:00
|
|
|
pj, err := json.Marshal(secret)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-07-08 08:32:32 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resSecret := new(csapitypes.Secret)
|
2019-07-08 08:32:32 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/projects/%s/secrets/%s", url.PathEscape(projectRef), secretName), nil, jsonContent, bytes.NewReader(pj), resSecret)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resSecret, resp, errors.WithStack(err)
|
2019-07-08 08:32:32 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 13:36:18 +00:00
|
|
|
func (c *Client) DeleteProjectGroupSecret(ctx context.Context, projectGroupRef, secretName string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projectgroups/%s/secrets/%s", url.PathEscape(projectGroupRef), secretName), nil, jsonContent, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) DeleteProjectSecret(ctx context.Context, projectRef, secretName string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projects/%s/secrets/%s", url.PathEscape(projectRef), secretName), nil, jsonContent, nil)
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProjectGroupVariables(ctx context.Context, projectGroupRef string, tree bool) ([]*csapitypes.Variable, *http.Response, error) {
|
2019-03-14 13:36:18 +00:00
|
|
|
q := url.Values{}
|
|
|
|
if tree {
|
|
|
|
q.Add("tree", "")
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
variables := []*csapitypes.Variable{}
|
2019-03-14 13:36:18 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/variables", url.PathEscape(projectGroupRef)), q, jsonContent, nil, &variables)
|
2022-02-22 14:01:29 +00:00
|
|
|
return variables, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProjectVariables(ctx context.Context, projectRef string, tree bool) ([]*csapitypes.Variable, *http.Response, error) {
|
2019-03-14 13:36:18 +00:00
|
|
|
q := url.Values{}
|
|
|
|
if tree {
|
|
|
|
q.Add("tree", "")
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
variables := []*csapitypes.Variable{}
|
2019-03-14 13:36:18 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projects/%s/variables", url.PathEscape(projectRef)), q, jsonContent, nil, &variables)
|
2022-02-22 14:01:29 +00:00
|
|
|
return variables, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateProjectGroupVariable(ctx context.Context, projectGroupRef string, variable *cstypes.Variable) (*csapitypes.Variable, *http.Response, error) {
|
2019-03-14 13:36:18 +00:00
|
|
|
pj, err := json.Marshal(variable)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resVariable := new(csapitypes.Variable)
|
2019-04-30 14:28:01 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projectgroups/%s/variables", url.PathEscape(projectGroupRef)), nil, jsonContent, bytes.NewReader(pj), resVariable)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resVariable, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateProjectGroupVariable(ctx context.Context, projectGroupRef, variableName string, variable *cstypes.Variable) (*csapitypes.Variable, *http.Response, error) {
|
2019-07-06 13:25:24 +00:00
|
|
|
pj, err := json.Marshal(variable)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-07-06 13:25:24 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resVariable := new(csapitypes.Variable)
|
2019-07-06 13:25:24 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/projectgroups/%s/variables/%s", url.PathEscape(projectGroupRef), variableName), nil, jsonContent, bytes.NewReader(pj), resVariable)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resVariable, resp, errors.WithStack(err)
|
2019-07-06 13:25:24 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateProjectVariable(ctx context.Context, projectRef string, variable *cstypes.Variable) (*csapitypes.Variable, *http.Response, error) {
|
2019-03-14 13:36:18 +00:00
|
|
|
pj, err := json.Marshal(variable)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resVariable := new(csapitypes.Variable)
|
2019-04-30 14:28:01 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/projects/%s/variables", url.PathEscape(projectRef)), nil, jsonContent, bytes.NewReader(pj), resVariable)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resVariable, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateProjectVariable(ctx context.Context, projectRef, variableName string, variable *cstypes.Variable) (*csapitypes.Variable, *http.Response, error) {
|
2019-07-06 13:25:24 +00:00
|
|
|
pj, err := json.Marshal(variable)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-07-06 13:25:24 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
resVariable := new(csapitypes.Variable)
|
2019-07-06 13:25:24 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/projects/%s/variables/%s", url.PathEscape(projectRef), variableName), nil, jsonContent, bytes.NewReader(pj), resVariable)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resVariable, resp, errors.WithStack(err)
|
2019-07-06 13:25:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 13:36:18 +00:00
|
|
|
func (c *Client) DeleteProjectGroupVariable(ctx context.Context, projectGroupRef, variableName string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projectgroups/%s/variables/%s", url.PathEscape(projectGroupRef), variableName), nil, jsonContent, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) DeleteProjectVariable(ctx context.Context, projectRef, variableName string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/projects/%s/variables/%s", url.PathEscape(projectRef), variableName), nil, jsonContent, nil)
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetUser(ctx context.Context, userRef string) (*cstypes.User, *http.Response, error) {
|
2022-02-21 11:19:55 +00:00
|
|
|
user := new(cstypes.User)
|
2019-05-03 09:07:53 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/users/%s", userRef), nil, jsonContent, nil, user)
|
2022-02-22 14:01:29 +00:00
|
|
|
return user, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetUserByToken(ctx context.Context, token string) (*cstypes.User, *http.Response, error) {
|
2019-02-21 15:08:30 +00:00
|
|
|
q := url.Values{}
|
|
|
|
q.Add("query_type", "bytoken")
|
|
|
|
q.Add("token", token)
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
users := []*cstypes.User{}
|
2019-02-21 15:08:30 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", "/users", q, jsonContent, nil, &users)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
2022-02-22 14:01:29 +00:00
|
|
|
return users[0], resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetUserByLinkedAccountRemoteUserAndSource(ctx context.Context, remoteUserID, remoteSourceID string) (*cstypes.User, *http.Response, error) {
|
2019-02-21 15:08:30 +00:00
|
|
|
q := url.Values{}
|
|
|
|
q.Add("query_type", "byremoteuser")
|
|
|
|
q.Add("remoteuserid", remoteUserID)
|
|
|
|
q.Add("remotesourceid", remoteSourceID)
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
users := []*cstypes.User{}
|
2019-02-21 15:08:30 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", "/users", q, jsonContent, nil, &users)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
2022-02-22 14:01:29 +00:00
|
|
|
return users[0], resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetUserByLinkedAccount(ctx context.Context, linkedAccountID string) (*cstypes.User, *http.Response, error) {
|
2019-02-21 15:08:30 +00:00
|
|
|
q := url.Values{}
|
|
|
|
q.Add("query_type", "bylinkedaccount")
|
|
|
|
q.Add("linkedaccountid", linkedAccountID)
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
users := []*cstypes.User{}
|
2019-02-21 15:08:30 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", "/users", q, jsonContent, nil, &users)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
2022-02-22 14:01:29 +00:00
|
|
|
return users[0], resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateUser(ctx context.Context, req *csapitypes.CreateUserRequest) (*cstypes.User, *http.Response, error) {
|
2019-03-29 16:50:51 +00:00
|
|
|
reqj, err := json.Marshal(req)
|
2019-02-21 15:08:30 +00:00
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
user := new(cstypes.User)
|
2019-04-08 06:54:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", "/users", nil, jsonContent, bytes.NewReader(reqj), user)
|
2022-02-22 14:01:29 +00:00
|
|
|
return user, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateUser(ctx context.Context, userRef string, req *csapitypes.UpdateUserRequest) (*cstypes.User, *http.Response, error) {
|
2019-05-03 07:53:38 +00:00
|
|
|
reqj, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-05-03 07:53:38 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
user := new(cstypes.User)
|
2019-05-03 09:07:53 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/users/%s", userRef), nil, jsonContent, bytes.NewReader(reqj), user)
|
2022-02-22 14:01:29 +00:00
|
|
|
return user, resp, errors.WithStack(err)
|
2019-05-03 07:53:38 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 09:07:53 +00:00
|
|
|
func (c *Client) DeleteUser(ctx context.Context, userRef string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s", userRef), nil, jsonContent, nil)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetUsers(ctx context.Context, start string, limit int, asc bool) ([]*cstypes.User, *http.Response, error) {
|
2019-02-21 15:08:30 +00:00
|
|
|
q := url.Values{}
|
|
|
|
if start != "" {
|
|
|
|
q.Add("start", start)
|
|
|
|
}
|
|
|
|
if limit > 0 {
|
|
|
|
q.Add("limit", strconv.Itoa(limit))
|
|
|
|
}
|
|
|
|
if asc {
|
|
|
|
q.Add("asc", "")
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
users := []*cstypes.User{}
|
2019-02-21 15:08:30 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", "/users", q, jsonContent, nil, &users)
|
2022-02-22 14:01:29 +00:00
|
|
|
return users, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateUserLA(ctx context.Context, userRef string, req *csapitypes.CreateUserLARequest) (*cstypes.LinkedAccount, *http.Response, error) {
|
2019-02-21 15:08:30 +00:00
|
|
|
reqj, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
la := new(cstypes.LinkedAccount)
|
2019-05-03 09:07:53 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/users/%s/linkedaccounts", userRef), nil, jsonContent, bytes.NewReader(reqj), la)
|
2022-02-22 14:01:29 +00:00
|
|
|
return la, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 09:07:53 +00:00
|
|
|
func (c *Client) DeleteUserLA(ctx context.Context, userRef, laID string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s/linkedaccounts/%s", userRef, laID), nil, jsonContent, nil)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateUserLA(ctx context.Context, userRef, laID string, req *csapitypes.UpdateUserLARequest) (*cstypes.LinkedAccount, *http.Response, error) {
|
2019-02-21 15:08:30 +00:00
|
|
|
reqj, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
la := new(cstypes.LinkedAccount)
|
2019-05-03 09:07:53 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/users/%s/linkedaccounts/%s", userRef, laID), nil, jsonContent, bytes.NewReader(reqj), la)
|
2022-02-22 14:01:29 +00:00
|
|
|
return la, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateUserToken(ctx context.Context, userRef string, req *csapitypes.CreateUserTokenRequest) (*csapitypes.CreateUserTokenResponse, *http.Response, error) {
|
2019-02-21 15:08:30 +00:00
|
|
|
reqj, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
tresp := new(csapitypes.CreateUserTokenResponse)
|
2019-05-03 09:07:53 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", fmt.Sprintf("/users/%s/tokens", userRef), nil, jsonContent, bytes.NewReader(reqj), tresp)
|
2022-02-22 14:01:29 +00:00
|
|
|
return tresp, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 09:07:53 +00:00
|
|
|
func (c *Client) DeleteUserToken(ctx context.Context, userRef, tokenName string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/users/%s/tokens/%s", userRef, tokenName), nil, jsonContent, nil)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetUserOrgs(ctx context.Context, userRef string) ([]*csapitypes.UserOrgsResponse, *http.Response, error) {
|
|
|
|
userOrgs := []*csapitypes.UserOrgsResponse{}
|
2019-05-03 15:40:07 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/users/%s/orgs", userRef), nil, jsonContent, nil, &userOrgs)
|
2022-02-22 14:01:29 +00:00
|
|
|
return userOrgs, resp, errors.WithStack(err)
|
2019-05-03 15:40:07 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetRemoteSource(ctx context.Context, rsRef string) (*cstypes.RemoteSource, *http.Response, error) {
|
2022-02-21 11:19:55 +00:00
|
|
|
rs := new(cstypes.RemoteSource)
|
2019-05-03 09:07:53 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/remotesources/%s", rsRef), nil, jsonContent, nil, rs)
|
2022-02-22 14:01:29 +00:00
|
|
|
return rs, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetRemoteSources(ctx context.Context, start string, limit int, asc bool) ([]*cstypes.RemoteSource, *http.Response, error) {
|
2019-02-21 15:08:30 +00:00
|
|
|
q := url.Values{}
|
|
|
|
if start != "" {
|
|
|
|
q.Add("start", start)
|
|
|
|
}
|
|
|
|
if limit > 0 {
|
|
|
|
q.Add("limit", strconv.Itoa(limit))
|
|
|
|
}
|
|
|
|
if asc {
|
|
|
|
q.Add("asc", "")
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
rss := []*cstypes.RemoteSource{}
|
2019-02-21 15:08:30 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", "/remotesources", q, jsonContent, nil, &rss)
|
2022-02-22 14:01:29 +00:00
|
|
|
return rss, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
func (c *Client) CreateRemoteSource(ctx context.Context, rs *cstypes.RemoteSource) (*cstypes.RemoteSource, *http.Response, error) {
|
2019-05-23 08:29:03 +00:00
|
|
|
rsj, err := json.Marshal(rs)
|
2019-02-21 15:08:30 +00:00
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
rs = new(cstypes.RemoteSource)
|
2019-05-23 08:29:03 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", "/remotesources", nil, jsonContent, bytes.NewReader(rsj), rs)
|
2022-02-22 14:01:29 +00:00
|
|
|
return rs, resp, errors.WithStack(err)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
func (c *Client) UpdateRemoteSource(ctx context.Context, remoteSourceRef string, remoteSource *cstypes.RemoteSource) (*cstypes.RemoteSource, *http.Response, error) {
|
2019-05-23 08:29:03 +00:00
|
|
|
rsj, err := json.Marshal(remoteSource)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-05-23 08:29:03 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
resRemoteSource := new(cstypes.RemoteSource)
|
2019-05-23 08:29:03 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/remotesources/%s", url.PathEscape(remoteSourceRef)), nil, jsonContent, bytes.NewReader(rsj), resRemoteSource)
|
2022-02-22 14:01:29 +00:00
|
|
|
return resRemoteSource, resp, errors.WithStack(err)
|
2019-05-23 08:29:03 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 09:07:53 +00:00
|
|
|
func (c *Client) DeleteRemoteSource(ctx context.Context, rsRef string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/remotesources/%s", rsRef), nil, jsonContent, nil)
|
2019-02-21 15:08:30 +00:00
|
|
|
}
|
2019-02-28 14:52:35 +00:00
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
func (c *Client) CreateOrg(ctx context.Context, org *cstypes.Organization) (*cstypes.Organization, *http.Response, error) {
|
2019-02-28 14:52:35 +00:00
|
|
|
oj, err := json.Marshal(org)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-02-28 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
org = new(cstypes.Organization)
|
2019-04-08 06:54:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", "/orgs", nil, jsonContent, bytes.NewReader(oj), org)
|
2022-02-22 14:01:29 +00:00
|
|
|
return org, resp, errors.WithStack(err)
|
2019-02-28 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 09:07:53 +00:00
|
|
|
func (c *Client) DeleteOrg(ctx context.Context, orgRef string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/orgs/%s", orgRef), nil, jsonContent, nil)
|
2019-02-28 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) AddOrgMember(ctx context.Context, orgRef, userRef string, role cstypes.MemberRole) (*cstypes.OrganizationMember, *http.Response, error) {
|
|
|
|
req := &csapitypes.AddOrgMemberRequest{
|
2019-05-09 14:47:22 +00:00
|
|
|
Role: role,
|
|
|
|
}
|
|
|
|
omj, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-05-09 14:47:22 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 11:19:55 +00:00
|
|
|
orgmember := new(cstypes.OrganizationMember)
|
2019-05-09 14:47:22 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/orgs/%s/members/%s", orgRef, userRef), nil, jsonContent, bytes.NewReader(omj), orgmember)
|
2022-02-22 14:01:29 +00:00
|
|
|
return orgmember, resp, errors.WithStack(err)
|
2019-05-09 14:47:22 +00:00
|
|
|
}
|
|
|
|
|
2019-05-14 09:20:09 +00:00
|
|
|
func (c *Client) RemoveOrgMember(ctx context.Context, orgRef, userRef string) (*http.Response, error) {
|
2019-05-09 15:05:13 +00:00
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/orgs/%s/members/%s", orgRef, userRef), nil, jsonContent, nil)
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetOrgs(ctx context.Context, start string, limit int, asc bool) ([]*cstypes.Organization, *http.Response, error) {
|
2019-02-28 14:52:35 +00:00
|
|
|
q := url.Values{}
|
|
|
|
if start != "" {
|
|
|
|
q.Add("start", start)
|
|
|
|
}
|
|
|
|
if limit > 0 {
|
|
|
|
q.Add("limit", strconv.Itoa(limit))
|
|
|
|
}
|
|
|
|
if asc {
|
|
|
|
q.Add("asc", "")
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
orgs := []*cstypes.Organization{}
|
2019-02-28 14:52:35 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", "/orgs", q, jsonContent, nil, &orgs)
|
2022-02-22 14:01:29 +00:00
|
|
|
return orgs, resp, errors.WithStack(err)
|
2019-02-28 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetOrg(ctx context.Context, orgRef string) (*cstypes.Organization, *http.Response, error) {
|
2022-02-21 11:19:55 +00:00
|
|
|
org := new(cstypes.Organization)
|
2019-05-03 09:07:53 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/orgs/%s", orgRef), nil, jsonContent, nil, org)
|
2022-02-22 14:01:29 +00:00
|
|
|
return org, resp, errors.WithStack(err)
|
2019-02-28 14:52:35 +00:00
|
|
|
}
|
2019-05-14 10:57:53 +00:00
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetOrgMembers(ctx context.Context, orgRef string) ([]*csapitypes.OrgMemberResponse, *http.Response, error) {
|
|
|
|
orgMembers := []*csapitypes.OrgMemberResponse{}
|
2019-05-14 10:57:53 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/orgs/%s/members", orgRef), nil, jsonContent, nil, &orgMembers)
|
2022-02-22 14:01:29 +00:00
|
|
|
return orgMembers, resp, errors.WithStack(err)
|
2019-05-14 10:57:53 +00:00
|
|
|
}
|