Skip to content

Commit

Permalink
feat: add host address to hasura actions (#491)
Browse files Browse the repository at this point in the history
## 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)
  • Loading branch information
huichiaotsou committed Oct 31, 2022
1 parent c999075 commit e7d9375
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion cmd/migrate/v3/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions modules/actions/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion modules/actions/handle_additional_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions modules/actions/types/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions types/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e7d9375

Please sign in to comment.