-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The
common-metering-plugin
now expands environment variables
- Loading branch information
Showing
3 changed files
with
39 additions
and
4 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,37 @@ | ||
package apps | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/streamingfast/dmetering" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// GetCommonMeteringPlugin returns the common metering plugin value to use | ||
// for the application. It reads the `common-metering-plugin` flag | ||
// from the command and returns the plugin after expanding the | ||
// environment variables in it meaning 'paymentGateway://test?token=${TOKEN}'. | ||
func GetCommonMeteringPluginValue() string { | ||
plugin := viper.GetString("common-metering-plugin") | ||
return os.ExpandEnv(plugin) | ||
} | ||
|
||
// GetCommonMeteringPlugin returns the common metering plugin to use | ||
// for the application. It reads the `common-metering-plugin` flag | ||
// from the command and returns the plugin after expanding the | ||
// environment variables in it meaning 'paymentGateway://test?token=${TOKEN}'. | ||
func GetCommonMeteringPlugin(cmd *cobra.Command, logger *zap.Logger) (dmetering.EventEmitter, error) { | ||
// We keep cmd as argument for future proofing, at which point we are going to break | ||
// GetCommonMeteringPluginValue above. | ||
_ = cmd | ||
|
||
eventEmitter, err := dmetering.New(GetCommonMeteringPluginValue(), logger) | ||
if err != nil { | ||
return nil, fmt.Errorf("new metering plugin: %w", err) | ||
} | ||
|
||
return eventEmitter, nil | ||
} |
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