Skip to content

Commit d8c01ef

Browse files
harmony7rcaril
andauthored
Ensure [local_server.pushpin] section persists during fastly.toml manifest file update (#1535)
### Change summary This PR updates `MarshalTOML()` for `manifest/File` such that the `[local_server.pushpin]` section and its fields persist when the file is written. * The `pushpin` section as well as its individual fields are now optional, such that it will be able to persist the file back as it was before starting. * `[local_server.pushpin]` has been added to `fastly-viceroy-update.toml`, which is used by the test `TestManifestPersistsLocalServerSection`, ensuring that the section is written out and reads back in to the same value. This fixes #1532. * [x] Have you followed the guidelines in our Contributing document? * [x] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/fastly/cli/pulls) for the same update/change? ### Changes to Core Features: * [x] Have you successfully run tests with your changes locally? ### User Impact * [x] What is the user impact of this change? Users can now safely run CLI commands that modify fastly.toml without losing their `[local_server.pushpin]` section. ### Are there any considerations that need to be addressed for release? Since this overwrite happens right after initializing an app from the starter kit, this would be nice to get out asap. Would be great if this can be released as a quick patch release such as 11.5.1. --------- Co-authored-by: Richard Carillo <77027245+rcaril@users.noreply.github.com>
1 parent 49216a4 commit d8c01ef

5 files changed

Lines changed: 58 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Bug fixes:
1212

13+
- fix(manifest): Ensure pushpin section is persisted during manifest file update ([#1535](https://github.com/fastly/cli/pull/1535))
14+
1315
### Dependencies:
1416
- build(deps): `github.com/ulikunitz/xz` from 0.5.12 to 0.5.13 ([#1524](https://github.com/fastly/cli/pull/1524))
1517
- build(deps): `github.com/stretchr/testify` from 1.10.0 to 1.11.0 ([#1527](https://github.com/fastly/cli/pull/1527))

pkg/commands/compute/serve.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ func (c *ServeCommand) Exec(in io.Reader, out io.Writer) (err error) {
215215
return err
216216
}
217217

218-
enablePushpin := c.enablePushpin || c.Globals.Manifest.File.LocalServer.Pushpin.EnablePushpin
218+
enablePushpin := c.enablePushpin ||
219+
(c.Globals.Manifest.File.LocalServer.Pushpin != nil &&
220+
c.Globals.Manifest.File.LocalServer.Pushpin.EnablePushpin != nil &&
221+
*c.Globals.Manifest.File.LocalServer.Pushpin.EnablePushpin)
219222
var pushpinCtx pushpinContext
220223
if enablePushpin {
221224
// The function checks for nil, so the semgrep warning is falsely triggered
@@ -607,12 +610,15 @@ func (c *ServeCommand) GetPushpinProxyPort(out io.Writer) (uint16, error) {
607610
return pushpinProxyPort, nil
608611
}
609612

610-
pushpinProxyPort = c.Globals.Manifest.File.LocalServer.Pushpin.PushpinProxyPort
611-
if pushpinProxyPort != 0 {
612-
if c.Globals.Verbose() {
613-
text.Info(out, "Using Pushpin proxy port via `local_server.pushpin.proxy_port` setting: %d", pushpinProxyPort)
613+
if c.Globals.Manifest.File.LocalServer.Pushpin != nil &&
614+
c.Globals.Manifest.File.LocalServer.Pushpin.PushpinProxyPort != nil {
615+
pushpinProxyPort = *c.Globals.Manifest.File.LocalServer.Pushpin.PushpinProxyPort
616+
if pushpinProxyPort != 0 {
617+
if c.Globals.Verbose() {
618+
text.Info(out, "Using Pushpin proxy port via `local_server.pushpin.proxy_port` setting: %d", pushpinProxyPort)
619+
}
620+
return pushpinProxyPort, nil
614621
}
615-
return pushpinProxyPort, nil
616622
}
617623

618624
pushpinProxyPort = 7677
@@ -647,12 +653,15 @@ func (c *ServeCommand) GetPushpinPublishPort(out io.Writer) (uint16, error) {
647653
return pushpinPublishPort, nil
648654
}
649655

650-
pushpinPublishPort = c.Globals.Manifest.File.LocalServer.Pushpin.PushpinPublishPort
651-
if pushpinPublishPort != 0 {
652-
if c.Globals.Verbose() {
653-
text.Info(out, "Using Pushpin publish handler port via `local_server.pushpin.publish_port` setting: %d", pushpinPublishPort)
656+
if c.Globals.Manifest.File.LocalServer.Pushpin != nil &&
657+
c.Globals.Manifest.File.LocalServer.Pushpin.PushpinPublishPort != nil {
658+
pushpinPublishPort = *c.Globals.Manifest.File.LocalServer.Pushpin.PushpinPublishPort
659+
if pushpinPublishPort != 0 {
660+
if c.Globals.Verbose() {
661+
text.Info(out, "Using Pushpin publish handler port via `local_server.pushpin.publish_port` setting: %d", pushpinPublishPort)
662+
}
663+
return pushpinPublishPort, nil
654664
}
655-
return pushpinPublishPort, nil
656665
}
657666

658667
pushpinPublishPort = 5561
@@ -676,12 +685,15 @@ func (c *ServeCommand) GetPushpinRunner(out io.Writer) (bin string, err error) {
676685
return filepath.Abs(pushpinRunnerBinPath)
677686
}
678687

679-
pushpinRunnerBinPath = c.Globals.Manifest.File.LocalServer.Pushpin.PushpinPath
680-
if pushpinRunnerBinPath != "" {
681-
if c.Globals.Verbose() {
682-
text.Info(out, "Using user provided install of Pushpin runner via `local_server.pushpin.pushpin_path` setting: %s", pushpinRunnerBinPath)
688+
if c.Globals.Manifest.File.LocalServer.Pushpin != nil &&
689+
c.Globals.Manifest.File.LocalServer.Pushpin.PushpinPath != nil {
690+
pushpinRunnerBinPath = *c.Globals.Manifest.File.LocalServer.Pushpin.PushpinPath
691+
if pushpinRunnerBinPath != "" {
692+
if c.Globals.Verbose() {
693+
text.Info(out, "Using user provided install of Pushpin runner via `local_server.pushpin.pushpin_path` setting: %s", pushpinRunnerBinPath)
694+
}
695+
return filepath.Abs(pushpinRunnerBinPath)
683696
}
684-
return filepath.Abs(pushpinRunnerBinPath)
685697
}
686698

687699
if c.Globals.Verbose() {

pkg/manifest/file.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,23 @@ func (f *File) MarshalTOML() ([]byte, error) {
9292
localServer["kv_stores"] = kvStores
9393
}
9494

95+
if f.LocalServer.Pushpin != nil {
96+
pushpin := make(map[string]any)
97+
if f.LocalServer.Pushpin.EnablePushpin != nil {
98+
pushpin["enable"] = *f.LocalServer.Pushpin.EnablePushpin
99+
}
100+
if f.LocalServer.Pushpin.PushpinPath != nil {
101+
pushpin["pushpin_path"] = *f.LocalServer.Pushpin.PushpinPath
102+
}
103+
if f.LocalServer.Pushpin.PushpinProxyPort != nil {
104+
pushpin["proxy_port"] = *f.LocalServer.Pushpin.PushpinProxyPort
105+
}
106+
if f.LocalServer.Pushpin.PushpinPublishPort != nil {
107+
pushpin["publish_port"] = *f.LocalServer.Pushpin.PushpinPublishPort
108+
}
109+
localServer["pushpin"] = pushpin
110+
}
111+
95112
if f.LocalServer.SecretStores != nil {
96113
secretStores := make(map[string]any)
97114
for key, entry := range f.LocalServer.SecretStores {

pkg/manifest/local_server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type LocalServer struct {
1313
ConfigStores map[string]LocalConfigStore `toml:"config_stores,omitempty"`
1414
KVStores LocalKVStoreMap `toml:"kv_stores,omitempty"`
1515
SecretStores LocalSecretStoreMap `toml:"secret_stores,omitempty"`
16-
Pushpin LocalPushpinMap `toml:"pushpin,omitempty"`
16+
Pushpin *LocalPushpinMap `toml:"pushpin,omitempty"`
1717
ViceroyVersion string `toml:"viceroy_version,omitempty"`
1818
}
1919

@@ -196,10 +196,10 @@ func (m *LocalSecretStoreMap) UnmarshalTOML(v any) error {
196196
// LocalPushpinMap represents configuration of a local instance of Pushpin,
197197
// used for local experimentation and testing of handoff_fanout.
198198
type LocalPushpinMap struct {
199-
EnablePushpin bool `toml:"enable,omitempty"`
200-
PushpinPath string `toml:"pushpin_path,omitempty"`
201-
PushpinProxyPort uint16 `toml:"proxy_port,omitempty"`
202-
PushpinPublishPort uint16 `toml:"publish_port,omitempty"`
199+
EnablePushpin *bool `toml:"enable,omitempty"`
200+
PushpinPath *string `toml:"pushpin_path,omitempty"`
201+
PushpinProxyPort *uint16 `toml:"proxy_port,omitempty"`
202+
PushpinPublishPort *uint16 `toml:"publish_port,omitempty"`
203203
}
204204

205205
func decodeTOMLMap(m map[string]any, out any) error {

pkg/manifest/testdata/fastly-viceroy-update.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ metadata = "This is some metadata"
5151
key = "second"
5252
file = "strings.json"
5353

54+
[local_server.pushpin]
55+
enable = true
56+
pushpin_path = "path/to/pushpin"
57+
proxy_port = 7777
58+
publish_port = 6666
59+
5460
[local_server.secret_stores]
5561
store_one = [
5662
{ key = "first", data = "This is some secret data" },

0 commit comments

Comments
 (0)