Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add host address to hasura actions #491

Merged
merged 2 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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