Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,11 @@ _install_completion_script() {
esac
}

_install_completion_script "$SHELL" || true
CURRENT_SHELL=${0#-}
[ "$CURRENT_SHELL" != "$SHELL" ] && _install_completion_script "$CURRENT_SHELL" || true
if [ "$CI" != "1" ]; then
_install_completion_script "$SHELL" || true
CURRENT_SHELL=${0#-}
[ "$CURRENT_SHELL" != "$SHELL" ] && _install_completion_script "$CURRENT_SHELL" || true
fi
Comment thread
lionello marked this conversation as resolved.

# Cleanup: Remove the temporary directory
echo "Cleaning up..."
Expand Down
12 changes: 0 additions & 12 deletions src/pkg/cli/client/byoc/aws/byoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,6 @@ func TestDomainMultipleProjectSupport(t *testing.T) {
}
}

type FakeLoader struct {
ProjectName string
}

func (f FakeLoader) LoadProject(ctx context.Context) (*composeTypes.Project, error) {
return &composeTypes.Project{Name: f.ProjectName}, nil
}

func (f FakeLoader) LoadProjectName(ctx context.Context) (string, bool, error) {
return f.ProjectName, false, nil
}

//go:embed testdata/*.json
var testDir embed.FS

Expand Down
9 changes: 5 additions & 4 deletions src/pkg/cli/client/byoc/gcp/byoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ func (b *ByocGcp) SetUpCD(ctx context.Context, force bool) error {
}
}

// 5. Setup Cloud Run Job
term.Debugf("Using CD image: %q", b.CDImage)

b.SetupDone = true
Expand Down Expand Up @@ -847,10 +846,12 @@ func (b *ByocGcp) GetProjectUpdate(ctx context.Context, projectName string) (*de
pbBytes, err := b.driver.GetBucketObjectWithServiceAccount(ctx, bucketName, path, uploadSA)
if err != nil {
term.Debugf("Failed to get project bucket object from bucket %q at path %q with service account %q: %v", bucketName, path, uploadSA, err)
if errors.Is(err, gcp.ErrObjectNotExist) {
return nil, client.ErrNotExist // no services yet
// Handle the case where the object does not exist, or where we do not have permission to view the object, ie.
// "Permission 'iam.serviceAccounts.getAccessToken' denied on resource (or it may not exist)." #2051
if errors.Is(err, gcp.ErrObjectNotExist) || strings.Contains(err.Error(), "(or it may not exist)") {
return nil, client.ErrNotExist // first deployment, no services yet
Comment thread
lionello marked this conversation as resolved.
}
return nil, err
return nil, annotateGcpError(err)
}

var projUpdate defangv1.ProjectUpdate
Expand Down
16 changes: 16 additions & 0 deletions src/pkg/cli/client/byoc/gcp/byoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/api/googleapi"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
)
Expand Down Expand Up @@ -368,4 +369,19 @@ func TestGetServices(t *testing.T) {
require.NoError(t, err)
assert.Empty(t, res.Services)
})

t.Run("first deployment 403 = no services", func(t *testing.T) {
b.driver = &mockGcpDriver{
bucketName: "bucket-a",
getBucketObjectWithServiceAccountError: &googleapi.Error{
Code: 403,
Message: "Permission 'iam.serviceAccounts.getAccessToken' denied on resource (or it may not exist).",
},
}
res, err := b.GetServices(t.Context(), &defangv1.GetServicesRequest{
Project: "project1",
})
require.NoError(t, err)
assert.Empty(t, res.Services)
})
}
18 changes: 0 additions & 18 deletions src/pkg/cli/client/byoc/gcp/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gcp
import (
"errors"
"fmt"
"strings"

"github.com/DefangLabs/defang/src/pkg/http"
"google.golang.org/api/googleapi"
Expand Down Expand Up @@ -41,20 +40,3 @@ func annotateGcpError(err error) error {
}
return err
}

// Used to get nested values from the detail of a googleapi.Error
func GetGoogleAPIErrorDetail(detail any, path string) string {
if path == "" {
value, ok := detail.(string)
if ok {
return value
}
return ""
}
dm, ok := detail.(map[string]any)
if !ok {
return ""
}
key, rest, _ := strings.Cut(path, ".")
return GetGoogleAPIErrorDetail(dm[key], rest)
}
2 changes: 1 addition & 1 deletion src/pkg/cli/client/byoc/gcp/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func Test_BadGCPprojectnameErrorWrap(t *testing.T) {
wrappedErr := annotateGcpError(gcpErr)
assert.Equal(t, `double check the GCP project ID and make sure your Application Default Credentials have permission to access the project: `+gcpErr.Message, wrappedErr.Error())

// Test the error is wrapper correctly
// Test the error is wrapped correctly
var unwrappedErr *googleapi.Error
assert.True(t, errors.As(wrappedErr, &unwrappedErr))
assert.Equal(t, gcpErr, unwrappedErr)
Expand Down
Loading