Skip to content

Commit fe02663

Browse files
committed
Address PR comments
1 parent a98f6fe commit fe02663

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

src/pkg/cli/client/byoc/aws/byoc.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,12 @@ func (b *ByocAws) setUp(ctx context.Context) error {
107107
term.Debug("Failed to get subdomain zone:", err)
108108
// return err; FIXME: ignore this error for now
109109
} else {
110-
// Use STS to get the account ID
111-
cfg, err := b.driver.LoadConfig(ctx)
110+
whoami, err := b.WhoAmI(ctx)
112111
if err != nil {
113-
return annotateAwsError(err)
114-
}
115-
identity, err := sts.NewFromConfig(cfg).GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
116-
if err != nil {
117-
return annotateAwsError(err)
112+
return err
118113
}
119114

120-
b.ProjectDomain = b.getProjectDomain(*identity.Account, domain.Zone)
115+
b.ProjectDomain = b.getProjectDomain(whoami.Account, domain.Zone)
121116
if b.ProjectDomain != "" {
122117
b.ShouldDelegateSubdomain = true
123118
}
@@ -480,7 +475,7 @@ func (b *ByocAws) Follow(ctx context.Context, req *defangv1.TailRequest) (client
480475
var err error
481476
var taskArn ecs.TaskArn
482477
var eventStream ecs.EventStream
483-
if etag != "" && !pkg.IsValidRandomID(etag) {
478+
if etag != "" && !pkg.IsValidBase36ID(etag) {
484479
// Assume "etag" is a task ID
485480
eventStream, err = b.driver.TailTaskID(ctx, etag)
486481
taskArn, _ = b.driver.GetTaskArn(etag)

src/pkg/cli/client/byoc/aws/byoc_test.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/json"
99
"io"
1010
"path"
11-
"regexp"
1211
"strings"
1312
"sync"
1413
"testing"
@@ -33,17 +32,17 @@ func TestDomainMultipleProjectSupport(t *testing.T) {
3332
PublicFqdn string
3433
PrivateFqdn string
3534
}{
36-
{"tenant1", "tenant1", "web", port80, `web--80\.[0-9a-z]{12}\.example\.com`, `web\.[0-9a-z]{12}\.example\.com`, "web.tenant1.internal"},
37-
{"tenant1", "tenant1", "web", hostModePort, `web\.tenant1.internal:80`, `web.[0-9a-z]{12}.example\.com`, "web.tenant1.internal"},
38-
{"project1", "tenant1", "web", port80, `web--80\.[0-9a-z]{12}\.example\.com`, `web\.[0-9a-z]{12}\.example\.com`, "web.project1.internal"},
39-
{"Project1", "tenant1", "web", port80, `web--80\.[0-9a-z]{12}\.example\.com`, `web\.[0-9a-z]{12}\.example\.com`, "web.project1.internal"},
40-
{"project1", "tenant1", "web", hostModePort, `web\.project1\.internal:80`, `web\.[0-9a-z]{12}\.example\.com`, "web.project1.internal"},
41-
{"project1", "tenant1", "api", port8080, `api--8080\.[0-9a-z]{12}\.example\.com`, `api\.[0-9a-z]{12}\.example\.com`, "api.project1.internal"},
42-
{"tenant1", "tenant1", "web", port80, `web--80\.[0-9a-z]{12}\.example\.com`, `web\.[0-9a-z]{12}\.example\.com`, "web.tenant1.internal"},
43-
{"tenant1", "tenant1", "web", hostModePort, `web\.tenant1\.internal:80`, `web\.[0-9a-z]{12}\.example\.com`, "web.tenant1.internal"},
44-
{"Project1", "tenant1", "web", port80, `web--80\.[0-9a-z]{12}\.example\.com`, `web\.[0-9a-z]{12}\.example\.com`, "web.project1.internal"},
45-
{"Tenant2", "tenant1", "web", port80, `web--80\.[0-9a-z]{12}\.example\.com`, `web\.[0-9a-z]{12}\.example\.com`, "web.tenant2.internal"},
46-
{"tenant1", "tenAnt1", "web", port80, `web--80\.[0-9a-z]{12}\.example\.com`, `web\.[0-9a-z]{12}\.example\.com`, "web.tenant1.internal"},
35+
{"tenant1", "tenant1", "web", port80, `web--80.hrdsvwhcn3jj.example.com`, `web.hrdsvwhcn3jj.example.com`, "web.tenant1.internal"},
36+
{"tenant1", "tenant1", "web", hostModePort, `web.tenant1.internal:80`, `web.hrdsvwhcn3jj.example.com`, "web.tenant1.internal"},
37+
{"project1", "tenant1", "web", port80, `web--80.b9vgnfzbeoeu.example.com`, `web.b9vgnfzbeoeu.example.com`, "web.project1.internal"},
38+
{"Project1", "tenant1", "web", port80, `web--80.cr8i4dwuk1vs.example.com`, `web.cr8i4dwuk1vs.example.com`, "web.project1.internal"},
39+
{"project1", "tenant1", "web", hostModePort, `web.project1.internal:80`, `web.b9vgnfzbeoeu.example.com`, "web.project1.internal"},
40+
{"project1", "tenant1", "api", port8080, `api--8080.b9vgnfzbeoeu.example.com`, `api.b9vgnfzbeoeu.example.com`, "api.project1.internal"},
41+
{"tenant1", "tenant1", "web", port80, `web--80.hrdsvwhcn3jj.example.com`, `web.hrdsvwhcn3jj.example.com`, "web.tenant1.internal"},
42+
{"tenant1", "tenant1", "web", hostModePort, `web.tenant1.internal:80`, `web.hrdsvwhcn3jj.example.com`, "web.tenant1.internal"},
43+
{"Project1", "tenant1", "web", port80, `web--80.cr8i4dwuk1vs.example.com`, `web.cr8i4dwuk1vs.example.com`, "web.project1.internal"},
44+
{"Tenant2", "tenant1", "web", port80, `web--80.wsm43awbq8pw.example.com`, `web.wsm43awbq8pw.example.com`, "web.tenant2.internal"},
45+
{"tenant1", "tenAnt1", "web", port80, `web--80.b63ocx2b6o4t.example.com`, `web.b63ocx2b6o4t.example.com`, "web.tenant1.internal"},
4746
}
4847

4948
for _, tt := range tests {
@@ -56,12 +55,12 @@ func TestDomainMultipleProjectSupport(t *testing.T) {
5655
b.ProjectDomain = b.getProjectDomain("123456789012", "example.com")
5756

5857
endpoint := b.getEndpoint(tt.Fqn, tt.Port)
59-
if !regexp.MustCompile(tt.EndPoint).MatchString(endpoint) {
58+
if tt.EndPoint != endpoint {
6059
t.Errorf("expected endpoint %q, got %q", tt.EndPoint, endpoint)
6160
}
6261

6362
publicFqdn := b.getPublicFqdn(tt.Fqn)
64-
if !regexp.MustCompile(tt.PublicFqdn).MatchString(publicFqdn) {
63+
if tt.PublicFqdn != publicFqdn {
6564
t.Errorf("expected public fqdn %q, got %q", tt.PublicFqdn, publicFqdn)
6665
}
6766

src/pkg/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func RandomID() string {
6969
return Base36ID(rand.Uint64())
7070
}
7171

72-
func IsValidRandomID(s string) bool {
72+
func IsValidBase36ID(s string) bool {
7373
_, err := strconv.ParseUint(s, 36, 64)
7474
return len(s) == 12 && err == nil
7575
}

0 commit comments

Comments
 (0)