2019-02-21 16:58:25 +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 16:58:25 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2019-02-28 14:52:35 +00:00
|
|
|
"path"
|
2019-02-21 16:58:25 +00:00
|
|
|
"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
|
|
|
gwapitypes "agola.io/agola/services/gateway/api/types"
|
2019-02-21 16:58:25 +00:00
|
|
|
)
|
|
|
|
|
2019-04-08 10:28:15 +00:00
|
|
|
var jsonContent = http.Header{"Content-Type": []string{"application/json"}}
|
2019-02-21 16:58:25 +00:00
|
|
|
|
|
|
|
type Client struct {
|
|
|
|
url string
|
|
|
|
client *http.Client
|
|
|
|
token string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewClient initializes and returns a API client.
|
|
|
|
func NewClient(url, token string) *Client {
|
|
|
|
return &Client{
|
|
|
|
url: strings.TrimSuffix(url, "/"),
|
|
|
|
client: &http.Client{},
|
|
|
|
token: token,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 16:58:25 +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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
req.Header.Set("Authorization", "token "+c.token)
|
|
|
|
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 16:58:25 +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 16:58:25 +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 16:58:25 +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 16:58:25 +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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProjectGroup(ctx context.Context, projectGroupRef string) (*gwapitypes.ProjectGroupResponse, *http.Response, error) {
|
|
|
|
projectGroup := new(gwapitypes.ProjectGroupResponse)
|
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-02-28 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProjectGroupSubgroups(ctx context.Context, projectGroupRef string) ([]*gwapitypes.ProjectGroupResponse, *http.Response, error) {
|
|
|
|
projectGroups := []*gwapitypes.ProjectGroupResponse{}
|
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-02-28 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProjectGroupProjects(ctx context.Context, projectGroupRef string) ([]*gwapitypes.ProjectResponse, *http.Response, error) {
|
|
|
|
projects := []*gwapitypes.ProjectResponse{}
|
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-02-21 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetProject(ctx context.Context, projectRef string) (*gwapitypes.ProjectResponse, *http.Response, error) {
|
|
|
|
project := new(gwapitypes.ProjectResponse)
|
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-28 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateProjectGroup(ctx context.Context, req *gwapitypes.CreateProjectGroupRequest) (*gwapitypes.ProjectResponse, *http.Response, error) {
|
2019-03-14 13:36:18 +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-03-14 13:36:18 +00:00
|
|
|
}
|
2019-02-28 14:52:35 +00:00
|
|
|
|
2019-10-01 07:41:56 +00:00
|
|
|
projectGroup := new(gwapitypes.ProjectResponse)
|
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", "/projectgroups", nil, jsonContent, bytes.NewReader(reqj), projectGroup)
|
2022-02-22 14:01:29 +00:00
|
|
|
return projectGroup, resp, errors.WithStack(err)
|
2019-10-01 07:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) UpdateProjectGroup(ctx context.Context, projectGroupRef string, req *gwapitypes.UpdateProjectGroupRequest) (*gwapitypes.ProjectResponse, *http.Response, error) {
|
|
|
|
reqj, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-10-01 07:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
projectGroup := new(gwapitypes.ProjectResponse)
|
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projectgroups", url.PathEscape(projectGroupRef)), nil, jsonContent, bytes.NewReader(reqj), projectGroup)
|
2022-02-22 14:01:29 +00:00
|
|
|
return projectGroup, resp, errors.WithStack(err)
|
2019-02-28 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-05-12 22:24:16 +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) CreateProject(ctx context.Context, req *gwapitypes.CreateProjectRequest) (*gwapitypes.ProjectResponse, *http.Response, error) {
|
2019-02-21 16:58:25 +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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
project := new(gwapitypes.ProjectResponse)
|
2019-04-08 06:54:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", "/projects", nil, jsonContent, bytes.NewReader(reqj), project)
|
2022-02-22 14:01:29 +00:00
|
|
|
return project, resp, errors.WithStack(err)
|
2019-09-24 13:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) UpdateProject(ctx context.Context, projectRef string, req *gwapitypes.UpdateProjectRequest) (*gwapitypes.ProjectResponse, *http.Response, error) {
|
|
|
|
reqj, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-09-24 13:19:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
project := new(gwapitypes.ProjectResponse)
|
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projects", url.PathEscape(projectRef)), nil, jsonContent, bytes.NewReader(reqj), project)
|
2022-02-22 14:01:29 +00:00
|
|
|
return project, resp, errors.WithStack(err)
|
2019-02-21 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateProjectGroupSecret(ctx context.Context, projectGroupRef string, req *gwapitypes.CreateSecretRequest) (*gwapitypes.SecretResponse, *http.Response, error) {
|
2019-03-14 13:36:18 +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-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
secret := new(gwapitypes.SecretResponse)
|
2019-04-08 06:54:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", path.Join("/projectgroups", url.PathEscape(projectGroupRef), "secrets"), nil, jsonContent, bytes.NewReader(reqj), secret)
|
2022-02-22 14:01:29 +00:00
|
|
|
return secret, 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, req *gwapitypes.UpdateSecretRequest) (*gwapitypes.SecretResponse, *http.Response, error) {
|
2019-07-08 08:32:45 +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-07-08 08:32:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
secret := new(gwapitypes.SecretResponse)
|
2019-07-08 08:32:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projectgroups", url.PathEscape(projectGroupRef), "secrets", secretName), nil, jsonContent, bytes.NewReader(reqj), secret)
|
2022-02-22 14:01:29 +00:00
|
|
|
return secret, resp, errors.WithStack(err)
|
2019-07-08 08:32:45 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 09:00:45 +00:00
|
|
|
func (c *Client) DeleteProjectGroupSecret(ctx context.Context, projectGroupRef, secretName string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", path.Join("/projectgroups", url.PathEscape(projectGroupRef), "secrets", secretName), nil, jsonContent, nil)
|
|
|
|
}
|
|
|
|
|
2019-09-19 08:12:19 +00:00
|
|
|
func (c *Client) GetProjectGroupSecrets(ctx context.Context, projectRef string, tree, removeoverridden bool) ([]*gwapitypes.SecretResponse, *http.Response, error) {
|
|
|
|
secrets := []*gwapitypes.SecretResponse{}
|
|
|
|
q := url.Values{}
|
|
|
|
if tree {
|
|
|
|
q.Add("tree", "")
|
|
|
|
}
|
|
|
|
if removeoverridden {
|
|
|
|
q.Add("removeoverridden", "")
|
|
|
|
}
|
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/secrets", url.PathEscape(projectRef)), q, jsonContent, nil, &secrets)
|
2022-02-22 14:01:29 +00:00
|
|
|
return secrets, resp, errors.WithStack(err)
|
2019-09-19 08:12:19 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateProjectSecret(ctx context.Context, projectRef string, req *gwapitypes.CreateSecretRequest) (*gwapitypes.SecretResponse, *http.Response, error) {
|
2019-03-14 13:36:18 +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-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
secret := new(gwapitypes.SecretResponse)
|
2019-04-08 06:54:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", path.Join("/projects", url.PathEscape(projectRef), "secrets"), nil, jsonContent, bytes.NewReader(reqj), secret)
|
2022-02-22 14:01:29 +00:00
|
|
|
return secret, resp, errors.WithStack(err)
|
2019-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateProjectSecret(ctx context.Context, projectRef, secretName string, req *gwapitypes.UpdateSecretRequest) (*gwapitypes.SecretResponse, *http.Response, error) {
|
2019-07-08 08:32:45 +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-07-08 08:32:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
secret := new(gwapitypes.SecretResponse)
|
2019-07-08 08:32:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projects", url.PathEscape(projectRef), "secrets", secretName), nil, jsonContent, bytes.NewReader(reqj), secret)
|
2022-02-22 14:01:29 +00:00
|
|
|
return secret, resp, errors.WithStack(err)
|
2019-07-08 08:32:45 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 09:00:45 +00:00
|
|
|
func (c *Client) DeleteProjectSecret(ctx context.Context, projectRef, secretName string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", path.Join("/projects", url.PathEscape(projectRef), "secrets", secretName), nil, jsonContent, nil)
|
|
|
|
}
|
|
|
|
|
2019-09-19 08:12:19 +00:00
|
|
|
func (c *Client) GetProjectSecrets(ctx context.Context, projectRef string, tree, removeoverridden bool) ([]*gwapitypes.SecretResponse, *http.Response, error) {
|
|
|
|
secrets := []*gwapitypes.SecretResponse{}
|
|
|
|
q := url.Values{}
|
|
|
|
if tree {
|
|
|
|
q.Add("tree", "")
|
|
|
|
}
|
|
|
|
if removeoverridden {
|
|
|
|
q.Add("removeoverridden", "")
|
|
|
|
}
|
|
|
|
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-09-19 08:12:19 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateProjectGroupVariable(ctx context.Context, projectGroupRef string, req *gwapitypes.CreateVariableRequest) (*gwapitypes.VariableResponse, *http.Response, error) {
|
2019-03-14 13:36:18 +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-03-14 13:36:18 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
variable := new(gwapitypes.VariableResponse)
|
2019-04-08 06:54:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", path.Join("/projectgroups", url.PathEscape(projectGroupRef), "variables"), nil, jsonContent, bytes.NewReader(reqj), variable)
|
2022-02-22 14:01:29 +00:00
|
|
|
return variable, resp, errors.WithStack(err)
|
2019-02-28 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateProjectGroupVariable(ctx context.Context, projectGroupRef, variableName string, req *gwapitypes.UpdateVariableRequest) (*gwapitypes.VariableResponse, *http.Response, error) {
|
2019-07-06 13:25:45 +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-07-06 13:25:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
variable := new(gwapitypes.VariableResponse)
|
2019-07-06 13:25:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projectgroups", url.PathEscape(projectGroupRef), "variables", variableName), nil, jsonContent, bytes.NewReader(reqj), variable)
|
2022-02-22 14:01:29 +00:00
|
|
|
return variable, resp, errors.WithStack(err)
|
2019-07-06 13:25:45 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 09:11:27 +00:00
|
|
|
func (c *Client) DeleteProjectGroupVariable(ctx context.Context, projectGroupRef, variableName string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", path.Join("/projectgroups", url.PathEscape(projectGroupRef), "variables", variableName), nil, jsonContent, nil)
|
|
|
|
}
|
|
|
|
|
2019-09-19 08:12:19 +00:00
|
|
|
func (c *Client) GetProjectGroupVariables(ctx context.Context, projectRef string, tree, removeoverridden bool) ([]*gwapitypes.VariableResponse, *http.Response, error) {
|
|
|
|
variables := []*gwapitypes.VariableResponse{}
|
|
|
|
q := url.Values{}
|
|
|
|
if tree {
|
|
|
|
q.Add("tree", "")
|
|
|
|
}
|
|
|
|
if removeoverridden {
|
|
|
|
q.Add("removeoverridden", "")
|
|
|
|
}
|
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/projectgroups/%s/variables", url.PathEscape(projectRef)), q, jsonContent, nil, &variables)
|
2022-02-22 14:01:29 +00:00
|
|
|
return variables, resp, errors.WithStack(err)
|
2019-09-19 08:12:19 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateProjectVariable(ctx context.Context, projectRef string, req *gwapitypes.CreateVariableRequest) (*gwapitypes.VariableResponse, *http.Response, error) {
|
2019-04-02 09:07:39 +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-04-02 09:07:39 +00:00
|
|
|
}
|
2019-02-28 14:52:35 +00:00
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
variable := new(gwapitypes.VariableResponse)
|
2019-04-08 06:54:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", path.Join("/projects", url.PathEscape(projectRef), "variables"), nil, jsonContent, bytes.NewReader(reqj), variable)
|
2022-02-22 14:01:29 +00:00
|
|
|
return variable, resp, errors.WithStack(err)
|
2019-02-28 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateProjectVariable(ctx context.Context, projectRef, variableName string, req *gwapitypes.UpdateVariableRequest) (*gwapitypes.VariableResponse, *http.Response, error) {
|
2019-07-06 13:25:45 +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-07-06 13:25:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
variable := new(gwapitypes.VariableResponse)
|
2019-07-06 13:25:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", path.Join("/projects", url.PathEscape(projectRef), "variables", variableName), nil, jsonContent, bytes.NewReader(reqj), variable)
|
2022-02-22 14:01:29 +00:00
|
|
|
return variable, resp, errors.WithStack(err)
|
2019-07-06 13:25:45 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 09:11:27 +00:00
|
|
|
func (c *Client) DeleteProjectVariable(ctx context.Context, projectRef, variableName string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", path.Join("/projects", url.PathEscape(projectRef), "variables", variableName), nil, jsonContent, nil)
|
|
|
|
}
|
|
|
|
|
2019-09-19 08:12:19 +00:00
|
|
|
func (c *Client) GetProjectVariables(ctx context.Context, projectRef string, tree, removeoverridden bool) ([]*gwapitypes.VariableResponse, *http.Response, error) {
|
|
|
|
variables := []*gwapitypes.VariableResponse{}
|
|
|
|
q := url.Values{}
|
|
|
|
if tree {
|
|
|
|
q.Add("tree", "")
|
|
|
|
}
|
|
|
|
if removeoverridden {
|
|
|
|
q.Add("removeoverridden", "")
|
|
|
|
}
|
|
|
|
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-09-19 08:12:19 +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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) ProjectCreateRun(ctx context.Context, projectRef string, req *gwapitypes.ProjectCreateRunRequest) (*http.Response, error) {
|
2019-06-11 07:31:12 +00:00
|
|
|
reqj, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, errors.WithStack(err)
|
2019-06-11 07:31:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c.getResponse(ctx, "POST", fmt.Sprintf("/projects/%s/createrun", url.PathEscape(projectRef)), nil, jsonContent, bytes.NewReader(reqj))
|
|
|
|
}
|
|
|
|
|
2019-04-02 09:07:39 +00:00
|
|
|
func (c *Client) ReconfigProject(ctx context.Context, projectRef string) (*http.Response, error) {
|
2019-04-08 06:54:45 +00:00
|
|
|
return c.getResponse(ctx, "PUT", fmt.Sprintf("/projects/%s/reconfig", url.PathEscape(projectRef)), nil, jsonContent, nil)
|
2019-02-21 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetCurrentUser(ctx context.Context) (*gwapitypes.UserResponse, *http.Response, error) {
|
|
|
|
user := new(gwapitypes.UserResponse)
|
2019-04-03 13:06:02 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", "/user", nil, jsonContent, nil, user)
|
2022-02-22 14:01:29 +00:00
|
|
|
return user, resp, errors.WithStack(err)
|
2019-04-03 13:06:02 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetUser(ctx context.Context, userRef string) (*gwapitypes.UserResponse, *http.Response, error) {
|
|
|
|
user := new(gwapitypes.UserResponse)
|
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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetUsers(ctx context.Context, start string, limit int, asc bool) ([]*gwapitypes.UserResponse, *http.Response, error) {
|
2019-02-21 16:58:25 +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 := []*gwapitypes.UserResponse{}
|
2019-02-21 16:58:25 +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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateUser(ctx context.Context, req *gwapitypes.CreateUserRequest) (*gwapitypes.UserResponse, *http.Response, error) {
|
2019-02-21 16:58:25 +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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
user := new(gwapitypes.UserResponse)
|
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 16:58:25 +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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UserCreateRun(ctx context.Context, req *gwapitypes.UserCreateRunRequest) (*http.Response, error) {
|
2019-06-11 13:09:41 +00:00
|
|
|
reqj, err := json.Marshal(req)
|
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, errors.WithStack(err)
|
2019-06-11 13:09:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return c.getResponse(ctx, "POST", "/user/createrun", nil, jsonContent, bytes.NewReader(reqj))
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateUserLA(ctx context.Context, userRef string, req *gwapitypes.CreateUserLARequest) (*gwapitypes.CreateUserLAResponse, *http.Response, error) {
|
2019-02-21 16:58:25 +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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
la := new(gwapitypes.CreateUserLAResponse)
|
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 16:58:25 +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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) RegisterUser(ctx context.Context, req *gwapitypes.RegisterUserRequest) (*gwapitypes.RegisterUserResponse, *http.Response, error) {
|
2019-03-29 16:53:15 +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-03-29 16:53:15 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
res := new(gwapitypes.RegisterUserResponse)
|
2020-02-19 09:03:13 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", "/auth/register", nil, jsonContent, bytes.NewReader(reqj), res)
|
2022-02-22 14:01:29 +00:00
|
|
|
return res, resp, errors.WithStack(err)
|
2019-03-29 16:53:15 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateUserToken(ctx context.Context, userRef string, req *gwapitypes.CreateUserTokenRequest) (*gwapitypes.CreateUserTokenResponse, *http.Response, error) {
|
2019-02-21 16:58:25 +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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
tresp := new(gwapitypes.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 16:58:25 +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-04-05 13:01:57 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetRun(ctx context.Context, runID string) (*gwapitypes.RunResponse, *http.Response, error) {
|
|
|
|
run := new(gwapitypes.RunResponse)
|
2019-04-08 14:11:19 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/runs/%s", runID), nil, jsonContent, nil, run)
|
2022-02-22 14:01:29 +00:00
|
|
|
return run, resp, errors.WithStack(err)
|
2019-02-21 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-11-09 10:18:00 +00:00
|
|
|
func (c *Client) GetRunTask(ctx context.Context, runID, taskID string) (*gwapitypes.RunTaskResponse, *http.Response, error) {
|
|
|
|
task := new(gwapitypes.RunTaskResponse)
|
2019-11-25 13:42:34 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/runs/%s/tasks/%s", runID, taskID), nil, jsonContent, nil, task)
|
2022-02-22 14:01:29 +00:00
|
|
|
return task, resp, errors.WithStack(err)
|
2019-11-09 10:18:00 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetRuns(ctx context.Context, phaseFilter, resultFilter, groups, runGroups []string, start string, limit int, asc bool) ([]*gwapitypes.RunsResponse, *http.Response, error) {
|
2019-02-21 16:58:25 +00:00
|
|
|
q := url.Values{}
|
|
|
|
for _, phase := range phaseFilter {
|
|
|
|
q.Add("phase", phase)
|
|
|
|
}
|
2019-07-05 08:42:45 +00:00
|
|
|
for _, result := range resultFilter {
|
|
|
|
q.Add("result", result)
|
|
|
|
}
|
2019-02-21 16:58:25 +00:00
|
|
|
for _, group := range groups {
|
|
|
|
q.Add("group", group)
|
|
|
|
}
|
|
|
|
for _, runGroup := range runGroups {
|
|
|
|
q.Add("rungroup", runGroup)
|
|
|
|
}
|
|
|
|
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
|
|
|
getRunsResponse := []*gwapitypes.RunsResponse{}
|
2019-06-11 07:31:12 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", "/runs", q, jsonContent, nil, &getRunsResponse)
|
2022-02-22 14:01:29 +00:00
|
|
|
return getRunsResponse, resp, errors.WithStack(err)
|
2019-02-21 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 10:07:10 +00:00
|
|
|
func (c *Client) GetLogs(ctx context.Context, runID, taskID string, setup bool, step int, follow bool) (*http.Response, error) {
|
2019-08-05 15:33:30 +00:00
|
|
|
q := url.Values{}
|
|
|
|
q.Add("runID", runID)
|
|
|
|
q.Add("taskID", taskID)
|
|
|
|
if setup {
|
|
|
|
q.Add("setup", "")
|
|
|
|
} else {
|
|
|
|
q.Add("step", strconv.Itoa(step))
|
|
|
|
}
|
2019-11-26 10:07:10 +00:00
|
|
|
if follow {
|
|
|
|
q.Add("follow", "")
|
|
|
|
}
|
2019-08-05 15:33:30 +00:00
|
|
|
return c.getResponse(ctx, "GET", "/logs", q, nil, nil)
|
|
|
|
}
|
|
|
|
|
2019-11-09 10:18:00 +00:00
|
|
|
func (c *Client) DeleteLogs(ctx context.Context, runID, taskID string, setup bool, step int) (*http.Response, error) {
|
|
|
|
q := url.Values{}
|
|
|
|
q.Add("runID", runID)
|
|
|
|
q.Add("taskID", taskID)
|
|
|
|
if setup {
|
|
|
|
q.Add("setup", "")
|
|
|
|
} else {
|
|
|
|
q.Add("step", strconv.Itoa(step))
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.getResponse(ctx, "DELETE", "/logs", q, nil, nil)
|
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetRemoteSource(ctx context.Context, rsRef string) (*gwapitypes.RemoteSourceResponse, *http.Response, error) {
|
|
|
|
rs := new(gwapitypes.RemoteSourceResponse)
|
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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetRemoteSources(ctx context.Context, start string, limit int, asc bool) ([]*gwapitypes.RemoteSourceResponse, *http.Response, error) {
|
2019-02-21 16:58:25 +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 := []*gwapitypes.RemoteSourceResponse{}
|
2019-02-21 16:58:25 +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 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateRemoteSource(ctx context.Context, req *gwapitypes.CreateRemoteSourceRequest) (*gwapitypes.RemoteSourceResponse, *http.Response, error) {
|
2019-05-23 08:29:03 +00:00
|
|
|
rsj, err := json.Marshal(req)
|
2019-02-21 16:58:25 +00:00
|
|
|
if err != nil {
|
2022-02-22 14:01:29 +00:00
|
|
|
return nil, nil, errors.WithStack(err)
|
2019-02-21 16:58:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
rs := new(gwapitypes.RemoteSourceResponse)
|
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-05-23 08:29:03 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) UpdateRemoteSource(ctx context.Context, rsRef string, req *gwapitypes.UpdateRemoteSourceRequest) (*gwapitypes.RemoteSourceResponse, *http.Response, error) {
|
2019-05-23 08:29:03 +00:00
|
|
|
rsj, err := json.Marshal(req)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
rs := new(gwapitypes.RemoteSourceResponse)
|
2019-05-23 08:29:03 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/remotesources/%s", rsRef), nil, jsonContent, bytes.NewReader(rsj), rs)
|
2022-02-22 14:01:29 +00:00
|
|
|
return rs, resp, errors.WithStack(err)
|
2019-02-21 16:58:25 +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 16:58:25 +00:00
|
|
|
}
|
2019-02-28 14:52:35 +00:00
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) CreateOrg(ctx context.Context, req *gwapitypes.CreateOrgRequest) (*gwapitypes.OrgResponse, *http.Response, error) {
|
2019-02-28 14:52:35 +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-28 14:52:35 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
org := new(gwapitypes.OrgResponse)
|
2019-04-08 06:54:45 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "POST", "/orgs", nil, jsonContent, bytes.NewReader(reqj), 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-05-14 09:25:12 +00:00
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) AddOrgMember(ctx context.Context, orgRef, userRef string, role gwapitypes.MemberRole) (*gwapitypes.AddOrgMemberResponse, *http.Response, error) {
|
|
|
|
req := &gwapitypes.AddOrgMemberRequest{
|
2019-05-14 09:25:12 +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-14 09:25:12 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
res := new(gwapitypes.AddOrgMemberResponse)
|
2019-05-14 09:25:12 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "PUT", fmt.Sprintf("/orgs/%s/members/%s", orgRef, userRef), nil, jsonContent, bytes.NewReader(omj), res)
|
2022-02-22 14:01:29 +00:00
|
|
|
return res, resp, errors.WithStack(err)
|
2019-05-14 09:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) RemoveOrgMember(ctx context.Context, orgRef, userRef string) (*http.Response, error) {
|
|
|
|
return c.getResponse(ctx, "DELETE", fmt.Sprintf("/orgs/%s/members/%s", orgRef, userRef), nil, jsonContent, nil)
|
|
|
|
}
|
2019-05-14 10:58:29 +00:00
|
|
|
|
2019-07-31 13:39:07 +00:00
|
|
|
func (c *Client) GetOrgMembers(ctx context.Context, orgRef string) (*gwapitypes.OrgMembersResponse, *http.Response, error) {
|
|
|
|
res := &gwapitypes.OrgMembersResponse{}
|
2019-05-14 10:58:29 +00:00
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", fmt.Sprintf("/orgs/%s/members", orgRef), nil, jsonContent, nil, &res)
|
2022-02-22 14:01:29 +00:00
|
|
|
return res, resp, errors.WithStack(err)
|
2019-05-14 10:58:29 +00:00
|
|
|
}
|
2019-10-04 09:32:07 +00:00
|
|
|
|
|
|
|
func (c *Client) GetVersion(ctx context.Context) (*gwapitypes.VersionResponse, *http.Response, error) {
|
|
|
|
res := &gwapitypes.VersionResponse{}
|
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", "/version", nil, jsonContent, nil, &res)
|
2022-02-22 14:01:29 +00:00
|
|
|
return res, resp, errors.WithStack(err)
|
2019-10-04 09:32:07 +00:00
|
|
|
}
|
2022-01-26 15:52:10 +00:00
|
|
|
|
|
|
|
func (c *Client) GetUserOrgs(ctx context.Context) ([]*gwapitypes.UserOrgsResponse, *http.Response, error) {
|
|
|
|
userOrgs := []*gwapitypes.UserOrgsResponse{}
|
|
|
|
resp, err := c.getParsedResponse(ctx, "GET", "/user/orgs", nil, jsonContent, nil, &userOrgs)
|
2022-02-22 14:01:29 +00:00
|
|
|
return userOrgs, resp, errors.WithStack(err)
|
2022-01-26 15:52:10 +00:00
|
|
|
}
|