Skip to content

Commit 86acb69

Browse files
cagedmantisgopherbot
authored andcommitted
internal/gomote: enable downloads from GCS bucket in WriteTGZFromURL
This change enables downloads from the gomote transfer GCS bucket for gomote instances that do not have permission to read from that bucket. Any URL that is passed in for that bucket will have a signed URL created for it and that will be passed on to the gomote instance. For golang/go#47521 Updates golang/go#48742 Change-Id: I5874efd1349f4154aea58677c734653b18cd88c9 Reviewed-on: https://go-review.googlesource.com/c/build/+/397597 Reviewed-by: Heschi Kreinick <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Run-TryBot: Carlos Amedee <[email protected]> Auto-Submit: Carlos Amedee <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 916d23b commit 86acb69

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

internal/gomote/gomote.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,18 @@ func (s *Server) WriteTGZFromURL(ctx context.Context, req *protos.WriteTGZFromUR
466466
// the helper function returns meaningful GRPC error.
467467
return nil, err
468468
}
469-
if err = bc.PutTarFromURL(ctx, req.GetUrl(), req.GetDirectory()); err != nil {
469+
url := req.GetUrl()
470+
if onObjectStore(s.gceBucketName, url) {
471+
object, err := objectFromURL(s.gceBucketName, url)
472+
if err != nil {
473+
return nil, status.Errorf(codes.InvalidArgument, "invalid URL")
474+
}
475+
url, err = s.signURLForDownload(object)
476+
if err != nil {
477+
return nil, status.Errorf(codes.Aborted, "unable to sign url for download: %s", err)
478+
}
479+
}
480+
if err := bc.PutTarFromURL(ctx, url, req.GetDirectory()); err != nil {
470481
return nil, status.Errorf(codes.FailedPrecondition, "unable to write tar.gz: %s", err)
471482
}
472483
return &protos.WriteTGZFromURLResponse{}, nil

internal/gomote/gomote_test.go

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -723,19 +723,6 @@ func TestUploadFileError(t *testing.T) {
723723
}
724724
}
725725

726-
func TestWriteTGZFromURL(t *testing.T) {
727-
ctx := access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAP())
728-
client := setupGomoteTest(t, context.Background())
729-
gomoteID := mustCreateInstance(t, client, fakeIAP())
730-
if _, err := client.WriteTGZFromURL(ctx, &protos.WriteTGZFromURLRequest{
731-
GomoteId: gomoteID,
732-
Directory: "foo",
733-
Url: `https://go.dev/dl/go1.17.6.linux-amd64.tar.gz`,
734-
}); err != nil {
735-
t.Fatalf("client.WriteTGZFromURL(ctx, req) = response, %s; want no error", err)
736-
}
737-
}
738-
739726
// TODO(go.dev/issue/48737) add test for files on GCS
740727
func TestWriteFileFromURL(t *testing.T) {
741728
ctx := access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAP())
@@ -817,6 +804,32 @@ func TestWriteFileFromURLError(t *testing.T) {
817804
}
818805
}
819806

807+
func TestWriteTGZFromURL(t *testing.T) {
808+
ctx := access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAP())
809+
client := setupGomoteTest(t, context.Background())
810+
gomoteID := mustCreateInstance(t, client, fakeIAP())
811+
if _, err := client.WriteTGZFromURL(ctx, &protos.WriteTGZFromURLRequest{
812+
GomoteId: gomoteID,
813+
Directory: "foo",
814+
Url: `https://go.dev/dl/go1.17.6.linux-amd64.tar.gz`,
815+
}); err != nil {
816+
t.Fatalf("client.WriteTGZFromURL(ctx, req) = response, %s; want no error", err)
817+
}
818+
}
819+
820+
func TestWriteTGZFromURLGomoteStaging(t *testing.T) {
821+
ctx := access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAP())
822+
client := setupGomoteTest(t, context.Background())
823+
gomoteID := mustCreateInstance(t, client, fakeIAP())
824+
if _, err := client.WriteTGZFromURL(ctx, &protos.WriteTGZFromURLRequest{
825+
GomoteId: gomoteID,
826+
Directory: "foo",
827+
Url: fmt.Sprintf("https://storage.googleapis.com/%s/go1.17.6.linux-amd64.tar.gz?field=x", testBucketName),
828+
}); err != nil {
829+
t.Fatalf("client.WriteTGZFromURL(ctx, req) = response, %s; want no error", err)
830+
}
831+
}
832+
820833
func TestWriteTGZFromURLError(t *testing.T) {
821834
// This test will create a gomote instance and attempt to call TestWriteTGZFromURL.
822835
// If overrideID is set to true, the test will use a different gomoteID than the
@@ -862,6 +875,12 @@ func TestWriteTGZFromURLError(t *testing.T) {
862875
url: "go.dev/dl/1_14.tar.gz",
863876
wantCode: codes.PermissionDenied,
864877
},
878+
{
879+
desc: "invalid gomote staging bucket URL",
880+
ctx: access.FakeContextWithOutgoingIAPAuth(context.Background(), fakeIAP()),
881+
url: fmt.Sprintf("https://storage.googleapis.com/%s/go1.17.6.linux-amd64.tar.gz", testBucketName),
882+
wantCode: codes.InvalidArgument,
883+
},
865884
}
866885
for _, tc := range testCases {
867886
t.Run(tc.desc, func(t *testing.T) {

0 commit comments

Comments
 (0)