From e7d9375c48630ff5bd20c74f78d8a41294cb192a Mon Sep 17 00:00:00 2001 From: Aaron <76254323+huichiaotsou@users.noreply.github.com> Date: Mon, 31 Oct 2022 23:11:57 +0800 Subject: [PATCH] feat: add host address to hasura actions (#491) ## Description Fixes #490 --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch - [x] provided a link to the relevant issue or specification - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- CHANGELOG.md | 1 + cmd/migrate/v3/migrate.go | 2 +- modules/actions/config.go | 14 +++++++++++--- modules/actions/handle_additional_operations.go | 2 +- modules/actions/types/worker.go | 4 ++-- types/config/config.go | 4 ++-- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5832a15f..11459b330 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ #### Hasura - ([\#473](https://github.com/forbole/bdjuno/pull/473)) Improved Hasura permissions +- ([\#491](https://github.com/forbole/bdjuno/pull/491)) Add host address to Hasura actions ### Dependencies - ([\#462](https://github.com/forbole/bdjuno/pull/462)) Updated Juno to `v3.4.0` diff --git a/cmd/migrate/v3/migrate.go b/cmd/migrate/v3/migrate.go index d7774779f..579758619 100644 --- a/cmd/migrate/v3/migrate.go +++ b/cmd/migrate/v3/migrate.go @@ -59,7 +59,7 @@ func migrateConfig() (Config, error) { } if cfg.Actions == nil { - cfg.Actions = actions.NewConfig(3000, nil) + cfg.Actions = actions.NewConfig("127.0.0.1", 3000, nil) } return cfg, nil diff --git a/modules/actions/config.go b/modules/actions/config.go index 928876c94..d127ed058 100644 --- a/modules/actions/config.go +++ b/modules/actions/config.go @@ -7,21 +7,24 @@ import ( // Config contains the configuration about the actions module type Config struct { + Host string `yaml:"host"` Port uint `yaml:"port"` Node *remote.Details `yaml:"node,omitempty"` } // NewConfig returns a new Config instance -func NewConfig(port uint, remoteDetails *remote.Details) *Config { +func NewConfig(host string, port uint, remoteDetails *remote.Details) *Config { return &Config{ + Host: host, Port: port, Node: remoteDetails, } } // DefaultConfig returns the default configuration -func DefaultConfig() Config { - return Config{ +func DefaultConfig() *Config { + return &Config{ + Host: "127.0.0.1", Port: 3000, Node: nil, } @@ -33,5 +36,10 @@ func ParseConfig(bz []byte) (*Config, error) { } var cfg T err := yaml.Unmarshal(bz, &cfg) + + if cfg.Config == nil { + return DefaultConfig(), nil + } + return cfg.Config, err } diff --git a/modules/actions/handle_additional_operations.go b/modules/actions/handle_additional_operations.go index 4b5327888..5a6cd0a34 100644 --- a/modules/actions/handle_additional_operations.go +++ b/modules/actions/handle_additional_operations.go @@ -46,7 +46,7 @@ func (m *Module) RunAdditionalOperations() error { // Start the worker waitGroup.Add(1) - go worker.Start(m.cfg.Port) + go worker.Start(m.cfg.Host, m.cfg.Port) // Block main process (signal capture will call WaitGroup's Done) waitGroup.Wait() diff --git a/modules/actions/types/worker.go b/modules/actions/types/worker.go index e2600b742..b6fe643fc 100644 --- a/modules/actions/types/worker.go +++ b/modules/actions/types/worker.go @@ -94,8 +94,8 @@ func (w *ActionsWorker) handleError(writer http.ResponseWriter, path string, err } // Start starts the worker -func (w *ActionsWorker) Start(port uint) { - err := http.ListenAndServe(fmt.Sprintf(":%d", port), w.mux) +func (w *ActionsWorker) Start(host string, port uint) { + err := http.ListenAndServe(fmt.Sprintf("%s:%d", host, port), w.mux) if err != nil { panic(err) } diff --git a/types/config/config.go b/types/config/config.go index 187c22269..f36154ed3 100644 --- a/types/config/config.go +++ b/types/config/config.go @@ -12,11 +12,11 @@ import ( // Config represents the BDJuno configuration type Config struct { JunoConfig junoconfig.Config `yaml:"-,inline"` - ActionsConfig actions.Config `yaml:"actions"` + ActionsConfig *actions.Config `yaml:"actions"` } // NewConfig returns a new Config instance -func NewConfig(junoCfg junoconfig.Config, actionsCfg actions.Config) Config { +func NewConfig(junoCfg junoconfig.Config, actionsCfg *actions.Config) Config { return Config{ JunoConfig: junoCfg, ActionsConfig: actionsCfg,