-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: list available connectors configs (#62)
Signed-off-by: Lawrence Zawila <[email protected]>
- Loading branch information
1 parent
cf71535
commit a762de0
Showing
11 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/formancehq/payments/internal/pkg/connectors/currencycloud" | ||
"github.com/formancehq/payments/internal/pkg/connectors/dummypay" | ||
"github.com/formancehq/payments/internal/pkg/connectors/modulr" | ||
"github.com/formancehq/payments/internal/pkg/connectors/stripe" | ||
"github.com/formancehq/payments/internal/pkg/connectors/wise" | ||
|
||
"github.com/formancehq/payments/internal/pkg/configtemplate" | ||
"github.com/formancehq/payments/internal/pkg/connectors/bankingcircle" | ||
) | ||
|
||
func connectorConfigsHandler() http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
// TODO: It's not ideal to re-identify available connectors | ||
// Refactor it when refactoring the HTTP lib. | ||
|
||
configs := configtemplate.BuildConfigs( | ||
bankingcircle.Config{}, | ||
currencycloud.Config{}, | ||
dummypay.Config{}, | ||
modulr.Config{}, | ||
stripe.Config{}, | ||
wise.Config{}, | ||
) | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
|
||
err := json.NewEncoder(w).Encode(configs) | ||
if err != nil { | ||
handleServerError(w, r, err) | ||
|
||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package configtemplate | ||
|
||
type Configs map[string]Config | ||
|
||
type Config map[string]Parameter | ||
|
||
type Parameter struct { | ||
DataType Type `json:"dataType"` | ||
Required bool `json:"required"` | ||
} | ||
|
||
type TemplateBuilder interface { | ||
BuildTemplate() (string, Config) | ||
} | ||
|
||
func BuildConfigs(builders ...TemplateBuilder) Configs { | ||
configs := make(map[string]Config) | ||
for _, builder := range builders { | ||
name, config := builder.BuildTemplate() | ||
configs[name] = config | ||
} | ||
|
||
return configs | ||
} | ||
|
||
func NewConfig() Config { | ||
return make(map[string]Parameter) | ||
} | ||
|
||
func (c *Config) AddParameter(name string, dataType Type, required bool) { | ||
(*c)[name] = Parameter{ | ||
DataType: dataType, | ||
Required: required, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package configtemplate | ||
|
||
type Type string | ||
|
||
const ( | ||
TypeString Type = "string" | ||
TypeDurationNs Type = "duration ns" | ||
TypeDurationUnsignedInteger Type = "unsigned integer" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters