Skip to content

print https:// before public endpoints #1207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion src/cmd/cli/command/deploymentinfo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
"regexp"
"strings"

"github.com/DefangLabs/defang/src/pkg/cli"
Expand Down Expand Up @@ -44,12 +45,28 @@ func printServiceStatesAndEndpoints(serviceInfos []*defangv1.ServiceInfo) error
showCertGenerateHint = true
}
}
endpoints := make([]string, 0, len(serviceInfo.Endpoints))
for _, endpoint := range serviceInfo.Endpoints {
if endpoint == "" {
continue
}

Comment on lines +50 to +53
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this actually happen? I'd remove it

Suggested change
if endpoint == "" {
continue
}

if !regexp.MustCompile(`\.internal:\d{1,5}$`).MatchString(endpoint) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels brittle. There's some code elsewhere that mirrors this. Perhaps we just check for the port number: no port = https (which is true)

endpoint = "https://" + endpoint
}

endpoints = append(endpoints, endpoint)
}
if len(endpoints) == 0 {
endpoints = append(endpoints, "N/A")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a test for this case

}

serviceTableItems = append(serviceTableItems, ServiceTableItem{
Deployment: serviceInfo.Etag,
Name: serviceInfo.Service.Name,
Status: serviceInfo.State.String(),
DomainName: domainname,
Endpoints: strings.Join(serviceInfo.Endpoints, ", "),
Endpoints: strings.Join(endpoints, ", "),
})
}

Expand Down
10 changes: 5 additions & 5 deletions src/cmd/cli/command/deploymentinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func TestPrintServiceStatesAndEndpoints(t *testing.T) {
Status: "UNKNOWN",
Endpoints: []string{
"example.com",
"service1.internal",
"service1.internal:80",
},
}})
const expectedOutput = `Deployment Name Status Endpoints
service1 NOT_SPECIFIED example.com, service1.internal
service1 NOT_SPECIFIED https://example.com, service1.internal:80
`
receivedLines := strings.Split(stdout.String(), "\n")
expectedLines := strings.Split(expectedOutput, "\n")
Expand Down Expand Up @@ -99,12 +99,12 @@ func TestPrintServiceStatesAndEndpointsAndDomainname(t *testing.T) {
Domainname: "example.com",
Endpoints: []string{
"example.com",
"service1.internal",
"service1.internal:80",
},
}})
expectedLines := []string{
"Deployment Name Status Endpoints DomainName",
" service1 NOT_SPECIFIED example.com, service1.internal https://example.com",
"Deployment Name Status Endpoints DomainName",
" service1 NOT_SPECIFIED https://example.com, service1.internal:80 https://example.com",
" * Run `defang cert generate` to get a TLS certificate for your service(s)",
"",
}
Expand Down
2 changes: 1 addition & 1 deletion src/pkg/clouds/gcp/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (gcp Gcp) EnsureAPIsEnabled(ctx context.Context, apis ...string) error {
projectName := "projects/" + gcp.ProjectId

for i := range 3 {
term.Debugf("Enabling services: %v\n", apis)
term.Debugf("Enabling services for project %q: %v\n", projectName, apis)
req := &serviceusage.BatchEnableServicesRequest{
ServiceIds: apis,
}
Expand Down
Loading