Skip to content

Commit 1dcbce3

Browse files
committed
#34: Added three way merge for declarative config updates
1 parent 74d1968 commit 1dcbce3

File tree

8 files changed

+294
-86
lines changed

8 files changed

+294
-86
lines changed

cmd/clace/app_cmds.go

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -190,30 +190,7 @@ Examples:
190190
return err
191191
}
192192

193-
approveResult := createResult.ApproveResults[0]
194-
if len(createResult.ApproveResults) == 2 {
195-
fmt.Printf("App audit results %s - %s\n", createResult.ApproveResults[1].AppPathDomain, createResult.ApproveResults[1].Id)
196-
}
197-
fmt.Printf("App audit results %s - %s\n", approveResult.AppPathDomain, approveResult.Id)
198-
printApproveResult(approveResult)
199-
200-
if approveResult.NeedsApproval {
201-
if cCtx.Bool("approve") {
202-
fmt.Print("App created. Permissions have been approved\n")
203-
} else {
204-
fmt.Print("App created. Permissions need to be approved\n")
205-
}
206-
} else {
207-
fmt.Print("App created. No approval required\n")
208-
}
209-
210-
if createResult.HttpUrl != "" {
211-
fmt.Printf("\n HTTP Url: %s\n", createResult.HttpUrl)
212-
}
213-
if createResult.HttpsUrl != "" {
214-
fmt.Printf("HTTPS Url: %s\n", createResult.HttpsUrl)
215-
}
216-
193+
printCreateResult(cCtx, createResult)
217194
if createResult.DryRun {
218195
fmt.Print(DRY_RUN_MESSAGE)
219196
}
@@ -223,6 +200,28 @@ Examples:
223200
}
224201
}
225202

