Example #1
0
func BuildLogCmd(c *cli.Context, client drone.Client) error {
	var (
		nameParam = c.Args().Get(0)
		numParam  = c.Args().Get(1)
		jobParam  = c.Args().Get(2)

		err   error
		owner string
		name  string
		num   int
		job   int
	)

	num, err = strconv.Atoi(numParam)
	if err != nil {
		return fmt.Errorf("Invalid or missing build number")
	}
	job, err = strconv.Atoi(jobParam)
	if err != nil {
		return fmt.Errorf("Invalid or missing job number")
	}

	owner, name, err = parseRepo(nameParam)
	if err != nil {
		return err
	}
	rc, err := client.BuildLogs(owner, name, num, job)
	if err != nil {
		return err
	}
	defer rc.Close()

	io.Copy(os.Stdout, rc)
	return nil
}
Example #2
0
func SecureYamlCmd(c *cli.Context, client drone.Client) error {
	var (
		repo     = c.String("repo")
		inFile   = c.String("in")
		outFile  = c.String("out")
		ymlFile  = c.String("yaml")
		checksum = c.BoolT("checksum")
	)

	owner, name, err := parseRepo(repo)
	if err != nil {
		return err
	}

	keypair, err := client.RepoKey(owner, name)
	if err != nil {
		return err
	}

	key, err := toPublicKey(keypair.Public)
	if err != nil {
		return err
	}

	// read the .drone.sec.yml file (plain text)
	plaintext, err := readInput(inFile)
	if err != nil {
		return err
	}

	// parse the .drone.sec.yml file
	sec := new(secure.Secure)
	err = yaml.Unmarshal(plaintext, sec)
	if err != nil {
		return err
	}

	// read the .drone.yml file and caclulate the
	// checksum. add to the .drone.sec.yml file.
	yml, err := ioutil.ReadFile(ymlFile)
	if err == nil && checksum {
		sec.Checksum = sha256sum(string(yml))
	}

	// re-marshal the .drone.sec.yml file since we've
	// added the checksum
	plaintext, err = yaml.Marshal(sec)
	if err != nil {
		return err
	}

	// encrypt the .drone.sec.yml file
	ciphertext, err := encrypt(plaintext, key)
	if err != nil {
		return err
	}

	// write the encrypted .drone.sec.yml file to .drone.sec
	return writeOutput(outFile, ciphertext)
}
Example #3
0
func BuildLastCmd(c *cli.Context, client drone.Client) error {
	var (
		nameParam   = c.Args().Get(0)
		branchParam = c.Args().Get(1)
	)

	owner, name, err := parseRepo(nameParam)
	if err != nil {
		return err
	}
	build, err := client.BuildLast(owner, name, branchParam)
	if err != nil {
		return err
	}
	fmt.Println(build.Number)
	fmt.Println(build.Event)
	fmt.Println(build.Status)
	fmt.Println(build.Created)
	fmt.Println(build.Started)
	fmt.Println(build.Enqueued)
	fmt.Println(build.Finished)
	fmt.Println(build.Commit)
	fmt.Println(build.Ref)
	fmt.Println(build.Author)
	fmt.Println(build.Message)
	return nil
}
Example #4
0
func BuildStartCmd(c *cli.Context, client drone.Client) error {
	var (
		nameParam = c.Args().Get(0)
		numParam  = c.Args().Get(1)

		err   error
		owner string
		name  string
		num   int
	)

	num, err = strconv.Atoi(numParam)
	if err != nil {
		return fmt.Errorf("Invalid or missing build number")
	}
	owner, name, err = parseRepo(nameParam)
	if err != nil {
		return err
	}

	build, err := client.BuildStart(owner, name, num)
	if err != nil {
		return err
	}

	fmt.Println(build.Number)
	fmt.Println(build.Status)

	return nil
}
Example #5
0
func UserSelfCmd(c *cli.Context, client drone.Client) error {
	user, err := client.Self()
	if err != nil {
		return err
	}

	fmt.Println(user.Login)
	return nil
}
Example #6
0
func RepoListCmd(c *cli.Context, client drone.Client) error {
	repos, err := client.RepoList()
	if err != nil {
		return err
	}

	for _, repo := range repos {
		fmt.Println(repo.FullName)
	}
	return nil
}
Example #7
0
func NodeListCmd(c *cli.Context, client drone.Client) error {
	nodes, err := client.NodeList()
	if err != nil {
		return err
	}

	for _, node := range nodes {
		fmt.Println(node.ID, node.Addr)
	}

	return nil
}
Example #8
0
func RepoAddCmd(c *cli.Context, client drone.Client) error {
	owner, name, err := parseRepo(c.Args().Get(0))
	if err != nil {
		return err
	}

	repo, err := client.RepoPost(owner, name)
	if err != nil {
		return err
	}
	fmt.Printf("Successfully added %s\n", repo.FullName)
	return nil
}
Example #9
0
func UserAddCmd(c *cli.Context, client drone.Client) error {
	login := c.Args().Get(0)
	if len(login) == 0 {
		return fmt.Errorf("Missing or invalid user login")
	}

	user, err := client.UserPost(&drone.User{Login: login})
	if err != nil {
		return err
	}
	fmt.Printf("Successfully added user %s\n", user.Login)
	return nil
}
Example #10
0
func UserDelCmd(c *cli.Context, client drone.Client) error {
	login := c.Args().Get(0)
	if len(login) == 0 {
		return fmt.Errorf("Missing or invalid user login")
	}

	err := client.UserDel(login)
	if err != nil {
		return err
	}
	fmt.Printf("Successfully removed user %s\n", login)
	return nil
}
Example #11
0
func RepoInfoCmd(c *cli.Context, client drone.Client) error {
	owner, name, err := parseRepo(c.Args().Get(0))
	if err != nil {
		return err
	}
	repo, err := client.Repo(owner, name)
	if err != nil {
		return err
	}

	fmt.Println(repo.FullName)
	return nil
}
Example #12
0
func RepoDelCmd(c *cli.Context, client drone.Client) error {
	owner, name, err := parseRepo(c.Args().Get(0))
	if err != nil {
		return err
	}

	err = client.RepoDel(owner, name)
	if err != nil {
		return err
	}
	fmt.Printf("Successfully removed %s/%s\n", owner, name)
	return nil
}
Example #13
0
func NodeInfoCmd(c *cli.Context, client drone.Client) error {
	id, err := strconv.ParseInt(c.Args().Get(0), 0, 64)
	if err != nil {
		return fmt.Errorf("Invalid or missing node id. Must be an integer")
	}

	node, err := client.Node(id)
	if err != nil {
		return fmt.Errorf("Endpoint is not yet supported")
	}
	fmt.Println(node.Addr)
	return nil
}
Example #14
0
func UserListCmd(c *cli.Context, client drone.Client) error {
	users, err := client.UserList()
	if err != nil || len(users) == 0 {
		return err
	}
	w := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
	fmt.Fprintln(w, "username\temail\tadmin\tactive")
	fmt.Fprintln(w, "--------\t-----\t-----\t------")
	for _, user := range users {
		fmt.Fprintf(w, "%s\t%s\t%v\t%v\n", user.Login, user.Email, user.Admin, user.Active)
	}
	w.Flush()
	return nil
}
Example #15
0
func NodeDelCmd(c *cli.Context, client drone.Client) error {
	id, err := strconv.ParseInt(c.Args().Get(0), 0, 64)
	if err != nil {
		return fmt.Errorf("Invalid or missing node id. Must be an integer")
	}

	err = client.NodeDel(id)
	if err != nil {
		return err
	}

	fmt.Printf("Successfully removed node %d\n", id)
	return nil
}
Example #16
0
func UserListCmd(c *cli.Context, client drone.Client) error {

	users, err := client.UserList()
	if err != nil {
		return err
	}
	for _, user := range users {
		fmt.Println(user.Login)
		fmt.Println("\t", user.Email)
		fmt.Println("\t", user.Admin)
		fmt.Println("\t", user.Active)
	}

	return nil
}
Example #17
0
func BuildListCmd(c *cli.Context, client drone.Client) error {
	owner, name, err := parseRepo(c.Args().Get(0))
	if err != nil {
		return err
	}
	builds, err := client.BuildList(owner, name)
	if err != nil {
		return err
	}

	for _, build := range builds {
		fmt.Println(build.Number)
	}
	return nil
}
Example #18
0
func UserInfoCmd(c *cli.Context, client drone.Client) error {
	login := c.Args().Get(0)
	if len(login) == 0 {
		return fmt.Errorf("Missing or invalid user login")
	}

	user, err := client.User(login)
	if err != nil {
		return err
	}
	fmt.Println(user.Login)
	fmt.Println(user.Email)
	fmt.Println(user.Admin)
	fmt.Println(user.Active)
	return nil
}
Example #19
0
func NodeCreateCmd(c *cli.Context, client drone.Client) error {
	node := drone.Node{
		Addr: c.String("docker-host"),
		Arch: "linux_amd64",
	}

	cert, _ := ioutil.ReadFile(filepath.Join(
		c.String("docker-cert-path"),
		"cert.pem",
	))

	key, _ := ioutil.ReadFile(filepath.Join(
		c.String("docker-cert-path"),
		"key.pem",
	))

	ca, _ := ioutil.ReadFile(filepath.Join(
		c.String("docker-cert-path"),
		"ca.pem",
	))

	if len(cert) == 0 || len(key) == 0 {
		return fmt.Errorf("Error reading cert.pem or key.pem from %s",
			c.String("docker-cert-path"))
	}

	node.Cert = string(cert)
	node.Key = string(key)

	// only use the certificate authority if tls verify
	// is enabled for this docker host.
	if c.Bool("docker-tls-verify") {
		node.CA = string(ca)
	}

	_, err := client.NodePost(&node)
	if err != nil {
		return err
	}

	fmt.Printf("Successfully added %s\n", node.Addr)
	return nil
}
Example #20
0
func BuildStopCmd(c *cli.Context, client drone.Client) error {
	var (
		nameParam = c.Args().Get(0)
		numParam  = c.Args().Get(1)
		jobParam  = c.Args().Get(2)

		err   error
		owner string
		name  string
		num   int
		job   int
	)

	// jobs are really only useful to matrix builds. So if the
	// job is not specified we'll assume it isn't a matrix build
	// and we'll cancel job number 1
	if len(jobParam) == 0 {
		jobParam = "1"
	}

	num, err = strconv.Atoi(numParam)
	if err != nil {
		return fmt.Errorf("Invalid or missing build number")
	}
	job, err = strconv.Atoi(jobParam)
	if err != nil {
		return fmt.Errorf("Invalid or missing job number")
	}
	owner, name, err = parseRepo(nameParam)
	if err != nil {
		return err
	}

	err = client.BuildStop(owner, name, num, job)
	if err != nil {
		return err
	}

	fmt.Printf("stopping build %d job %d\n", num, job)
	return nil
}
Example #21
0
func BuildInfoCmd(c *cli.Context, client drone.Client) error {
	var (
		nameParam = c.Args().Get(0)
		numParam  = c.Args().Get(1)

		err   error
		owner string
		name  string
		num   int
	)

	num, err = strconv.Atoi(numParam)
	if err != nil {
		return fmt.Errorf("Invalid or missing build number")
	}

	owner, name, err = parseRepo(nameParam)
	if err != nil {
		return err
	}
	build, err := client.Build(owner, name, num)
	if err != nil {
		return err
	}
	fmt.Println(build.Number)
	fmt.Println(build.Event)
	fmt.Println(build.Status)
	fmt.Println(build.Created)
	fmt.Println(build.Started)
	fmt.Println(build.Enqueued)
	fmt.Println(build.Finished)
	fmt.Println(build.Commit)
	fmt.Println(build.Ref)
	fmt.Println(build.Author)
	fmt.Println(build.Message)
	return nil
}