1
0
mirror of https://github.com/drone/drone-cli.git synced 2024-11-22 17:01:58 +01:00

support for latest drone-go 0.9

This commit is contained in:
Brad Rydzewski 2018-09-20 16:04:58 -07:00
parent 7b2bbca496
commit 8ab39ea77b
61 changed files with 730 additions and 1876 deletions

2
Gopkg.lock generated

@ -105,7 +105,7 @@
"plugin/logger",
"plugin/secret"
]
revision = "b320d99c80703685b42e6d3126adbaad5c52a96d"
revision = "70af34cccf3c52890f3e4490e06f0bba2e2969c7"
[[projects]]
branch = "master"

@ -9,14 +9,13 @@ var Command = cli.Command{
Subcommands: []cli.Command{
buildListCmd,
buildLastCmd,
buildLogsCmd,
buildInfoCmd,
buildStopCmd,
buildStartCmd,
buildApproveCmd,
buildDeclineCmd,
buildQueueCmd,
buildKillCmd,
buildPsCmd,
buildPromoteCmd,
buildRollbackCmd,
},
}

@ -10,8 +10,8 @@ import (
var buildApproveCmd = cli.Command{
Name: "approve",
Usage: "approve a build",
ArgsUsage: "<repo/name> <build>",
Usage: "approve a build stage",
ArgsUsage: "<repo/name> <build> <stage>",
Action: buildApprove,
}
@ -25,13 +25,17 @@ func buildApprove(c *cli.Context) (err error) {
if err != nil {
return err
}
stage, err := strconv.Atoi(c.Args().Get(2))
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
_, err = client.BuildApprove(owner, name, number)
err = client.Approve(owner, name, number, stage)
if err != nil {
return err
}

@ -10,8 +10,8 @@ import (
var buildDeclineCmd = cli.Command{
Name: "decline",
Usage: "decline a build",
ArgsUsage: "<repo/name> <build>",
Usage: "decline a build stage",
ArgsUsage: "<repo/name> <build> <stage>",
Action: buildDecline,
}
@ -25,13 +25,17 @@ func buildDecline(c *cli.Context) (err error) {
if err != nil {
return err
}
stage, err := strconv.Atoi(c.Args().Get(2))
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
_, err = client.BuildDecline(owner, name, number)
err = client.Decline(owner, name, number, stage)
if err != nil {
return err
}

@ -43,7 +43,7 @@ func buildInfo(c *cli.Context) error {
if err != nil {
return err
}
number = build.Number
number = int(build.Number)
} else {
number, err = strconv.Atoi(buildArg)
if err != nil {
@ -67,9 +67,9 @@ func buildInfo(c *cli.Context) error {
var tmplBuildInfo = `Number: {{ .Number }}
Status: {{ .Status }}
Event: {{ .Event }}
Commit: {{ .Commit }}
Branch: {{ .Branch }}
Commit: {{ .After }}
Branch: {{ .Target }}
Ref: {{ .Ref }}
Author: {{ .Author }} {{ if .AuthorEmail }}<{{.AuthorEmail}}>{{ end }}
Message: {{ .Message }}
Author: {{ .Author }}
`

@ -1,42 +0,0 @@
package build
import (
"fmt"
"strconv"
"github.com/drone/drone-cli/drone/internal"
"github.com/urfave/cli"
)
var buildKillCmd = cli.Command{
Name: "kill",
Usage: "force kill a build",
ArgsUsage: "<repo/name> <build>",
Action: buildKill,
Hidden: true,
}
func buildKill(c *cli.Context) (err error) {
repo := c.Args().First()
owner, name, err := internal.ParseRepo(repo)
if err != nil {
return err
}
number, err := strconv.Atoi(c.Args().Get(1))
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
err = client.BuildKill(owner, name, number)
if err != nil {
return err
}
fmt.Printf("Force killing build %s/%s#%d\n", owner, name, number)
return nil
}

@ -71,7 +71,7 @@ func buildList(c *cli.Context) error {
if count >= limit {
break
}
if branch != "" && build.Branch != branch {
if branch != "" && build.Target != branch {
continue
}
if event != "" && build.Event != event {
@ -90,9 +90,9 @@ func buildList(c *cli.Context) error {
var tmplBuildList = "\x1b[33mBuild #{{ .Number }} \x1b[0m" + `
Status: {{ .Status }}
Event: {{ .Event }}
Commit: {{ .Commit }}
Branch: {{ .Branch }}
Commit: {{ .After }}
Branch: {{ .Target }}
Ref: {{ .Ref }}
Author: {{ .Author }} {{ if .Email }}<{{.Email}}>{{ end }}
Author: {{ .Author }} {{ if .AuthorEmail }}<{{.AuthorEmail}}>{{ end }}
Message: {{ .Message }}
`

@ -1,18 +0,0 @@
package build
import (
"fmt"
"github.com/urfave/cli"
)
var buildLogsCmd = cli.Command{
Name: "logs",
Usage: "show build logs",
ArgsUsage: "<repo/name> [build] [job]",
Action: buildLogs,
}
func buildLogs(c *cli.Context) error {
return fmt.Errorf("Command temporarily disabled. See https://github.com/drone/drone/issues/2005")
}

@ -0,0 +1,47 @@
package build
import (
"strconv"
"github.com/drone/drone-cli/drone/internal"
"github.com/urfave/cli"
)
var buildPromoteCmd = cli.Command{
Name: "promote",
Usage: "promote a build",
ArgsUsage: "<repo/name> <build> <environment>",
Action: buildPromote,
Flags: []cli.Flag{
cli.StringSliceFlag{
Name: "param, p",
Usage: "custom parameters to be injected into the job environment. Format: KEY=value",
},
},
}
func buildPromote(c *cli.Context) (err error) {
repo := c.Args().First()
owner, name, err := internal.ParseRepo(repo)
if err != nil {
return err
}
number, err := strconv.Atoi(c.Args().Get(1))
if err != nil {
return err
}
target := c.Args().Get(2)
params := internal.ParseKeyPair(c.StringSlice("param"))
client, err := internal.NewClient(c)
if err != nil {
return err
}
_, err = client.Promote(owner, name, number, target, params)
if err != nil {
return err
}
return nil
}

@ -1,82 +0,0 @@
package build
import (
"os"
"strconv"
"text/template"
"github.com/drone/drone-cli/drone/internal"
"github.com/urfave/cli"
)
var buildPsCmd = cli.Command{
Name: "ps",
Usage: "show build steps",
ArgsUsage: "<repo/name> [build]",
Action: buildPs,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplBuildPs,
},
},
}
func buildPs(c *cli.Context) error {
repo := c.Args().First()
owner, name, err := internal.ParseRepo(repo)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
buildArg := c.Args().Get(1)
var number int
if buildArg == "last" || len(buildArg) == 0 {
// Fetch the build number from the last build
build, err := client.BuildLast(owner, name, "")
if err != nil {
return err
}
number = build.Number
} else {
number, err = strconv.Atoi(buildArg)
if err != nil {
return err
}
}
build, err := client.Build(owner, name, number)
if err != nil {
return err
}
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
if err != nil {
return err
}
for _, proc := range build.Procs {
for _, child := range proc.Children {
if err := tmpl.Execute(os.Stdout, child); err != nil {
return err
}
}
}
return nil
}
// template for build ps information
var tmplBuildPs = "\x1b[33mProc #{{ .PID }} \x1b[0m" + `
Step: {{ .Name }}
State: {{ .State }}
`

@ -58,6 +58,6 @@ Event: {{ .Event }}
Commit: {{ .Commit }}
Branch: {{ .Branch }}
Ref: {{ .Ref }}
Author: {{ .Author }} {{ if .Email }}<{{.Email}}>{{ end }}
Author: {{ .Author }} {{ if .AuthorEmail }}<{{.AuthorEmail}}>{{ end }}
Message: {{ .Message }}
`

@ -0,0 +1,47 @@
package build
import (
"strconv"
"github.com/drone/drone-cli/drone/internal"
"github.com/urfave/cli"
)
var buildRollbackCmd = cli.Command{
Name: "rollback",
Usage: "rollback a build",
ArgsUsage: "<repo/name> <build> <environment>",
Action: buildRollback,
Flags: []cli.Flag{
cli.StringSliceFlag{
Name: "param, p",
Usage: "custom parameters to be injected into the job environment. Format: KEY=value",
},
},
}
func buildRollback(c *cli.Context) (err error) {
repo := c.Args().First()
owner, name, err := internal.ParseRepo(repo)
if err != nil {
return err
}
number, err := strconv.Atoi(c.Args().Get(1))
if err != nil {
return err
}
target := c.Args().Get(2)
params := internal.ParseKeyPair(c.StringSlice("param"))
client, err := internal.NewClient(c)
if err != nil {
return err
}
_, err = client.Rollback(owner, name, number, target, params)
if err != nil {
return err
}
return nil
}

@ -10,8 +10,8 @@ import (
)
var buildStartCmd = cli.Command{
Name: "start",
Usage: "start a build",
Name: "restart",
Usage: "restart a build",
ArgsUsage: "<repo/name> [build]",
Action: buildStart,
Flags: []cli.Flag{
@ -42,7 +42,7 @@ func buildStart(c *cli.Context) (err error) {
if err != nil {
return err
}
number = build.Number
number = int(build.Number)
} else {
if len(buildArg) == 0 {
return errors.New("missing job number")
@ -55,7 +55,7 @@ func buildStart(c *cli.Context) (err error) {
params := internal.ParseKeyPair(c.StringSlice("param"))
build, err := client.BuildStart(owner, name, number, params)
build, err := client.BuildRestart(owner, name, number, params)
if err != nil {
return err
}

@ -11,7 +11,7 @@ import (
var buildStopCmd = cli.Command{
Name: "stop",
Usage: "stop a build",
ArgsUsage: "<repo/name> [build] [job]",
ArgsUsage: "<repo/name> [build]",
Action: buildStop,
}
@ -25,21 +25,17 @@ func buildStop(c *cli.Context) (err error) {
if err != nil {
return err
}
job, _ := strconv.Atoi(c.Args().Get(2))
if job == 0 {
job = 1
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
err = client.BuildStop(owner, name, number, job)
err = client.BuildCancel(owner, name, number)
if err != nil {
return err
}
fmt.Printf("Stopping build %s/%s#%d.%d\n", owner, name, number, job)
fmt.Printf("Stopping build %s/%s#%d\n", owner, name, number)
return nil
}

@ -7,9 +7,9 @@ var Command = cli.Command{
Name: "cron",
Usage: "manage cron jobs",
Subcommands: []cli.Command{
cronCreateCmd,
cronDeleteCmd,
cronInfoCmd,
cronListCmd,
cronInfoCmd,
cronDisableCmd,
cronEnableCmd,
},
}

@ -1,44 +0,0 @@
package cron
import (
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/urfave/cli"
)
var cronCreateCmd = cli.Command{
Name: "add",
Usage: "adds a cronjob",
ArgsUsage: "[repo/name]",
Action: cronCreate,
Flags: []cli.Flag{
cli.StringFlag{
Name: "branch",
Usage: "branch name",
Value: "master",
},
},
}
func cronCreate(c *cli.Context) error {
slug := c.Args().First()
owner, name, err := internal.ParseRepo(slug)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
cron := &drone.Cron{
Name: c.Args().Get(1),
Expr: c.Args().Get(2),
Branch: c.String("branch"),
}
_, err = client.CronCreate(owner, name, cron)
if err != nil {
return err
}
return nil
}

@ -0,0 +1,28 @@
package cron
import (
"github.com/drone/drone-cli/drone/internal"
"github.com/urfave/cli"
)
var cronDisableCmd = cli.Command{
Name: "disable",
Usage: "disable cron jobs",
ArgsUsage: "[repo/name]",
Action: cronDisable,
}
func cronDisable(c *cli.Context) error {
slug := c.Args().First()
owner, name, err := internal.ParseRepo(slug)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
cronjob := c.Args().Get(1)
return client.CronDisable(owner, name, cronjob)
}

@ -6,14 +6,14 @@ import (
"github.com/urfave/cli"
)
var cronDeleteCmd = cli.Command{
Name: "rm",
Usage: "display cron rm",
var cronEnableCmd = cli.Command{
Name: "enable",
Usage: "enable cron jobs",
ArgsUsage: "[repo/name]",
Action: cronDelete,
Action: cronEnable,
}
func cronDelete(c *cli.Context) error {
func cronEnable(c *cli.Context) error {
slug := c.Args().First()
owner, name, err := internal.ParseRepo(slug)
if err != nil {
@ -24,5 +24,5 @@ func cronDelete(c *cli.Context) error {
return err
}
cronjob := c.Args().Get(1)
return client.CronDelete(owner, name, cronjob)
return client.CronDisable(owner, name, cronjob)
}

@ -1,125 +0,0 @@
package deploy
import (
"fmt"
"html/template"
"os"
"strconv"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/urfave/cli"
)
// Command exports the deploy command.
var Command = cli.Command{
Name: "deploy",
Usage: "deploy code",
ArgsUsage: "<repo/name> <build> <environment>",
Action: deploy,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplDeployInfo,
},
cli.StringFlag{
Name: "branch",
Usage: "branch filter",
Value: "master",
},
cli.StringFlag{
Name: "event",
Usage: "event filter",
Value: drone.EventPush,
},
cli.StringFlag{
Name: "status",
Usage: "status filter",
Value: drone.StatusSuccess,
},
cli.StringSliceFlag{
Name: "param, p",
Usage: "custom parameters to be injected into the job environment. Format: KEY=value",
},
},
}
func deploy(c *cli.Context) error {
repo := c.Args().First()
owner, name, err := internal.ParseRepo(repo)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
branch := c.String("branch")
event := c.String("event")
status := c.String("status")
buildArg := c.Args().Get(1)
var number int
if buildArg == "last" {
// Fetch the build number from the last build
builds, berr := client.BuildList(owner, name)
if berr != nil {
return berr
}
for _, build := range builds {
if branch != "" && build.Branch != branch {
continue
}
if event != "" && build.Event != event {
continue
}
if status != "" && build.Status != status {
continue
}
if build.Number > number {
number = build.Number
}
}
if number == 0 {
return fmt.Errorf("Cannot deploy failure build.")
}
} else {
number, err = strconv.Atoi(buildArg)
if err != nil {
return err
}
}
env := c.Args().Get(2)
if env == "" {
return fmt.Errorf("Error: Please specify the target environment (e.g. production).")
}
params := internal.ParseKeyPair(c.StringSlice("param"))
deploy, err := client.Deploy(owner, name, number, env, params)
if err != nil {
return err
}
tmpl, err := template.New("_").Parse(c.String("format"))
if err != nil {
return err
}
return tmpl.Execute(os.Stdout, deploy)
}
// template for deployment information
var tmplDeployInfo = `Number: {{ .Number }}
Status: {{ .Status }}
Commit: {{ .Commit }}
Branch: {{ .Branch }}
Ref: {{ .Ref }}
Message: {{ .Message }}
Author: {{ .Author }}
Target: {{ .Deploy }}
`

@ -1,13 +1,59 @@
package encrypt
import "github.com/urfave/cli"
import (
"fmt"
"io/ioutil"
"strings"
// Command exports the build command set.
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/urfave/cli"
)
// Command is an encryption cli.Command
var Command = cli.Command{
Name: "encrypt",
Usage: "encrypt resources",
Subcommands: []cli.Command{
encryptSecretCommand,
encryptRegistryCommand,
Name: "encrypt",
Usage: "encrypt a secret",
ArgsUsage: "<repo/name> <string>",
Action: encryptSecret,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "allow-pull-request",
Usage: "permit access to pull requests",
},
},
}
func encryptSecret(c *cli.Context) error {
repo := c.Args().First()
owner, name, err := internal.ParseRepo(repo)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
plaintext := c.Args().Get(1)
if strings.HasPrefix(plaintext, "@") {
data, err := ioutil.ReadFile(plaintext)
if err != nil {
return err
}
plaintext = string(data)
}
secret := &drone.Secret{
Data: plaintext,
Pull: c.Bool("allow-pull-request"),
}
encrypted, err := client.Encrypt(owner, name, secret)
if err != nil {
return err
}
fmt.Println(encrypted)
return nil
}

@ -1,77 +1,77 @@
package encrypt
import (
"fmt"
"io/ioutil"
"strings"
// import (
// "fmt"
// "io/ioutil"
// "strings"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
// "github.com/drone/drone-cli/drone/internal"
// "github.com/drone/drone-go/drone"
"github.com/urfave/cli"
)
// "github.com/urfave/cli"
// )
var encryptRegistryCommand = cli.Command{
Name: "registry",
Usage: "encrypt registry credentials",
ArgsUsage: "<repo/name> <string>",
Action: encryptRegistry,
Flags: []cli.Flag{
cli.StringFlag{
Name: "username",
Usage: "registry username",
},
cli.StringFlag{
Name: "password",
Usage: "registry password",
},
cli.StringFlag{
Name: "server",
Usage: "registry server",
Value: "docker.io",
},
},
}
// var encryptRegistryCommand = cli.Command{
// Name: "registry",
// Usage: "encrypt registry credentials",
// ArgsUsage: "<repo/name> <string>",
// Action: encryptRegistry,
// Flags: []cli.Flag{
// cli.StringFlag{
// Name: "username",
// Usage: "registry username",
// },
// cli.StringFlag{
// Name: "password",
// Usage: "registry password",
// },
// cli.StringFlag{
// Name: "server",
// Usage: "registry server",
// Value: "docker.io",
// },
// },
// }
func encryptRegistry(c *cli.Context) error {
repo := c.Args().First()
owner, name, err := internal.ParseRepo(repo)
if err != nil {
return err
}
// func encryptRegistry(c *cli.Context) error {
// repo := c.Args().First()
// owner, name, err := internal.ParseRepo(repo)
// if err != nil {
// return err
// }
client, err := internal.NewClient(c)
if err != nil {
return err
}
// client, err := internal.NewClient(c)
// if err != nil {
// return err
// }
password := c.String("password")
if strings.HasPrefix(password, "@") {
data, err := ioutil.ReadFile(password)
if err != nil {
return err
}
password = string(data)
}
// password := c.String("password")
// if strings.HasPrefix(password, "@") {
// data, err := ioutil.ReadFile(password)
// if err != nil {
// return err
// }
// password = string(data)
// }
policy := "pull"
switch {
case c.Bool("push"):
policy = "push"
case c.Bool("push-pull-request"):
policy = "push-pull-request"
}
// policy := "pull"
// switch {
// case c.Bool("push"):
// policy = "push"
// case c.Bool("push-pull-request"):
// policy = "push-pull-request"
// }
registry := &drone.Registry{
Address: c.String("server"),
Username: c.String("username"),
Password: password,
Policy: policy,
}
encrypted, err := client.EncryptRegistry(owner, name, registry)
if err != nil {
return err
}
fmt.Println(encrypted)
return nil
}
// registry := &drone.Registry{
// Address: c.String("server"),
// Username: c.String("username"),
// Password: password,
// Policy: policy,
// }
// encrypted, err := client.EncryptRegistry(owner, name, registry)
// if err != nil {
// return err
// }
// fmt.Println(encrypted)
// return nil
// }

@ -1,58 +0,0 @@
package encrypt
import (
"fmt"
"io/ioutil"
"strings"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/urfave/cli"
)
var encryptSecretCommand = cli.Command{
Name: "secret",
Usage: "encrypt a secret",
ArgsUsage: "<repo/name> <string>",
Action: encryptSecret,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "allow-pull-request",
Usage: "permit access to pull requests",
},
},
}
func encryptSecret(c *cli.Context) error {
repo := c.Args().First()
owner, name, err := internal.ParseRepo(repo)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
plaintext := c.Args().Get(1)
if strings.HasPrefix(plaintext, "@") {
data, err := ioutil.ReadFile(plaintext)
if err != nil {
return err
}
plaintext = string(data)
}
secret := &drone.Secret{
Data: plaintext,
Pull: c.Bool("allow-pull-request"),
}
encrypted, err := client.EncryptSecret(owner, name, secret)
if err != nil {
return err
}
fmt.Println(encrypted)
return nil
}

@ -1,3 +0,0 @@
{
v1:: import 'v1/v1.libsonnet',
}

@ -1,7 +0,0 @@
{
new(
name
):: {
name: name,
},
}

@ -1,13 +0,0 @@
{
new(
os='linux',
arch='amd64',
variant=null,
kernel=null
):: {
os: os,
arch: arch,
[if kernel != null then 'kernel']: kernel,
[if variant != null then 'variant']: variant,
},
}

@ -1,12 +0,0 @@
{
new(
name,
external=null,
secretbox=null
):: {
[name]: {
[if external != null then 'external']: external,
[if secretbox != null then 'secretbox']: secretbox,
},
},
}

@ -1,23 +0,0 @@
{
new(
image,
commands=[],
detach=false,
environment=[],
group='',
secrets=[],
when=null,
pull=true,
):: {
image: image,
[if commands != [] then 'commands']: commands,
[if detach == true then 'detach']: true,
[if environment != [] then 'environment']: environment,
[if group != '' then 'group']: group,
[if secrets != [] then 'secrets']: secrets,
[if when != null then 'when']: when,
[if pull == true then 'pull']: pull,
with(params):: self + params,
},
}

@ -1,6 +0,0 @@
{
metadata:: import 'metadata.libsonnet',
platform:: import 'platform.libsonnet',
secrets:: import 'secrets.libsonnet',
step:: import 'step.libsonnet',
}

@ -1,66 +0,0 @@
// +build ignore
package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
func main() {
var files []string
err := filepath.Walk("files", func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
if filepath.Ext(path) == ".libsonnet" {
files = append(files, path)
}
return nil
})
if err != nil {
log.Fatal(err)
}
buf := new(bytes.Buffer)
buf.WriteString("package stdlib\n\n")
buf.WriteString("import jsonnet \"github.com/google/go-jsonnet\"\n\n")
buf.WriteString("var files = map[string]jsonnet.Contents{\n")
for _, file := range files {
raw, err := ioutil.ReadFile(file)
if err != nil {
log.Fatal(err)
}
fmt.Fprintf(buf, "\t%q:jsonnet.MakeContents(%q),\n", strings.TrimPrefix(file, "files/"), string(raw))
}
buf.WriteString("}\n")
formatted, err := format(buf)
if err != nil {
log.Fatal(err)
}
data, err := ioutil.ReadAll(formatted)
if err != nil {
log.Fatal(err)
}
ioutil.WriteFile("stdlib_gen.go", data, 0644)
}
// format formats a template using gofmt.
func format(in io.Reader) (io.Reader, error) {
var out bytes.Buffer
gofmt := exec.Command("gofmt", "-s")
gofmt.Stdin = in
gofmt.Stdout = &out
gofmt.Stderr = os.Stderr
err := gofmt.Run()
return &out, err
}

@ -1,30 +0,0 @@
package stdlib
import (
"path"
jsonnet "github.com/google/go-jsonnet"
)
//go:generate go run gen.go
// Importer provides a default importer that automatically
// loads the embedded drone standard library.
func Importer() jsonnet.Importer {
return &importer{
base: &jsonnet.FileImporter{},
}
}
type importer struct {
base jsonnet.Importer
}
func (i *importer) Import(importedFrom, importedPath string) (contents jsonnet.Contents, foundAt string, err error) {
dir, _ := path.Split(importedFrom)
path := path.Join(dir, importedPath)
if contents, ok := files[path]; ok {
return contents, path, nil
}
return i.base.Import(importedFrom, importedPath)
}

@ -1,12 +0,0 @@
package stdlib
import jsonnet "github.com/google/go-jsonnet"
var files = map[string]jsonnet.Contents{
"drone.libsonnet": jsonnet.MakeContents("{\n v1:: import 'v1/v1.libsonnet',\n}"),
"v1/metadata.libsonnet": jsonnet.MakeContents("{\n new(\n name\n ):: {\n name: name,\n },\n}"),
"v1/platform.libsonnet": jsonnet.MakeContents("{\n new(\n os='linux',\n arch='amd64',\n variant=null,\n kernel=null\n ):: {\n os: os,\n arch: arch,\n [if kernel != null then 'kernel']: kernel,\n [if variant != null then 'variant']: variant,\n },\n}"),
"v1/secrets.libsonnet": jsonnet.MakeContents("{\n new(\n name,\n external=null,\n secretbox=null\n ):: {\n [name]: {\n [if external != null then 'external']: external,\n [if secretbox != null then 'secretbox']: secretbox,\n },\n },\n}"),
"v1/step.libsonnet": jsonnet.MakeContents("{\n new(\n image,\n commands=[],\n detach=false,\n environment=[],\n group='',\n secrets=[],\n when=null,\n pull=true,\n ):: {\n image: image,\n [if commands != [] then 'commands']: commands,\n [if detach == true then 'detach']: true,\n [if environment != [] then 'environment']: environment,\n [if group != '' then 'group']: group,\n [if secrets != [] then 'secrets']: secrets,\n [if when != null then 'when']: when,\n [if pull == true then 'pull']: pull,\n\n with(params):: self + params,\n },\n}"),
"v1/v1.libsonnet": jsonnet.MakeContents("{\n metadata:: import 'metadata.libsonnet',\n platform:: import 'platform.libsonnet',\n secrets:: import 'secrets.libsonnet',\n step:: import 'step.libsonnet',\n}\n"),
}

@ -8,5 +8,6 @@ var Command = cli.Command{
Usage: "manage logs",
Subcommands: []cli.Command{
logPurgeCmd,
logViewCmd,
},
}

@ -11,7 +11,7 @@ import (
var logPurgeCmd = cli.Command{
Name: "purge",
Usage: "purge a log",
ArgsUsage: "<repo/name> <build>",
ArgsUsage: "<repo/name> <build> <stage> <step>",
Action: logPurge,
}
@ -25,13 +25,21 @@ func logPurge(c *cli.Context) (err error) {
if err != nil {
return err
}
stage, err := strconv.Atoi(c.Args().Get(2))
if err != nil {
return err
}
step, err := strconv.Atoi(c.Args().Get(3))
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
err = client.LogsPurge(owner, name, number)
err = client.LogsPurge(owner, name, number, stage, step)
if err != nil {
return err
}

50
drone/log/log_view.go Normal file

@ -0,0 +1,50 @@
package log
import (
"strconv"
"github.com/drone/drone-cli/drone/internal"
"github.com/urfave/cli"
)
var logViewCmd = cli.Command{
Name: "view",
Usage: "display the step logs",
ArgsUsage: "<repo/name> <build> <stage> <step>",
Action: logView,
}
func logView(c *cli.Context) (err error) {
repo := c.Args().First()
owner, name, err := internal.ParseRepo(repo)
if err != nil {
return err
}
number, err := strconv.Atoi(c.Args().Get(1))
if err != nil {
return err
}
stage, err := strconv.Atoi(c.Args().Get(2))
if err != nil {
return err
}
step, err := strconv.Atoi(c.Args().Get(3))
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
lines, err := client.Logs(owner, name, number, stage, step)
if err != nil {
return err
}
for _, line := range lines {
print(line.Message)
}
return nil
}

@ -7,7 +7,6 @@ import (
"github.com/drone/drone-cli/drone/autoscale"
"github.com/drone/drone-cli/drone/build"
"github.com/drone/drone-cli/drone/cron"
"github.com/drone/drone-cli/drone/deploy"
"github.com/drone/drone-cli/drone/encrypt"
"github.com/drone/drone-cli/drone/exec"
"github.com/drone/drone-cli/drone/format"
@ -15,9 +14,7 @@ import (
"github.com/drone/drone-cli/drone/jsonnet"
"github.com/drone/drone-cli/drone/log"
"github.com/drone/drone-cli/drone/plugins"
"github.com/drone/drone-cli/drone/registry"
"github.com/drone/drone-cli/drone/repo"
"github.com/drone/drone-cli/drone/secret"
"github.com/drone/drone-cli/drone/server"
"github.com/drone/drone-cli/drone/sign"
"github.com/drone/drone-cli/drone/user"
@ -75,12 +72,9 @@ func main() {
build.Command,
cron.Command,
log.Command,
deploy.Command,
encrypt.Command,
exec.Command,
info.Command,
registry.Command,
secret.Command,
repo.Command,
user.Command,
server.Command,

@ -105,7 +105,7 @@ func secretFind(c *cli.Context) error {
if err != nil {
return err
}
println(res.Name)
println(req.Name)
println(res.Data)
return nil
}

@ -1,16 +0,0 @@
package registry
import "github.com/urfave/cli"
// Command exports the registry command set.
var Command = cli.Command{
Name: "registry",
Usage: "manage registries",
Subcommands: []cli.Command{
registryCreateCmd,
registryDeleteCmd,
registryUpdateCmd,
registryInfoCmd,
registryListCmd,
},
}

@ -1,75 +0,0 @@
package registry
import (
"io/ioutil"
"strings"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/urfave/cli"
)
var registryCreateCmd = cli.Command{
Name: "add",
Usage: "adds a registry",
ArgsUsage: "[repo/name]",
Action: registryCreate,
Flags: []cli.Flag{
cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
cli.StringFlag{
Name: "hostname",
Usage: "registry hostname",
Value: "docker.io",
},
cli.StringFlag{
Name: "username",
Usage: "registry username",
},
cli.StringFlag{
Name: "password",
Usage: "registry password",
},
},
}
func registryCreate(c *cli.Context) error {
var (
hostname = c.String("hostname")
username = c.String("username")
password = c.String("password")
reponame = c.String("repository")
)
if reponame == "" {
reponame = c.Args().First()
}
owner, name, err := internal.ParseRepo(reponame)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
registry := &drone.Registry{
Address: hostname,
Username: username,
Password: password,
}
if strings.HasPrefix(registry.Password, "@") {
path := strings.TrimPrefix(registry.Password, "@")
out, ferr := ioutil.ReadFile(path)
if ferr != nil {
return ferr
}
registry.Password = string(out)
}
_, err = client.RegistryCreate(owner, name, registry)
if err != nil {
return err
}
return nil
}

@ -1,62 +0,0 @@
package registry
import (
"html/template"
"os"
"github.com/drone/drone-cli/drone/internal"
"github.com/urfave/cli"
)
var registryInfoCmd = cli.Command{
Name: "info",
Usage: "display registry info",
ArgsUsage: "[repo/name]",
Action: registryInfo,
Flags: []cli.Flag{
cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
cli.StringFlag{
Name: "hostname",
Usage: "registry hostname",
Value: "docker.io",
},
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplRegistryList,
Hidden: true,
},
},
}
func registryInfo(c *cli.Context) error {
var (
hostname = c.String("hostname")
reponame = c.String("repository")
format = c.String("format") + "\n"
)
if reponame == "" {
reponame = c.Args().First()
}
owner, name, err := internal.ParseRepo(reponame)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
registry, err := client.Registry(owner, name, hostname)
if err != nil {
return err
}
tmpl, err := template.New("_").Parse(format)
if err != nil {
return err
}
return tmpl.Execute(os.Stdout, registry)
}

@ -1,65 +0,0 @@
package registry
import (
"html/template"
"os"
"github.com/urfave/cli"
"github.com/drone/drone-cli/drone/internal"
)
var registryListCmd = cli.Command{
Name: "ls",
Usage: "list registries",
ArgsUsage: "[repo/name]",
Action: registryList,
Flags: []cli.Flag{
cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplRegistryList,
Hidden: true,
},
},
}
func registryList(c *cli.Context) error {
var (
format = c.String("format") + "\n"
reponame = c.String("repository")
)
if reponame == "" {
reponame = c.Args().First()
}
owner, name, err := internal.ParseRepo(reponame)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
list, err := client.RegistryList(owner, name)
if err != nil {
return err
}
tmpl, err := template.New("_").Parse(format)
if err != nil {
return err
}
for _, registry := range list {
tmpl.Execute(os.Stdout, registry)
}
return nil
}
// template for build list information
var tmplRegistryList = "\x1b[33m{{ .Address }} \x1b[0m" + `
Username: {{ .Username }}
Email: {{ .Email }}
`

@ -1,44 +0,0 @@
package registry
import (
"github.com/drone/drone-cli/drone/internal"
"github.com/urfave/cli"
)
var registryDeleteCmd = cli.Command{
Name: "rm",
Usage: "remove a registry",
ArgsUsage: "[repo/name]",
Action: registryDelete,
Flags: []cli.Flag{
cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
cli.StringFlag{
Name: "hostname",
Usage: "registry hostname",
Value: "docker.io",
},
},
}
func registryDelete(c *cli.Context) error {
var (
hostname = c.String("hostname")
reponame = c.String("repository")
)
if reponame == "" {
reponame = c.Args().First()
}
owner, name, err := internal.ParseRepo(reponame)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
return client.RegistryDelete(owner, name, hostname)
}

@ -1,75 +0,0 @@
package registry
import (
"io/ioutil"
"strings"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/urfave/cli"
)
var registryUpdateCmd = cli.Command{
Name: "update",
Usage: "update a registry",
ArgsUsage: "[repo/name]",
Action: registryUpdate,
Flags: []cli.Flag{
cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
cli.StringFlag{
Name: "hostname",
Usage: "registry hostname",
Value: "docker.io",
},
cli.StringFlag{
Name: "username",
Usage: "registry username",
},
cli.StringFlag{
Name: "password",
Usage: "registry password",
},
},
}
func registryUpdate(c *cli.Context) error {
var (
hostname = c.String("hostname")
username = c.String("username")
password = c.String("password")
reponame = c.String("repository")
)
if reponame == "" {
reponame = c.Args().First()
}
owner, name, err := internal.ParseRepo(reponame)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
registry := &drone.Registry{
Address: hostname,
Username: username,
Password: password,
}
if strings.HasPrefix(registry.Password, "@") {
path := strings.TrimPrefix(registry.Password, "@")
out, ferr := ioutil.ReadFile(path)
if ferr != nil {
return ferr
}
registry.Password = string(out)
}
_, err = client.RegistryUpdate(owner, name, registry)
if err != nil {
return err
}
return nil
}

@ -8,8 +8,8 @@ import (
)
var repoAddCmd = cli.Command{
Name: "add",
Usage: "add a repository",
Name: "enable",
Usage: "enable a repository",
ArgsUsage: "<repo/name>",
Action: repoAdd,
}
@ -26,7 +26,7 @@ func repoAdd(c *cli.Context) error {
return err
}
if _, err := client.RepoPost(owner, name); err != nil {
if _, err := client.RepoEnable(owner, name); err != nil {
return err
}
fmt.Printf("Successfully activated repository %s/%s\n", owner, name)

@ -47,13 +47,12 @@ func repoInfo(c *cli.Context) error {
}
// template for repo information
var tmplRepoInfo = `Owner: {{ .Owner }}
var tmplRepoInfo = `Owner: {{ .Namespace }}
Repo: {{ .Name }}
Type: {{ .Kind }}
Config: {{ .Config }}
Visibility: {{ .Visibility }}
Private: {{ .IsPrivate }}
Trusted: {{ .IsTrusted }}
Gated: {{ .IsGated }}
Remote: {{ .Clone }}
Private: {{ .Private }}
Trusted: {{ .Trusted }}
Protected: {{ .Protected }}
Remote: {{ .HTTPURL }}
`

@ -44,7 +44,7 @@ func repoList(c *cli.Context) error {
org := c.String("org")
for _, repo := range repos {
if org != "" && org != repo.Owner {
if org != "" && org != repo.Namespace {
continue
}
tmpl.Execute(os.Stdout, repo)
@ -53,4 +53,4 @@ func repoList(c *cli.Context) error {
}
// template for repository list items
var tmplRepoList = `{{ .FullName }}`
var tmplRepoList = `{{ .Slug }}`

@ -9,8 +9,8 @@ import (
)
var repoRemoveCmd = cli.Command{
Name: "rm",
Usage: "remove a repository",
Name: "disable",
Usage: "disable a repository",
ArgsUsage: "<repo/name>",
Action: repoRemove,
}
@ -27,7 +27,7 @@ func repoRemove(c *cli.Context) error {
return err
}
if err := client.RepoDel(owner, name); err != nil {
if err := client.RepoDisable(owner, name); err != nil {
return err
}
fmt.Printf("Successfully removed repository %s/%s\n", owner, name)

@ -28,7 +28,7 @@ func repoSync(c *cli.Context) error {
return err
}
repos, err := client.RepoListOpts(true, true)
repos, err := client.RepoListSync()
if err != nil || len(repos) == 0 {
return err
}
@ -38,11 +38,7 @@ func repoSync(c *cli.Context) error {
return err
}
org := c.String("org")
for _, repo := range repos {
if org != "" && org != repo.Owner {
continue
}
tmpl.Execute(os.Stdout, repo)
}
return nil

@ -21,8 +21,8 @@ var repoUpdateCmd = cli.Command{
Usage: "repository is trusted",
},
cli.BoolFlag{
Name: "gated",
Usage: "repository is gated",
Name: "protected",
Usage: "repository is protected",
},
cli.DurationFlag{
Name: "timeout",
@ -64,17 +64,17 @@ func repoUpdate(c *cli.Context) error {
config = c.String("config")
timeout = c.Duration("timeout")
trusted = c.Bool("trusted")
gated = c.Bool("gated")
protected = c.Bool("protected")
buildCounter = c.Int("build-counter")
unsafe = c.Bool("unsafe")
)
patch := new(drone.RepoPatch)
if c.IsSet("trusted") {
patch.IsTrusted = &trusted
patch.Trusted = &trusted
}
if c.IsSet("gated") {
patch.IsGated = &gated
if c.IsSet("protected") {
patch.Protected = &protected
}
if c.IsSet("timeout") {
v := int64(timeout / time.Minute)
@ -93,10 +93,10 @@ func repoUpdate(c *cli.Context) error {
fmt.Printf("Setting the build counter is an unsafe operation that could put your repository in an inconsistent state. Please use --unsafe to proceed")
}
if c.IsSet("build-counter") && unsafe {
patch.BuildCounter = &buildCounter
patch.Counter = &buildCounter
}
if _, err := client.RepoPatch(owner, name, patch); err != nil {
if _, err := client.RepoUpdate(owner, name, patch); err != nil {
return err
}
fmt.Printf("Successfully updated repository %s/%s\n", owner, name)

@ -1,16 +0,0 @@
package secret
import "github.com/urfave/cli"
// Command exports the secret command.
var Command = cli.Command{
Name: "secret",
Usage: "manage secrets",
Subcommands: []cli.Command{
secretCreateCmd,
secretDeleteCmd,
secretUpdateCmd,
secretInfoCmd,
secretListCmd,
},
}

@ -1,80 +0,0 @@
package secret
import (
"io/ioutil"
"strings"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/urfave/cli"
)
var secretCreateCmd = cli.Command{
Name: "add",
Usage: "adds a secret",
ArgsUsage: "[repo/name]",
Action: secretCreate,
Flags: []cli.Flag{
cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
cli.StringFlag{
Name: "name",
Usage: "secret name",
},
cli.StringFlag{
Name: "value",
Usage: "secret value",
},
cli.StringSliceFlag{
Name: "event",
Usage: "secret limited to these events",
},
cli.StringSliceFlag{
Name: "image",
Usage: "secret limited to these images",
},
},
}
func secretCreate(c *cli.Context) error {
reponame := c.String("repository")
if reponame == "" {
reponame = c.Args().First()
}
owner, name, err := internal.ParseRepo(reponame)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
secret := &drone.Secret{
Name: c.String("name"),
Value: c.String("value"),
Images: c.StringSlice("image"),
Events: c.StringSlice("event"),
}
if len(secret.Events) == 0 {
secret.Events = defaultSecretEvents
}
if strings.HasPrefix(secret.Value, "@") {
path := strings.TrimPrefix(secret.Value, "@")
out, ferr := ioutil.ReadFile(path)
if ferr != nil {
return ferr
}
secret.Value = string(out)
}
_, err = client.SecretCreate(owner, name, secret)
return err
}
var defaultSecretEvents = []string{
drone.EventPush,
drone.EventTag,
drone.EventDeploy,
}

@ -1,61 +0,0 @@
package secret
import (
"html/template"
"os"
"github.com/urfave/cli"
"github.com/drone/drone-cli/drone/internal"
)
var secretInfoCmd = cli.Command{
Name: "info",
Usage: "display secret info",
ArgsUsage: "[repo/name]",
Action: secretInfo,
Flags: []cli.Flag{
cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
cli.StringFlag{
Name: "name",
Usage: "secret name",
},
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplSecretList,
Hidden: true,
},
},
}
func secretInfo(c *cli.Context) error {
var (
secretName = c.String("name")
repoName = c.String("repository")
format = c.String("format") + "\n"
)
if repoName == "" {
repoName = c.Args().First()
}
owner, name, err := internal.ParseRepo(repoName)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
secret, err := client.Secret(owner, name, secretName)
if err != nil {
return err
}
tmpl, err := template.New("_").Funcs(secretFuncMap).Parse(format)
if err != nil {
return err
}
return tmpl.Execute(os.Stdout, secret)
}

@ -1,76 +0,0 @@
package secret
import (
"html/template"
"os"
"strings"
"github.com/urfave/cli"
"github.com/drone/drone-cli/drone/internal"
)
var secretListCmd = cli.Command{
Name: "ls",
Usage: "list secrets",
ArgsUsage: "[repo/name]",
Action: secretList,
Flags: []cli.Flag{
cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplSecretList,
Hidden: true,
},
},
}
func secretList(c *cli.Context) error {
var (
format = c.String("format") + "\n"
reponame = c.String("repository")
)
if reponame == "" {
reponame = c.Args().First()
}
owner, name, err := internal.ParseRepo(reponame)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
list, err := client.SecretList(owner, name)
if err != nil {
return err
}
tmpl, err := template.New("_").Funcs(secretFuncMap).Parse(format)
if err != nil {
return err
}
for _, registry := range list {
tmpl.Execute(os.Stdout, registry)
}
return nil
}
// template for secret list items
var tmplSecretList = "\x1b[33m{{ .Name }} \x1b[0m" + `
Events: {{ list .Events }}
{{- if .Images }}
Images: {{ list .Images }}
{{- else }}
Images: <any>
{{- end }}
`
var secretFuncMap = template.FuncMap{
"list": func(s []string) string {
return strings.Join(s, ", ")
},
}

@ -1,43 +0,0 @@
package secret
import (
"github.com/urfave/cli"
"github.com/drone/drone-cli/drone/internal"
)
var secretDeleteCmd = cli.Command{
Name: "rm",
Usage: "remove a secret",
ArgsUsage: "[repo/name]",
Action: secretDelete,
Flags: []cli.Flag{
cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
cli.StringFlag{
Name: "name",
Usage: "secret name",
},
},
}
func secretDelete(c *cli.Context) error {
var (
secret = c.String("name")
reponame = c.String("repository")
)
if reponame == "" {
reponame = c.Args().First()
}
owner, name, err := internal.ParseRepo(reponame)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
return client.SecretDelete(owner, name, secret)
}

@ -1,71 +0,0 @@
package secret
import (
"io/ioutil"
"strings"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/urfave/cli"
)
var secretUpdateCmd = cli.Command{
Name: "update",
Usage: "update a secret",
ArgsUsage: "[repo/name]",
Action: secretUpdate,
Flags: []cli.Flag{
cli.StringFlag{
Name: "repository",
Usage: "repository name (e.g. octocat/hello-world)",
},
cli.StringFlag{
Name: "name",
Usage: "secret name",
},
cli.StringFlag{
Name: "value",
Usage: "secret value",
},
cli.StringSliceFlag{
Name: "event",
Usage: "secret limited to these events",
},
cli.StringSliceFlag{
Name: "image",
Usage: "secret limited to these images",
},
},
}
func secretUpdate(c *cli.Context) error {
reponame := c.String("repository")
if reponame == "" {
reponame = c.Args().First()
}
owner, name, err := internal.ParseRepo(reponame)
if err != nil {
return err
}
client, err := internal.NewClient(c)
if err != nil {
return err
}
secret := &drone.Secret{
Name: c.String("name"),
Value: c.String("value"),
Images: c.StringSlice("image"),
Events: c.StringSlice("event"),
}
if strings.HasPrefix(secret.Value, "@") {
path := strings.TrimPrefix(secret.Value, "@")
out, ferr := ioutil.ReadFile(path)
if ferr != nil {
return ferr
}
secret.Value = string(out)
}
_, err = client.SecretUpdate(owner, name, secret)
return err
}

@ -14,6 +14,16 @@ var userAddCmd = cli.Command{
Usage: "adds a user",
ArgsUsage: "<username>",
Action: userAdd,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "admin",
Usage: "admin privileged",
},
cli.BoolFlag{
Name: "machine",
Usage: "machine account",
},
},
}
func userAdd(c *cli.Context) error {
@ -24,7 +34,12 @@ func userAdd(c *cli.Context) error {
return err
}
user, err := client.UserPost(&drone.User{Login: login})
in := &drone.User{
Login: login,
Admin: c.Bool("admin"),
Machine: c.Bool("machine"),
}
user, err := client.UserCreate(in)
if err != nil {
return err
}

@ -49,4 +49,7 @@ func userInfo(c *cli.Context) error {
// template for user information
var tmplUserInfo = `User: {{ .Login }}
Email: {{ .Email }}`
Email: {{ .Email }}
Admin: {{ .Admin }}
Machine: {{ .Machine }}
`

@ -23,7 +23,7 @@ func userRemove(c *cli.Context) error {
return err
}
if err := client.UserDel(login); err != nil {
if err := client.UserDelete(login); err != nil {
return err
}
fmt.Printf("Successfully removed user %s\n", login)

@ -17,7 +17,6 @@ package drone
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
@ -37,11 +36,12 @@ const (
pathRepair = "%s/api/repos/%s/%s/repair"
pathBuilds = "%s/api/repos/%s/%s/builds"
pathBuild = "%s/api/repos/%s/%s/builds/%v"
pathApprove = "%s/api/repos/%s/%s/builds/%d/approve"
pathDecline = "%s/api/repos/%s/%s/builds/%d/decline"
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"
pathJob = "%s/api/repos/%s/%s/builds/%d/%d"
pathLog = "%s/api/repos/%s/%s/logs/%d/%d"
pathLogPurge = "%s/api/repos/%s/%s/logs/%d"
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"
pathRepoRegistries = "%s/api/repos/%s/%s/registry"
@ -54,12 +54,11 @@ const (
pathCron = "%s/api/repos/%s/%s/cron/%s"
pathUsers = "%s/api/users"
pathUser = "%s/api/users/%s"
pathBuildQueue = "%s/api/builds"
pathBuildQueue = "%s/api/system/builds"
pathServers = "%s/api/servers"
pathServer = "%s/api/servers/%s"
pathScalerPause = "%s/api/pause"
pathScalerResume = "%s/api/resume"
pathVarz = "%s/varz"
pathVersion = "%s/version"
)
@ -68,53 +67,6 @@ type client struct {
addr string
}
// // Options provides a list of client options.
// type Options struct {
// token string
// proxy string
// pool *x509.CertPool
// conf *tls.Config
// skip bool
// }
//
// // Option defines client options.
// type Option func(opts *Options)
//
// // WithToken returns an option to set the token.
// func WithToken(token string) Option {
// return func(opts *Options) {
// opts.token = token
// }
// }
//
// // WithTLS returns an option to use custom tls configuration.
// func WithTLS(conf *tls.Config) Option {
// return func(opts *Options) {
// opts.conf = conf
// }
// }
//
// // WithSocks returns a client option to provide a socks5 proxy.
// func WithSocks(proxy string) Option {
// return func(opts *Options) {
// opts.proxy = proxy
// }
// }
//
// // WithSkipVerify returns a client option to skip ssl verification.
// func WithSkipVerify(skip bool) Option {
// return func(opts *Options) {
// opts.skip = skip
// }
// }
//
// // WithCertPool returns a client option to provide a custom cert pool.
// func WithCertPool(pool *x509.CertPool) Option {
// return func(opts *Options) {
// opts.pool = pool
// }
// }
// New returns a client at the specified url.
func New(uri string) Client {
return &client{http.DefaultClient, strings.TrimSuffix(uri, "/")}
@ -159,24 +111,24 @@ func (c *client) UserList() ([]*User, error) {
return out, err
}
// UserPost creates a new user account.
func (c *client) UserPost(in *User) (*User, error) {
// UserCreate creates a new user account.
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
}
// UserPatch updates a user account.
func (c *client) UserPatch(in *User) (*User, error) {
// UserUpdate updates a user account.
func (c *client) UserUpdate(in *User) (*User, error) {
out := new(User)
uri := fmt.Sprintf(pathUser, c.addr, in.Login)
err := c.patch(uri, in, out)
return out, err
}
// UserDel deletes a user account.
func (c *client) UserDel(login string) error {
// UserDelete deletes a user account.
func (c *client) UserDelete(login string) error {
uri := fmt.Sprintf(pathUser, c.addr, login)
err := c.delete(uri)
return err
@ -199,25 +151,40 @@ func (c *client) RepoList() ([]*Repo, error) {
return out, err
}
// RepoListOpts returns a list of all repositories to which
// RepoListSync returns a list of all repositories to which
// the user has explicit access in the host system.
func (c *client) RepoListOpts(sync, all bool) ([]*Repo, error) {
func (c *client) RepoListSync() ([]*Repo, error) {
var out []*Repo
uri := fmt.Sprintf(pathRepos+"?flush=%v&all=%v", c.addr, sync, all)
err := c.get(uri, &out)
uri := fmt.Sprintf(pathRepos, c.addr)
err := c.post(uri, nil, &out)
return out, err
}
// RepoPost activates a repository.
func (c *client) RepoPost(owner string, name string) (*Repo, error) {
// RepoEnable activates a repository.
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
}
// RepoDisable disables a repository.
func (c *client) RepoDisable(owner, name string) error {
uri := fmt.Sprintf(pathRepo, c.addr, owner, name)
err := c.delete(uri)
return err
}
// RepoUpdate updates a repository.
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
}
// RepoChown updates a repository owner.
func (c *client) RepoChown(owner string, name string) (*Repo, error) {
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)
@ -225,32 +192,11 @@ func (c *client) RepoChown(owner string, name string) (*Repo, error) {
}
// RepoRepair repais the repository hooks.
func (c *client) RepoRepair(owner string, name string) error {
func (c *client) RepoRepair(owner, name string) error {
uri := fmt.Sprintf(pathRepair, c.addr, owner, name)
return c.post(uri, nil, nil)
}
// RepoPatch updates a repository.
func (c *client) RepoPatch(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
}
// RepoDel deletes a repository.
func (c *client) RepoDel(owner, name string) error {
uri := fmt.Sprintf(pathRepo, c.addr, owner, name)
err := c.delete(uri)
return err
}
// RepoMove moves a repository
func (c *client) RepoMove(owner, name, newFullName string) error {
uri := fmt.Sprintf(pathRepoMove, c.addr, owner, name, newFullName)
return c.post(uri, nil, nil)
}
// Build returns a repository build by number.
func (c *client) Build(owner, name string, num int) (*Build, error) {
out := new(Build)
@ -280,208 +226,113 @@ func (c *client) BuildList(owner, name string) ([]*Build, error) {
}
// BuildQueue returns a list of enqueued builds.
func (c *client) BuildQueue() ([]*Activity, error) {
var out []*Activity
func (c *client) BuildQueue() ([]*Build, error) {
var out []*Build
uri := fmt.Sprintf(pathBuildQueue, c.addr)
err := c.get(uri, &out)
return out, err
}
// BuildStart re-starts a stopped build.
func (c *client) BuildStart(owner, name string, num int, params map[string]string) (*Build, error) {
// BuildRestart re-starts a stopped build.
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, num)
err := c.post(uri+"?"+val.Encode(), nil, out)
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
}
// BuildStop cancels the running job.
func (c *client) BuildStop(owner, name string, num, job int) error {
uri := fmt.Sprintf(pathJob, c.addr, owner, name, num, job)
// BuildCancel cancels the running job.
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
}
// BuildApprove approves a blocked build.
func (c *client) BuildApprove(owner, name string, num int) (*Build, error) {
// Promote promotes a build to the target environment.
func (c *client) Promote(namespace, name string, build int, target string, params map[string]string) (*Build, error) {
out := new(Build)
uri := fmt.Sprintf(pathApprove, c.addr, owner, name, num)
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
}
// BuildDecline declines a blocked build.
func (c *client) BuildDecline(owner, name string, num int) (*Build, error) {
// Roolback reverts the target environment to an previous build.
func (c *client) Rollback(namespace, name string, build int, target string, params map[string]string) (*Build, error) {
out := new(Build)
uri := fmt.Sprintf(pathDecline, c.addr, owner, name, num)
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
}
// BuildKill force kills the running build.
func (c *client) BuildKill(owner, name string, num int) error {
uri := fmt.Sprintf(pathBuild, c.addr, owner, name, num)
err := c.delete(uri)
// Approve approves a blocked build stage.
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
}
// Decline declines a blocked build stage.
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
}
// BuildLogs returns the build logs for the specified job.
func (c *client) BuildLogs(owner, name string, num, job int) (io.ReadCloser, error) {
return nil, errors.New("Method not implemented")
}
// Deploy triggers a deployment for an existing build using the
// specified target environment.
func (c *client) Deploy(owner, name string, num int, env string, params map[string]string) (*Build, error) {
out := new(Build)
val := mapValues(params)
val.Set("event", "deployment")
val.Set("deploy_to", env)
uri := fmt.Sprintf(pathBuild, c.addr, owner, name, num)
err := c.post(uri+"?"+val.Encode(), nil, out)
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
}
// LogsPurge purges the build logs for the specified build.
func (c *client) LogsPurge(owner, name string, num int) error {
uri := fmt.Sprintf(pathLogPurge, c.addr, owner, name, num)
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
}
// Registry returns a registry by hostname.
func (c *client) Registry(owner, name, hostname string) (*Registry, error) {
out := new(Registry)
uri := fmt.Sprintf(pathRepoRegistry, c.addr, owner, name, hostname)
err := c.get(uri, out)
return out, err
}
// RegistryList returns a list of all repository registries.
func (c *client) RegistryList(owner string, name string) ([]*Registry, error) {
var out []*Registry
uri := fmt.Sprintf(pathRepoRegistries, c.addr, owner, name)
err := c.get(uri, &out)
return out, err
}
// RegistryCreate creates a registry.
func (c *client) RegistryCreate(owner, name string, in *Registry) (*Registry, error) {
out := new(Registry)
uri := fmt.Sprintf(pathRepoRegistries, c.addr, owner, name)
err := c.post(uri, in, out)
return out, err
}
// RegistryUpdate updates a registry.
func (c *client) RegistryUpdate(owner, name string, in *Registry) (*Registry, error) {
out := new(Registry)
uri := fmt.Sprintf(pathRepoRegistry, c.addr, owner, name, in.Address)
err := c.patch(uri, in, out)
return out, err
}
// RegistryDelete deletes a registry.
func (c *client) RegistryDelete(owner, name, hostname string) error {
uri := fmt.Sprintf(pathRepoRegistry, c.addr, owner, name, hostname)
return c.delete(uri)
}
// Secret returns a secret by name.
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
}
// SecretList returns a list of all repository secrets.
func (c *client) SecretList(owner string, name string) ([]*Secret, error) {
var out []*Secret
uri := fmt.Sprintf(pathRepoSecrets, c.addr, owner, name)
err := c.get(uri, &out)
return out, err
}
// SecretCreate creates a secret.
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
}
// SecretUpdate updates a secret.
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
}
// SecretDelete deletes a secret.
func (c *client) SecretDelete(owner, name, secret string) error {
uri := fmt.Sprintf(pathRepoSecret, c.addr, owner, name, secret)
return c.delete(uri)
}
//
// signature
//
type signatureRequest struct {
Data string `json:"data"`
}
type signatureResponse struct {
Data string `json:"data"`
}
// Sign signs the yaml file.
func (c *client) Sign(owner, name, file string) (string, error) {
in := &signatureRequest{Data: file}
out := &signatureResponse{}
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)
err := c.post(uri, &in, &out)
return out.Data, err
}
// Verify verifies the yaml signature.
func (c *client) Verify(owner, name, file string) error {
in := &signatureRequest{Data: file}
in := struct {
Data string `json:"data"`
}{Data: file}
uri := fmt.Sprintf(pathVerify, c.addr, owner, name)
return c.post(uri, in, nil)
return c.post(uri, &in, nil)
}
//
// encryption
//
type encryptResponse struct {
Data string `json:"data"`
}
// EncryptSecret returns an encrypted secret.
func (c *client) EncryptSecret(owner, name string, secret *Secret) (string, error) {
out := &encryptResponse{}
// Encrypt returns an encrypted secret.
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)
err := c.post(uri, secret, &out)
return out.Data, err
}
// EncryptRegistry returns an encrypted registry.
func (c *client) EncryptRegistry(owner, name string, registry *Registry) (string, error) {
out := &encryptResponse{}
uri := fmt.Sprintf(pathEncryptRegistry, c.addr, owner, name)
err := c.post(uri, registry, out)
return out.Data, err
}
//
// cron jobs
//
// Cron returns a cronjob by name.
func (c *client) Cron(owner, name, cron string) (*Cron, error) {
out := new(Cron)
@ -498,18 +349,18 @@ func (c *client) CronList(owner string, name string) ([]*Cron, error) {
return out, err
}
// CronCreate creates a cronjob.
func (c *client) CronCreate(owner, name string, in *Cron) (*Cron, error) {
out := new(Cron)
uri := fmt.Sprintf(pathCrons, c.addr, owner, name)
err := c.post(uri, in, out)
return out, err
// CronEnable ensables a cronjob.
func (c *client) CronEnable(owner, name, cron string) error {
uri := fmt.Sprintf(pathCron, c.addr, owner, name, cron)
err := c.post(uri, nil, nil)
return err
}
// CronDelete deletes a cronjob.
func (c *client) CronDelete(owner, name, cron string) error {
// CronDisable disables a cronjob.
func (c *client) CronDisable(owner, name, cron string) error {
uri := fmt.Sprintf(pathCron, c.addr, owner, name, cron)
return c.delete(uri)
err := c.delete(uri)
return err
}
//
@ -580,11 +431,6 @@ func (c *client) post(rawurl string, in, out interface{}) error {
return c.do(rawurl, "POST", in, out)
}
// helper function for making an http PUT request.
func (c *client) put(rawurl string, in, out interface{}) error {
return c.do(rawurl, "PUT", in, out)
}
// helper function for making an http PATCH request.
func (c *client) patch(rawurl string, in, out interface{}) error {
return c.do(rawurl, "PATCH", in, out)
@ -633,7 +479,7 @@ func (c *client) open(rawurl, method string, in, out interface{}) (io.ReadCloser
if err != nil {
return nil, err
}
if resp.StatusCode > http.StatusPartialContent {
if resp.StatusCode > 299 {
defer resp.Body.Close()
out, _ := ioutil.ReadAll(resp.Body)
return nil, fmt.Errorf("client error %d: %s", resp.StatusCode, string(out))

@ -16,26 +16,23 @@ package drone
// Event values.
const (
EventPush = "push"
EventPull = "pull_request"
EventTag = "tag"
EventDeploy = "deployment"
EventPush = "push"
EventPullRequest = "pull_request"
EventTag = "tag"
EventPromote = "promote"
EventRollback = "rollback"
)
// Status values.
const (
StatusBlocked = "blocked"
StatusSkipped = "skipped"
StatusPending = "pending"
StatusRunning = "running"
StatusSuccess = "success"
StatusFailure = "failure"
StatusKilled = "killed"
StatusError = "error"
)
// Encryption algorithms
const (
EncryptAesgcm = "aesgcm"
EncryptSecretbox = "secretbox"
StatusSkipped = "skipped"
StatusBlocked = "blocked"
StatusDeclined = "declined"
StatusWaiting = "waiting_on_dependencies"
StatusPending = "pending"
StatusRunning = "running"
StatusPassing = "success"
StatusFailing = "failure"
StatusKilled = "killed"
StatusError = "error"
)

@ -14,7 +14,14 @@
package drone
import "net/http"
import (
"net/http"
)
// TODO(bradrydzewski) add repo + latest build endpoint
// TODO(bradrydzewski) add queue endpoint
// TDOO(bradrydzewski) add stats endpoint
// TODO(bradrydzewski) add version endpoint
// Client is used to communicate with a Drone server.
type Client interface {
@ -28,126 +35,84 @@ type Client interface {
Self() (*User, error)
// User returns a user by login.
User(string) (*User, error)
User(login string) (*User, error)
// UserList returns a list of all registered users.
UserList() ([]*User, error)
// UserPost creates a new user account.
UserPost(*User) (*User, error)
// UserCreate creates a new user account.
UserCreate(user *User) (*User, error)
// UserPatch updates a user account.
UserPatch(*User) (*User, error)
// UserUpdate updates a user account.
UserUpdate(user *User) (*User, error)
// UserDel deletes a user account.
UserDel(string) error
// UserDelete deletes a user account.
UserDelete(login string) error
// Repo returns a repository by name.
Repo(string, string) (*Repo, error)
Repo(namespace, name string) (*Repo, error)
// RepoList returns a list of all repositories to which the user has explicit
// access in the host system.
// RepoList returns a list of all repositories to which
// the user has explicit access in the host system.
RepoList() ([]*Repo, error)
// RepoListOpts returns a list of all repositories to which the user has
// explicit access in the host system.
RepoListOpts(bool, bool) ([]*Repo, error)
// RepoListSync returns a list of all repositories to which
// the user has explicit access in the host system.
RepoListSync() ([]*Repo, error)
// RepoPost activates a repository.
RepoPost(string, string) (*Repo, error)
// RepoEnable activates a repository.
RepoEnable(namespace, name string) (*Repo, error)
// RepoPatch updates a repository.
RepoPatch(string, string, *RepoPatch) (*Repo, error)
// RepoMove moves the repository
RepoMove(string, string, string) error
// RepoUpdate updates a repository.
RepoUpdate(namespace, name string, repo *RepoPatch) (*Repo, error)
// RepoChown updates a repository owner.
RepoChown(string, string) (*Repo, error)
RepoChown(namespace, name string) (*Repo, error)
// RepoRepair repairs the repository hooks.
RepoRepair(string, string) error
RepoRepair(namespace, name string) error
// RepoDel deletes a repository.
RepoDel(string, string) error
// RepoDisable disables a repository.
RepoDisable(namespace, name string) error
// Build returns a repository build by number.
Build(string, string, int) (*Build, error)
Build(namespace, name string, build int) (*Build, error)
// BuildLast returns the latest repository build by branch. An empty branch
// will result in the default branch.
BuildLast(string, string, string) (*Build, error)
// BuildLast returns the latest build by branch. An
// empty branch will result in the default branch.
BuildLast(namespace, name, branch string) (*Build, error)
// BuildList returns a list of recent builds for the
// the specified repository.
BuildList(string, string) ([]*Build, error)
BuildList(namespace, name string) ([]*Build, error)
// BuildQueue returns a list of enqueued builds.
BuildQueue() ([]*Activity, error)
BuildQueue() ([]*Build, error)
// BuildStart re-starts a stopped build.
BuildStart(string, string, int, map[string]string) (*Build, error)
// BuildRestart re-starts a build.
BuildRestart(namespace, name string, build int, params map[string]string) (*Build, error)
// BuildStop stops the specified running job for given build.
BuildStop(string, string, int, int) error
// BuildCancel stops the specified running job for
// given build.
BuildCancel(namespace, name string, build int) error
// BuildApprove approves a blocked build.
BuildApprove(string, string, int) (*Build, error)
// Approve approves a blocked build stage.
Approve(namespace, name string, build, stage int) error
// BuildDecline declines a blocked build.
BuildDecline(string, string, int) (*Build, error)
// Decline declines a blocked build stage.
Decline(namespace, name string, build, stage int) error
// BuildKill force kills the running build.
BuildKill(string, string, int) error
// Promote promotes a build to the target environment.
Promote(namespace, name string, build int, target string, params map[string]string) (*Build, error)
// Deploy triggers a deployment for an existing build using the specified
// target environment.
Deploy(string, string, int, string, map[string]string) (*Build, error)
// Rollback reverts the target environment to an previous build.
Rollback(namespace, name string, build int, target string, params map[string]string) (*Build, error)
// LogsPurge purges the build logs for the specified build.
LogsPurge(string, string, int) error
// Logs gets the logs for the specified step.
Logs(owner, name string, build, stage, step int) ([]*Line, error)
// Registry returns a registry by hostname.
Registry(owner, name, hostname string) (*Registry, error)
// RegistryList returns a list of all repository registries.
RegistryList(owner, name string) ([]*Registry, error)
// RegistryCreate creates a registry.
RegistryCreate(owner, name string, registry *Registry) (*Registry, error)
// RegistryUpdate updates a registry.
RegistryUpdate(owner, name string, registry *Registry) (*Registry, error)
// RegistryDelete deletes a registry.
RegistryDelete(owner, name, hostname string) error
// Secret returns a secret by name.
Secret(owner, name, secret string) (*Secret, error)
// SecretList returns a list of all repository secrets.
SecretList(owner, name string) ([]*Secret, error)
// SecretCreate creates a registry.
SecretCreate(owner, name string, secret *Secret) (*Secret, error)
// SecretUpdate updates a registry.
SecretUpdate(owner, name string, secret *Secret) (*Secret, error)
// SecretDelete deletes a secret.
SecretDelete(owner, name, secret string) error
// Sign signs the yaml file.
Sign(owner, name, file string) (string, error)
// Verify verifies the yaml signature.
Verify(owner, name, file string) error
// EncryptSecret returns an encrypted secret
EncryptSecret(owner, name string, secret *Secret) (string, error)
// EncryptRegistry returns an encrypted secret
EncryptRegistry(owner, name string, registry *Registry) (string, error)
// LogsPurge purges the build logs for the specified step.
LogsPurge(owner, name string, build, stage, step int) error
// Cron returns a cronjob by name.
Cron(owner, name, cron string) (*Cron, error)
@ -155,11 +120,24 @@ type Client interface {
// CronList returns a list of all repository cronjobs.
CronList(owner string, name string) ([]*Cron, error)
// CronCreate creates a cronjob.
CronCreate(owner, name string, in *Cron) (*Cron, error)
// CronEnable enables a cronjob.
CronEnable(owner, name, cron string) error
// CronDelete deletes a cronjob.
CronDelete(owner, name, cron string) error
// CronDisable disables a cronjob.
CronDisable(owner, name, cron string) error
// Sign signs the yaml file.
Sign(owner, name, file string) (string, error)
// Verify verifies the yaml signature.
Verify(owner, name, file string) error
// Encrypt returns an encrypted secret
Encrypt(owner, name string, secret *Secret) (string, error)
//
// Move to autoscaler-go
//
// Server returns the named servers details.
Server(name string) (*Server, error)

@ -17,173 +17,177 @@ package drone
type (
// User represents a user account.
User struct {
ID int64 `json:"id"`
Login string `json:"login"`
Email string `json:"email"`
Avatar string `json:"avatar_url"`
Active bool `json:"active"`
Admin bool `json:"admin"`
ID int64 `json:"id"`
Login string `json:"login"`
Email string `json:"email"`
Avatar string `json:"avatar_url"`
Active bool `json:"active"`
Admin bool `json:"admin"`
Machine bool `json:"machine"`
Syncing bool `json:"syncing"`
Synced int64 `json:"synced"`
Created int64 `json:"created"`
Updated int64 `json:"updated"`
LastLogin int64 `json:"last_login"`
}
// Repo represents a repository.
Repo struct {
ID int64 `json:"id,omitempty"`
Owner string `json:"owner"`
FullName string `json:"full_name"`
Avatar string `json:"avatar_url,omitempty"`
Link string `json:"link_url,omitempty"`
Kind string `json:"scm,omitempty"`
Clone string `json:"clone_url,omitempty"`
Branch string `json:"default_branch,omitempty"`
Timeout int64 `json:"timeout,omitempty"`
Visibility string `json:"visibility"`
IsPrivate bool `json:"private,omitempty"`
IsTrusted bool `json:"trusted"`
IsStarred bool `json:"starred,omitempty"`
IsGated bool `json:"gated"`
AllowPull bool `json:"allow_pr"`
AllowPush bool `json:"allow_push"`
AllowDeploy bool `json:"allow_deploys"`
AllowTag bool `json:"allow_tags"`
Config string `json:"config_file"`
//
// fields added in 0.9
//
Namespace string `json:"namespace"`
Name string `json:"name"`
Slug string `json:"slug"`
ID int64 `json:"id"`
UID string `json:"uid"`
UserID int64 `json:"user_id"`
Namespace string `json:"namespace"`
Name string `json:"name"`
Slug string `json:"slug"`
SCM string `json:"scm"`
HTTPURL string `json:"git_http_url"`
SSHURL string `json:"git_ssh_url"`
Link string `json:"link"`
Branch string `json:"default_branch"`
Private bool `json:"private"`
Visibility string `json:"visibility"`
Active bool `json:"active"`
Config string `json:"config_path"`
Trusted bool `json:"trusted"`
Protected bool `json:"protected"`
Timeout int64 `json:"timeout"`
Counter int64 `json:"counter"`
Synced int64 `json:"synced"`
Created int64 `json:"created"`
Updated int64 `json:"updated"`
Version int64 `json:"version"`
}
// RepoPatch defines a repository patch request.
RepoPatch struct {
Config *string `json:"config_file,omitempty"`
IsTrusted *bool `json:"trusted,omitempty"`
IsGated *bool `json:"gated,omitempty"`
Timeout *int64 `json:"timeout,omitempty"`
Visibility *string `json:"visibility"`
AllowPull *bool `json:"allow_pr,omitempty"`
AllowPush *bool `json:"allow_push,omitempty"`
AllowDeploy *bool `json:"allow_deploy,omitempty"`
AllowTag *bool `json:"allow_tag,omitempty"`
BuildCounter *int `json:"build_counter,omitempty"`
Config *string `json:"config_path,omitempty"`
Protected *bool `json:"protected,omitempty"`
Trusted *bool `json:"trusted,omitempty"`
Timeout *int64 `json:"timeout,omitempty"`
Visibility *string `json:"visibility,omitempty"`
Counter *int `json:"counter,omitempty"`
}
// Build defines a build object.
Build struct {
ID int64 `json:"id"`
Number int `json:"number"`
Parent int `json:"parent"`
Event string `json:"event"`
Status string `json:"status"`
Error string `json:"error"`
Enqueued int64 `json:"enqueued_at"`
Created int64 `json:"created_at"`
Started int64 `json:"started_at"`
Finished int64 `json:"finished_at"`
Deploy string `json:"deploy_to"`
Commit string `json:"commit"`
Branch string `json:"branch"`
Ref string `json:"ref"`
Refspec string `json:"refspec"`
Remote string `json:"remote"`
Title string `json:"title"`
Message string `json:"message"`
Timestamp int64 `json:"timestamp"`
Sender string `json:"sender"`
Author string `json:"author"`
Avatar string `json:"author_avatar"`
Email string `json:"author_email"`
Link string `json:"link_url"`
Reviewer string `json:"reviewed_by"`
Reviewed int64 `json:"reviewed_at"`
Procs []*Proc `json:"procs,omitempty"`
//
// fields added in 0.9
//
Before string `json:"before"`
After string `json:"after"`
Source string `json:"source"`
Target string `json:"target"`
Fork string `json:"fork"`
ID int64 `json:"id"`
RepoID int64 `json:"repo_id"`
Trigger string `json:"trigger"`
Number int64 `json:"number"`
Parent int64 `json:"parent,omitempty"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
Event string `json:"event"`
Action string `json:"action"`
Link string `json:"link"`
Timestamp int64 `json:"timestamp"`
Title string `json:"title,omitempty"`
Message string `json:"message"`
Before string `json:"before"`
After string `json:"after"`
Ref string `json:"ref"`
Fork string `json:"source_repo"`
Source string `json:"source"`
Target string `json:"target"`
Author string `json:"author_login"`
AuthorName string `json:"author_name"`
AuthorEmail string `json:"author_email"`
AuthorAvatar string `json:"author_avatar"`
Sender string `json:"sender"`
Params map[string]string `json:"params,omitempty"`
Deploy string `json:"deploy_to,omitempty"`
Started int64 `json:"started"`
Finished int64 `json:"finished"`
Created int64 `json:"created"`
Updated int64 `json:"updated"`
Version int64 `json:"version"`
Stages []*Stage `json:"stages,omitempty"`
}
// Proc represents a process in the build pipeline.
Proc struct {
ID int64 `json:"id"`
PID int `json:"pid"`
PPID int `json:"ppid"`
PGID int `json:"pgid"`
Name string `json:"name"`
State string `json:"state"`
Error string `json:"error,omitempty"`
ExitCode int `json:"exit_code"`
Started int64 `json:"start_time,omitempty"`
Stopped int64 `json:"end_time,omitempty"`
Machine string `json:"machine,omitempty"`
Platform string `json:"platform,omitempty"`
Environ map[string]string `json:"environ,omitempty"`
Children []*Proc `json:"children,omitempty"`
// Stage represents a stage of build execution.
Stage struct {
ID int64 `json:"id"`
BuildID int64 `json:"build_id"`
Number int `json:"number"`
Name string `json:"name"`
Kind string `json:"kind,omitempty"`
Type string `json:"type,omitempty"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
ErrIgnore bool `json:"errignore"`
ExitCode int `json:"exit_code"`
Machine string `json:"machine,omitempty"`
OS string `json:"os"`
Arch string `json:"arch"`
Variant string `json:"variant,omitempty"`
Kernel string `json:"kernel,omitempty"`
Started int64 `json:"started"`
Stopped int64 `json:"stopped"`
Created int64 `json:"created"`
Updated int64 `json:"updated"`
Version int64 `json:"version"`
OnSuccess bool `json:"on_success"`
OnFailure bool `json:"on_failure"`
DependsOn []string `json:"depends_on,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Steps []*Step `json:"steps,omitempty"`
}
// Step represents an individual step in the stage.
Step struct {
ID int64 `json:"id"`
StageID int64 `json:"step_id"`
Number int `json:"number"`
Name string `json:"name"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
ErrIgnore bool `json:"errignore,omitempty"`
ExitCode int `json:"exit_code"`
Started int64 `json:"started,omitempty"`
Stopped int64 `json:"stopped,omitempty"`
Version int64 `json:"version"`
}
// DEPRECATED
// Registry represents a docker registry with credentials.
Registry struct {
ID int64 `json:"id"`
Address string `json:"address"`
Username string `json:"username"`
Password string `json:"password,omitempty"`
Email string `json:"email"`
Token string `json:"token"`
//
// fields added in 0.9
//
Policy string `json:"policy,omitempty"`
Policy string `json:"policy,omitempty"`
}
// Secret represents a secret variable, such as a password or token.
Secret struct {
ID int64 `json:"id"`
Name string `json:"name"`
Value string `json:"value,omitempty"`
Images []string `json:"image"`
Events []string `json:"event"`
//
// fields added in 0.9
//
Data string `json:"data,omitempty"`
Pull bool `json:"pull,omitempty"`
Fork bool `json:"fork,omitempty"`
}
// Activity represents an item in the user's feed or timeline.
Activity struct {
Owner string `json:"owner"`
Name string `json:"name"`
FullName string `json:"full_name"`
Number int `json:"number,omitempty"`
Event string `json:"event,omitempty"`
Status string `json:"status,omitempty"`
Created int64 `json:"created_at,omitempty"`
Started int64 `json:"started_at,omitempty"`
Finished int64 `json:"finished_at,omitempty"`
Commit string `json:"commit,omitempty"`
Branch string `json:"branch,omitempty"`
Ref string `json:"ref,omitempty"`
Refspec string `json:"refspec,omitempty"`
Remote string `json:"remote,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Author string `json:"author,omitempty"`
Avatar string `json:"author_avatar,omitempty"`
Email string `json:"author_email,omitempty"`
}
// // Activity represents an item in the user's feed or timeline.
// Activity struct {
// Owner string `json:"owner"`
// Name string `json:"name"`
// FullName string `json:"full_name"`
// Number int `json:"number,omitempty"`
// Event string `json:"event,omitempty"`
// Status string `json:"status,omitempty"`
// Created int64 `json:"created_at,omitempty"`
// Started int64 `json:"started_at,omitempty"`
// Finished int64 `json:"finished_at,omitempty"`
// Commit string `json:"commit,omitempty"`
// Branch string `json:"branch,omitempty"`
// Ref string `json:"ref,omitempty"`
// Refspec string `json:"refspec,omitempty"`
// Remote string `json:"remote,omitempty"`
// Title string `json:"title,omitempty"`
// Message string `json:"message,omitempty"`
// Author string `json:"author,omitempty"`
// Avatar string `json:"author_avatar,omitempty"`
// Email string `json:"author_email,omitempty"`
// }
// Server represents a server node.
Server struct {
@ -221,6 +225,13 @@ type (
Updated int64 `json:"updated"`
}
// Line represents a line of container logs.
Line struct {
Number int `json:"pos"`
Message string `json:"out"`
Timestamp int64 `json:"time"`
}
// Config represents a config file.
Config struct {
Data string `json:"data"`
@ -234,3 +245,13 @@ type (
Commit string `json:"commit,omitempty"`
}
)
// Error represents a json-encoded API error.
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
}
func (e *Error) Error() string {
return e.Message
}