203+
func printCreateResult(cCtx *cli.Context, createResult types.AppCreateResponse) {
204+
fmt.Printf(" App: %s\n", createResult.Path)
205+
if createResult.HttpUrl != "" {
206+
fmt.Printf(" HTTP Url: %s\n", createResult.HttpUrl)
207+
}
208+
if createResult.HttpsUrl != "" {
209+
fmt.Printf("HTTPS Url: %s\n", createResult.HttpsUrl)
210+
}
211+
approveResult := createResult.ApproveResults[0]
212+
printApproveResult(approveResult)
213+
214+
if approveResult.NeedsApproval {
215+
if cCtx.Bool("approve") {
216+
fmt.Print("App created. Permissions have been approved\n")
217+
} else {
218+
fmt.Print("App created. Permissions need to be approved\n")
219+
}
220+
} else {
221+
fmt.Print("App created. No approval required\n")
222+
}
223+
}
224+
226225
func appListCommand(commonFlags []cli.Flag, clientConfig *types.ClientConfig) *cli.Command {
227226
flags := make([]cli.Flag, 0, len(commonFlags)+2)
228227
flags = append(flags, commonFlags...)

cmd/clace/apply_cmd.go

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ func initApplyCommand(commonFlags []cli.Flag, clientConfig *types.ClientConfig)
2121
flags = append(flags, newStringFlag("commit", "c", "The commit SHA to checkout if using git source. This takes precedence over branch", ""))
2222
flags = append(flags, newStringFlag("git-auth", "g", "The name of the git_auth entry in server config to use", ""))
2323
flags = append(flags, newBoolFlag("approve", "a", "Approve the app permissions", false))
24-
flags = append(flags, newBoolFlag("reload", "", "Which apps to reload: none, updated, all (default)", false))
24+
flags = append(flags, newStringFlag("reload", "r", "Which apps to reload: none, updated (default), all", "updated"))
25+
flags = append(flags, newBoolFlag("promote", "p", "Promote changes from stage to prod", false))
26+
flags = append(flags, newBoolFlag("force", "f", "Force update app config, removing non-declarative changes", false))
2527
flags = append(flags, dryRunFlag())
2628

2729
return &cli.Command{
@@ -39,11 +41,16 @@ Examples:
3941
Apply app config for all apps: clace apply ./app.ace all
4042
Apply app config for all apps: clace apply ./app.ace all
4143
Apply app config for example.com domain apps: clace apply ./app.ace example.com:**
42-
Apply app config from git for all apps: clace apply github.com/claceio/apps/apps.ace all
44+
Apply app config from git for all apps: clace apply --reload=updated --promote --approve github.com/claceio/apps/apps.ace all
45+
Apply app config from git for all apps, overwriting changes: clace apply --reload=updated --promote --force github.com/claceio/apps/apps.ace all
4346
`,
4447

4548
Action: func(cCtx *cli.Context) error {
46-
if cCtx.NArg() != 2 {
49+
if cCtx.NArg() < 2 {
50+
reload := cCtx.String("reload")
51+
if reload != "" && reload != "none" && reload != "updated" && reload != "all" {
52+
return fmt.Errorf("invalid value for --reload, expected none/updated/all: %s", reload)
53+
}
4754
return fmt.Errorf("expected two arguments: <filePath> <appPathGlob>")
4855
}
4956

@@ -58,6 +65,8 @@ Examples:
5865
values.Add("commit", cCtx.String("commit"))
5966
values.Add("gitAuth", cCtx.String("git-auth"))
6067
values.Add("reload", cCtx.String("reload"))
68+
values.Add("promote", strconv.FormatBool(cCtx.Bool("promote")))
69+
values.Add("force", strconv.FormatBool(cCtx.Bool("force")))
6170

6271
var applyResponse types.AppApplyResponse
6372
err := client.Post("/_clace/apply", values, nil, &applyResponse)
@@ -66,6 +75,70 @@ Examples:
6675
}
6776

6877
fmt.Printf("Applied %#+v\n", applyResponse)
78+
79+
if len(applyResponse.CreateResults) > 0 {
80+
fmt.Fprintf(cCtx.App.Writer, "Created apps:\n")
81+
for i, createResult := range applyResponse.CreateResults {
82+
if i > 0 {
83+
fmt.Fprintf(cCtx.App.Writer, ", ")
84+
}
85+
printCreateResult(cCtx, createResult)
86+
}
87+
}
88+
89+
if len(applyResponse.UpdateResults) > 0 {
90+
fmt.Fprintf(cCtx.App.Writer, "Updated apps: ")
91+
for i, updateResult := range applyResponse.UpdateResults {
92+
if i > 0 {
93+
fmt.Fprintf(cCtx.App.Writer, ", ")
94+
}
95+
fmt.Fprintf(cCtx.App.Writer, "%s", updateResult)
96+
}
97+
fmt.Fprintln(cCtx.App.Writer)
98+
}
99+
100+
if len(applyResponse.ReloadResults) > 0 {
101+
fmt.Fprintf(cCtx.App.Writer, "Reloaded apps: ")
102+
for i, reloadResult := range applyResponse.ReloadResults {
103+
if i > 0 {
104+
fmt.Fprintf(cCtx.App.Writer, ", ")
105+
}
106+
fmt.Fprintf(cCtx.App.Writer, "%s", reloadResult)
107+
}
108+
fmt.Fprintln(cCtx.App.Writer)
109+
}
110+
111+
if len(applyResponse.ApproveResults) > 0 {
112+
fmt.Fprintf(cCtx.App.Writer, "Approved apps:\n")
113+
for _, approveResult := range applyResponse.ApproveResults {
114+
if !approveResult.NeedsApproval {
115+
// Server does not return these for reload to reduce the noise
116+
fmt.Printf("No approval required. %s - %s\n", approveResult.AppPathDomain, approveResult.Id)
117+
} else {
118+
fmt.Printf("App permissions have been approved %s - %s\n", approveResult.AppPathDomain, approveResult.Id)
119+
printApproveResult(approveResult)
120+
}
121+
}
122+
}
123+
124+
if len(applyResponse.PromoteResults) > 0 {
125+
fmt.Fprintf(cCtx.App.Writer, "Promoted apps: ")
126+
for i, promoteResult := range applyResponse.PromoteResults {
127+
if i > 0 {
128+
fmt.Fprintf(cCtx.App.Writer, ", ")
129+
}
130+
fmt.Fprintf(cCtx.App.Writer, "%s", promoteResult)
131+
}
132+
fmt.Fprintln(cCtx.App.Writer)
133+
}
134+
135+
fmt.Fprintf(cCtx.App.Writer, "%d app(s) updated, %d app(s) reloaded, %d app(s) approved, %d app(s) promoted.\n",
136+
len(applyResponse.UpdateResults), len(applyResponse.ReloadResults), len(applyResponse.ApproveResults), len(applyResponse.PromoteResults))
137+
138+
if applyResponse.DryRun {
139+
fmt.Print(DRY_RUN_MESSAGE)
140+
}
141+
69142
return nil
70143
},
71144
}

internal/server/app_apis.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ func (s *Server) createApp(ctx context.Context, currentTx types.Transaction, app
243243
}
244244

245245
ret := &types.AppCreateResponse{
246+
Path: appEntry.String(),
246247
HttpUrl: s.getAppHttpUrl(appEntry),
247248
HttpsUrl: s.getAppHttpsUrl(appEntry),
248249
DryRun: dryRun,

0 commit comments

Comments
 (0)