Skip to content

Commit 249410a

Browse files
committed
Added app url in create output
1 parent 9ecae43 commit 249410a

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

cmd/clace/app_cmds.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ Examples:
146146
fmt.Print("App created. No approval required\n")
147147
}
148148

149+
if createResult.HttpUrl != "" {
150+
fmt.Printf("\n HTTP Url: %s\n", createResult.HttpUrl)
151+
}
152+
if createResult.HttpsUrl != "" {
153+
fmt.Printf("HTTPS Url: %s\n", createResult.HttpsUrl)
154+
}
155+
149156
if createResult.DryRun {
150157
fmt.Print(DRY_RUN_MESSAGE)
151158
}

cmd/clace/preview_cmds.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ func previewCreateCommand(commonFlags []cli.Flag, clientConfig *types.ClientConf
8080
fmt.Printf("App creation %s. No approval required\n", status)
8181
}
8282

83+
if previewResponse.HttpUrl != "" {
84+
fmt.Printf("\n HTTP Url: %s\n", previewResponse.HttpUrl)
85+
}
86+
if previewResponse.HttpsUrl != "" {
87+
fmt.Printf("HTTPS Url: %s\n", previewResponse.HttpsUrl)
88+
}
89+
8390
if previewResponse.DryRun {
8491
fmt.Print(DRY_RUN_MESSAGE)
8592
}

internal/server/app_apis.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package server
55

66
import (
7+
"cmp"
78
"context"
89
"errors"
910
"fmt"
@@ -222,6 +223,8 @@ func (s *Server) createApp(ctx context.Context, appEntry *types.AppEntry, approv
222223
}
223224

224225
ret := &types.AppCreateResponse{
226+
HttpUrl: s.getAppHttpUrl(appEntry),
227+
HttpsUrl: s.getAppHttpsUrl(appEntry),
225228
DryRun: dryRun,
226229
ApproveResults: results,
227230
}
@@ -238,6 +241,24 @@ func (s *Server) createApp(ctx context.Context, appEntry *types.AppEntry, approv
238241
return ret, nil
239242
}
240243

244+
// getAppHttpUrl returns the HTTP URL for accessing the app
245+
func (s *Server) getAppHttpUrl(appEntry *types.AppEntry) string {
246+
if s.config.Http.Port <= 0 {
247+
return ""
248+
}
249+
domain := cmp.Or(appEntry.Domain, "localhost")
250+
return fmt.Sprintf("%s://%s:%d%s", "http", domain, s.config.Http.Port, appEntry.Path)
251+
}
252+
253+
// getAppHttpsUrl returns the HTTPS URL for accessing the app
254+
func (s *Server) getAppHttpsUrl(appEntry *types.AppEntry) string {
255+
if s.config.Https.Port <= 0 {
256+
return ""
257+
}
258+
domain := cmp.Or(appEntry.Domain, "localhost")
259+
return fmt.Sprintf("%s://%s:%d%s", "https", domain, s.config.Https.Port, appEntry.Path)
260+
}
261+
241262
func (s *Server) setupApp(appEntry *types.AppEntry, tx types.Transaction) (*app.App, error) {
242263
subLogger := s.With().Str("id", string(appEntry.Id)).Str("path", appEntry.Path).Logger()
243264
appLogger := types.Logger{Logger: &subLogger}
@@ -907,6 +928,8 @@ func (s *Server) PreviewApp(ctx context.Context, mainAppPath, commitId string, a
907928

908929
ret := &types.AppPreviewResponse{
909930
DryRun: dryRun,
931+
HttpUrl: s.getAppHttpUrl(&previewAppEntry),
932+
HttpsUrl: s.getAppHttpsUrl(&previewAppEntry),
910933
ApproveResult: *auditResult,
911934
Success: true,
912935
}

internal/types/api.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ type AppListResponse struct {
9292

9393
type AppCreateResponse struct {
9494
DryRun bool `json:"dry_run"`
95+
HttpUrl string `json:"http_url"`
96+
HttpsUrl string `json:"https_url"`
9597
ApproveResults []ApproveResult `json:"approve_results"`
9698
}
9799

@@ -131,6 +133,8 @@ type AppUpdateSettingsResponse struct {
131133

132134
type AppPreviewResponse struct {
133135
DryRun bool `json:"dry_run"`
136+
HttpUrl string `json:"http_url"`
137+
HttpsUrl string `json:"https_url"`
134138
Success bool `json:"success"`
135139
ApproveResult ApproveResult `json:"approve_result"`
136140
}

tests/commander/test_load_app.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ tests:
135135
exit-code: 1
136136
load0270: # Create app, valid branch
137137
command: ../clace app create --approve --branch main https://github.com/claceio/clace/examples/disk_usage /ghload3
138-
stdout: "App created. Permissions have been approved"
138+
stdout: "HTTPS Url: https://localhost:25223/ghload3"
139139
exit-code: 0
140140
load0280: # Create app, invalid commit id.
141141
command: ../clace app create --approve --commit invalid https://github.com/claceio/clace/examples/disk_usage /ghload4
142142
stderr: "reference not found"
143143
exit-code: 1
144144
load0290: # Create app, valid commit id
145145
command: ../clace app create --approve --commit 6574d08b47abb71636665fbcbad51c2f7e8cab71 https://github.com/claceio/clace/examples/disk_usage /ghload5
146-
stdout: "App created. Permissions have been approved"
146+
stdout: "HTTP Url: http://localhost:25222/ghload5"
147147
exit-code: 0
148148

149149
load0900: # cleanup

0 commit comments

Comments
 (0)