-
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.
Merge pull request #27 from form3tech-oss/mike-kintri-config
Make pact-proxy more configurable using ENV variables
- Loading branch information
Showing
14 changed files
with
1,493 additions
and
40 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,30 @@ | ||
package configuration | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"context" | ||
|
||
"github.com/form3tech-oss/pact-proxy/internal/app/pactproxy" | ||
"github.com/pkg/errors" | ||
"github.com/sethvargo/go-envconfig" | ||
) | ||
|
||
type ProxyConfig struct { | ||
ServerAddress string | ||
Target string | ||
} | ||
func NewFromEnv() (pactproxy.Config, error) { | ||
ctx := context.Background() | ||
|
||
func ConfigureProxy(config ProxyConfig) error { | ||
targetURL, err := url.Parse(config.Target) | ||
var config pactproxy.Config | ||
err := envconfig.Process(ctx, &config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
serverAddr := config.ServerAddress | ||
if serverAddr == "" { | ||
serverAddr = fmt.Sprintf("http://:%s", targetURL.Port()) | ||
} | ||
|
||
serverAddrURL, err := url.Parse(serverAddr) | ||
if err != nil { | ||
return err | ||
return config, errors.Wrap(err, "process env config") | ||
} | ||
return config, nil | ||
} | ||
|
||
server, err := GetServer(serverAddrURL) | ||
func ConfigureProxy(config pactproxy.Config) error { | ||
server, err := GetServer(&config.ServerAddress) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
pactproxy.StartProxy(server, targetURL) | ||
pactproxy.StartProxy(server, &config) | ||
return err | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.