func (c *client) OrgSecretUpdate(namespace string, in *Secret) (*Secret, error) {
	out := new(Secret)
	uri := fmt.Sprintf(pathSecretsName, c.addr, namespace, in.Name)
	err := c.patch(uri, in, out)
	return out, err
}
OrgSecretUpdate updates a registry.
package drone
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"net/url"
	"strconv"
	"strings"
)
const (
	pathSelf              = "%s/api/user"
	pathRepos             = "%s/api/user/repos"
	pathIncomplete        = "%s/api/builds/incomplete"
	pathIncompleteV2      = "%s/api/builds/incomplete/v2"
	pathReposAll          = "%s/api/repos"
	pathRepo              = "%s/api/repos/%s/%s"
	pathChown             = "%s/api/repos/%s/%s/chown"
	pathRepair            = "%s/api/repos/%s/%s/repair"
	pathBuilds            = "%s/api/repos/%s/%s/builds?%s"
	pathBuild             = "%s/api/repos/%s/%s/builds/%v"
	pathApprove           = "%s/api/repos/%s/%s/builds/%d/approve/%d"
	pathDecline           = "%s/api/repos/%s/%s/builds/%d/decline/%d"
	pathPromote           = "%s/api/repos/%s/%s/builds/%d/promote?%s"
	pathRollback          = "%s/api/repos/%s/%s/builds/%d/rollback?%s"
	pathLog               = "%s/api/repos/%s/%s/builds/%d/logs/%d/%d"
	pathRepoSecrets       = "%s/api/repos/%s/%s/secrets"
	pathRepoSecret        = "%s/api/repos/%s/%s/secrets/%s"
	pathEncryptSecret     = "%s/api/repos/%s/%s/encrypt/secret"
	pathSign              = "%s/api/repos/%s/%s/sign"
	pathVerify            = "%s/api/repos/%s/%s/verify"
	pathCrons             = "%s/api/repos/%s/%s/cron"
	pathCron              = "%s/api/repos/%s/%s/cron/%s"
	pathSecrets           = "%s/api/secrets"
	pathSecretsNamespace  = "%s/api/secrets/%s"
	pathSecretsName       = "%s/api/secrets/%s/%s"
	pathUsers             = "%s/api/users"
	pathUser              = "%s/api/users/%s"
	pathQueue             = "%s/api/queue"
	pathServers           = "%s/api/servers"
	pathServer            = "%s/api/servers/%s"
	pathScalerPause       = "%s/api/pause"
	pathScalerResume      = "%s/api/resume"
	pathNodes             = "%s/api/nodes"
	pathNode              = "%s/api/nodes/%s"
	pathVersion           = "%s/version"
	pathTemplates         = "%s/api/templates"
	pathTemplateName      = "%s/api/templates/%s/%s"
	pathTemplateNamespace = "%s/api/templates/%s"
)
type client struct {
	client *http.Client
	addr   string
}
type ListOptions struct {
	Page int
	Size int
}
func encodeListOptions(opts ListOptions) string {
	params := url.Values{}
	if opts.Page != 0 {
		params.Set("page", strconv.Itoa(opts.Page))
	}
	if opts.Size != 0 {
		params.Set("per_page", strconv.Itoa(opts.Size))
	}
	return params.Encode()
}
func New(uri string) Client {
	return &client{http.DefaultClient, strings.TrimSuffix(uri, "/")}
}
func NewClient(uri string, cli *http.Client) Client {
	return &client{cli, strings.TrimSuffix(uri, "/")}
}
func (c *client) SetClient(client *http.Client) {
	c.client = client
}
func (c *client) SetAddress(addr string) {
	c.addr = addr
}
func (c *client) Self() (*User, error) {
	out := new(User)
	uri := fmt.Sprintf(pathSelf, c.addr)
	err := c.get(uri, out)
	return out, err
}
func (c *client) User(login string) (*User, error) {
	out := new(User)
	uri := fmt.Sprintf(pathUser, c.addr, login)
	err := c.get(uri, out)
	return out, err
}
func (c *client) UserList() ([]*User, error) {
	var out []*User
	uri := fmt.Sprintf(pathUsers, c.addr)
	err := c.get(uri, &out)
	return out, err
}
func (c *client) UserCreate(in *User) (*User, error) {
	out := new(User)
	uri := fmt.Sprintf(pathUsers, c.addr)
	err := c.post(uri, in, out)
	return out, err
}
func (c *client) UserUpdate(login string, in *UserPatch) (*User, error) {
	out := new(User)
	uri := fmt.Sprintf(pathUser, c.addr, login)
	err := c.patch(uri, in, out)
	return out, err
}
func (c *client) UserDelete(login string) error {
	uri := fmt.Sprintf(pathUser, c.addr, login)
	err := c.delete(uri)
	return err
}
func (c *client) Incomplete() ([]*Repo, error) {
	var out []*Repo
	uri := fmt.Sprintf(pathIncomplete, c.addr)
	err := c.get(uri, &out)
	return out, err
}
func (c *client) IncompleteV2() ([]*RepoBuildStage, error) {
	var out []*RepoBuildStage
	uri := fmt.Sprintf(pathIncompleteV2, c.addr)
	err := c.get(uri, &out)
	return out, err
}
func (c *client) Repo(owner, name string) (*Repo, error) {
	out := new(Repo)
	uri := fmt.Sprintf(pathRepo, c.addr, owner, name)
	err := c.get(uri, out)
	return out, err
}
func (c *client) RepoList() ([]*Repo, error) {
	var out []*Repo
	uri := fmt.Sprintf(pathRepos, c.addr)
	err := c.get(uri, &out)
	return out, err
}
func (c *client) RepoListSync() ([]*Repo, error) {
	var out []*Repo
	uri := fmt.Sprintf(pathRepos, c.addr)
	err := c.post(uri, nil, &out)
	return out, err
}
func (c *client) RepoListAll(opts ListOptions) ([]*Repo, error) {
	var out []*Repo
	uri := fmt.Sprintf(pathReposAll, c.addr)
	if opt := encodeListOptions(opts); opt != "" {
		uri = uri + "?" + opt
	}
	err := c.get(uri, &out)
	return out, err
}
func (c *client) RepoEnable(owner, name string) (*Repo, error) {
	out := new(Repo)
	uri := fmt.Sprintf(pathRepo, c.addr, owner, name)
	err := c.post(uri, nil, out)
	return out, err
}
func (c *client) RepoDisable(owner, name string) error {
	uri := fmt.Sprintf(pathRepo, c.addr, owner, name)
	err := c.delete(uri)
	return err
}
func (c *client) RepoDelete(owner, name string) error {
	uri := fmt.Sprintf(pathRepo+"?remove=true", c.addr, owner, name)
	err := c.delete(uri)
	return err
}
func (c *client) RepoUpdate(owner, name string, in *RepoPatch) (*Repo, error) {
	out := new(Repo)
	uri := fmt.Sprintf(pathRepo, c.addr, owner, name)
	err := c.patch(uri, in, out)
	return out, err
}
func (c *client) RepoChown(owner, name string) (*Repo, error) {
	out := new(Repo)
	uri := fmt.Sprintf(pathChown, c.addr, owner, name)
	err := c.post(uri, nil, out)
	return out, err
}
func (c *client) RepoRepair(owner, name string) error {
	uri := fmt.Sprintf(pathRepair, c.addr, owner, name)
	return c.post(uri, nil, nil)
}
func (c *client) Build(owner, name string, num int) (*Build, error) {
	out := new(Build)
	uri := fmt.Sprintf(pathBuild, c.addr, owner, name, num)
	err := c.get(uri, out)
	return out, err
}
func (c *client) BuildLast(owner, name, branch string) (*Build, error) {
	out := new(Build)
	uri := fmt.Sprintf(pathBuild, c.addr, owner, name, "latest")
	if branch != "" {
		uri += "?branch=" + branch
	}
	err := c.get(uri, out)
	return out, err
}
func (c *client) BuildList(owner, name string, opts ListOptions) ([]*Build, error) {
	var out []*Build
	uri := fmt.Sprintf(pathBuilds, c.addr, owner, name, encodeListOptions(opts))
	err := c.get(uri, &out)
	return out, err
}
func (c *client) BuildCreate(owner, name, commit, branch string, params map[string]string) (*Build, error) {
	out := new(Build)
	val := mapValues(params)
	if commit != "" {
		val.Set("commit", commit)
	}
	if branch != "" {
		val.Set("branch", branch)
	}
	uri := fmt.Sprintf(pathBuilds, c.addr, owner, name, val.Encode())
	err := c.post(uri, nil, out)
	return out, err
}
func (c *client) BuildRestart(owner, name string, build int, params map[string]string) (*Build, error) {
	out := new(Build)
	val := mapValues(params)
	uri := fmt.Sprintf(pathBuild, c.addr, owner, name, build)
	if len(params) > 0 {
		uri = uri + "?" + val.Encode()
	}
	err := c.post(uri, nil, out)
	return out, err
}
func (c *client) BuildCancel(owner, name string, build int) error {
	uri := fmt.Sprintf(pathBuild, c.addr, owner, name, build)
	err := c.delete(uri)
	return err
}
func (c *client) BuildPurge(owner, name string, before int) error {
	param := fmt.Sprintf("before=%d", before)
	uri := fmt.Sprintf(pathBuilds, c.addr, owner, name, param)
	err := c.delete(uri)
	return err
}
func (c *client) Promote(namespace, name string, build int, target string, params map[string]string) (*Build, error) {
	out := new(Build)
	val := mapValues(params)
	val.Set("target", target)
	uri := fmt.Sprintf(pathPromote, c.addr, namespace, name, build, val.Encode())
	err := c.post(uri, nil, out)
	return out, err
}
func (c *client) Rollback(namespace, name string, build int, target string, params map[string]string) (*Build, error) {
	out := new(Build)
	val := mapValues(params)
	val.Set("target", target)
	uri := fmt.Sprintf(pathRollback, c.addr, namespace, name, build, val.Encode())
	err := c.post(uri, nil, out)
	return out, err
}
func (c *client) Approve(namespace, name string, build, stage int) error {
	uri := fmt.Sprintf(pathApprove, c.addr, namespace, name, build, stage)
	err := c.post(uri, nil, nil)
	return err
}
func (c *client) Decline(namespace, name string, build, stage int) error {
	uri := fmt.Sprintf(pathDecline, c.addr, namespace, name, build, stage)
	err := c.post(uri, nil, nil)
	return err
}
func (c *client) Logs(owner, name string, build, stage, step int) ([]*Line, error) {
	var out []*Line
	uri := fmt.Sprintf(pathLog, c.addr, owner, name, build, stage, step)
	err := c.get(uri, &out)
	return out, err
}
func (c *client) LogsPurge(owner, name string, build, stage, step int) error {
	uri := fmt.Sprintf(pathLog, c.addr, owner, name, build, stage, step)
	err := c.delete(uri)
	return err
}
func (c *client) Sign(owner, name, file string) (string, error) {
	in := struct {
		Data string `json:"data"`
	}{Data: file}
	out := struct {
		Data string `json:"data"`
	}{}
	uri := fmt.Sprintf(pathSign, c.addr, owner, name)
	err := c.post(uri, &in, &out)
	return out.Data, err
}
func (c *client) Verify(owner, name, file string) error {
	in := struct {
		Data string `json:"data"`
	}{Data: file}
	uri := fmt.Sprintf(pathVerify, c.addr, owner, name)
	return c.post(uri, &in, nil)
}
func (c *client) Encrypt(owner, name string, secret *Secret) (string, error) {
	out := struct {
		Data string `json:"data"`
	}{}
	uri := fmt.Sprintf(pathEncryptSecret, c.addr, owner, name)
	err := c.post(uri, secret, &out)
	return out.Data, err
}
func (c *client) Secret(owner, name, secret string) (*Secret, error) {
	out := new(Secret)
	uri := fmt.Sprintf(pathRepoSecret, c.addr, owner, name, secret)
	err := c.get(uri, out)
	return out, err
}
func (c *client) SecretList(owner, name string) ([]*Secret, error) {
	var out []*Secret
	uri := fmt.Sprintf(pathRepoSecrets, c.addr, owner, name)
	err := c.get(uri, &out)
	return out, err
}
func (c *client) SecretCreate(owner, name string, in *Secret) (*Secret, error) {
	out := new(Secret)
	uri := fmt.Sprintf(pathRepoSecrets, c.addr, owner, name)
	err := c.post(uri, in, out)
	return out, err
}
func (c *client) SecretUpdate(owner, name string, in *Secret) (*Secret, error) {
	out := new(Secret)
	uri := fmt.Sprintf(pathRepoSecret, c.addr, owner, name, in.Name)
	err := c.patch(uri, in, out)
	return out, err
}
func (c *client) SecretDelete(owner, name, secret string) error {
	uri := fmt.Sprintf(pathRepoSecret, c.addr, owner, name, secret)
	return c.delete(uri)
}
func (c *client) OrgSecret(namespace, name string) (*Secret, error) {
	out := new(Secret)
	uri := fmt.Sprintf(pathSecretsName, c.addr, namespace, name)
	err := c.get(uri, &out)
	return out, err
}
func (c *client) OrgSecretList(namespace string) ([]*Secret, error) {
	var out []*Secret
	uri := fmt.Sprintf(pathSecretsNamespace, c.addr, namespace)
	err := c.get(uri, &out)
	return out, err
}
func (c *client) OrgSecretListAll() ([]*Secret, error) {
	var out []*Secret
	uri := fmt.Sprintf(pathSecrets, c.addr)
	err := c.get(uri, &out)
	return out, err
}
func (c *client) OrgSecretCreate(namespace string, in *Secret) (*Secret, error) {
	out := new(Secret)
	uri := fmt.Sprintf(pathSecretsNamespace, c.addr, namespace)
	err := c.post(uri, in, out)
	return out, err
}