Skip to content

Commit

Permalink
cmd/gomote: implements GRPC gettar command
Browse files Browse the repository at this point in the history
This change adds the implementation for the GRPC gettar comamnd to the
gomote client.

Updates golang/go#48737
For golang/go#47521

Change-Id: I8b8f12a3104977128d912ced41215faed69ea719
Reviewed-on: https://go-review.googlesource.com/c/build/+/406857
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Run-TryBot: Carlos Amedee <[email protected]>
Reviewed-by: Carlos Amedee <[email protected]>
Auto-Submit: Carlos Amedee <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
cagedmantis committed May 17, 2022
1 parent ab8fa91 commit 92f7ca4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
56 changes: 54 additions & 2 deletions cmd/gomote/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import (
"flag"
"fmt"
"io"
"net/http"
"os"
"time"

"golang.org/x/build/internal/gomote/protos"
)

// get a .tar.gz
func getTar(args []string) error {
// legacyGetTar a .tar.gz
func legacyGetTar(args []string) error {
fs := flag.NewFlagSet("get", flag.ContinueOnError)
fs.Usage = func() {
fmt.Fprintln(os.Stderr, "gettar usage: gomote gettar [get-opts] <buildlet-name>")
Expand Down Expand Up @@ -41,3 +45,51 @@ func getTar(args []string) error {
_, err = io.Copy(os.Stdout, tgz)
return err
}

// getTar a .tar.gz
func getTar(args []string) error {
fs := flag.NewFlagSet("get", flag.ContinueOnError)
fs.Usage = func() {
fmt.Fprintln(os.Stderr, "gettar usage: gomote gettar [get-opts] <buildlet-name>")
fs.PrintDefaults()
os.Exit(1)
}
var dir string
fs.StringVar(&dir, "dir", "", "relative directory from buildlet's work dir to tar up")

fs.Parse(args)
if fs.NArg() != 1 {
fs.Usage()
}

name := fs.Arg(0)
ctx := context.Background()
client := gomoteServerClient(ctx)
resp, err := client.ReadTGZToURL(ctx, &protos.ReadTGZToURLRequest{
GomoteId: name,
Directory: dir,
})
if err != nil {
return fmt.Errorf("unable to retireve tgz URL: %s", statusFromError(err))
}
httpClient := &http.Client{
Timeout: 10 * time.Second,
Transport: &http.Transport{
TLSHandshakeTimeout: 5 * time.Second,
},
}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, resp.GetUrl(), nil)
if err != nil {
return fmt.Errorf("unable to create HTTP Request: %s", err)
}
r, err := httpClient.Do(req)
if err != nil {
return fmt.Errorf("unable to download tgz: %s", err)
}
defer r.Body.Close()
_, err = io.Copy(os.Stdout, r.Body)
if err != nil {
return fmt.Errorf("unable to copy tgz to stdout: %s", err)
}
return nil
}
5 changes: 3 additions & 2 deletions cmd/gomote/gomote.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ To list the subcommands, run "gomote" without arguments:
rdp RDP (Remote Desktop Protocol) to a Windows buildlet
run run a command on a buildlet
ssh ssh to a buildlet
v2 version 2 of the gomote API
v2 version 2 of the gomote API
To list all the builder types available, run "create" with no arguments:
Expand Down Expand Up @@ -151,7 +151,7 @@ func registerCommand(name, des string, run func([]string) error) {
func registerCommands() {
registerCommand("create", "create a buildlet; with no args, list types of buildlets", legacyCreate)
registerCommand("destroy", "destroy a buildlet", legacyDestroy)
registerCommand("gettar", "extract a tar.gz from a buildlet", getTar)
registerCommand("gettar", "extract a tar.gz from a buildlet", legacyGetTar)
registerCommand("ls", "list the contents of a directory on a buildlet", legacyLs)
registerCommand("list", "list active buildlets", legacyList)
registerCommand("ping", "test whether a buildlet is alive and reachable ", ping)
Expand Down Expand Up @@ -224,6 +224,7 @@ func version2(args []string) error {
"ping": ping,
"ssh": ssh,
"rm": rm,
"gettar": getTar,
}
if len(args) == 0 {
usage()
Expand Down

0 comments on commit 92f7ca4

Please sign in to comment.