|
|
@@ -0,0 +1,39 @@
|
|
|
+package preview
|
|
|
+
|
|
|
+import (
|
|
|
+ "os"
|
|
|
+ "strings"
|
|
|
+
|
|
|
+ "github.com/porter-dev/switchboard/pkg/drivers"
|
|
|
+ "github.com/porter-dev/switchboard/pkg/models"
|
|
|
+)
|
|
|
+
|
|
|
+type OSEnvDriver struct {
|
|
|
+ output map[string]interface{}
|
|
|
+}
|
|
|
+
|
|
|
+func NewOSEnvDriver(resource *models.Resource, opts *drivers.SharedDriverOpts) (drivers.Driver, error) {
|
|
|
+ return &OSEnvDriver{
|
|
|
+ output: make(map[string]interface{}),
|
|
|
+ }, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (d *OSEnvDriver) ShouldApply(resource *models.Resource) bool {
|
|
|
+ return true
|
|
|
+}
|
|
|
+
|
|
|
+func (d *OSEnvDriver) Apply(resource *models.Resource) (*models.Resource, error) {
|
|
|
+ for _, key := range os.Environ() {
|
|
|
+ keyVal := strings.Split(key, "=")
|
|
|
+
|
|
|
+ if len(keyVal) == 2 && keyVal[0] != "" && keyVal[1] != "" {
|
|
|
+ d.output[keyVal[0]] = keyVal[1]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return resource, nil
|
|
|
+}
|
|
|
+
|
|
|
+func (d *OSEnvDriver) Output() (map[string]interface{}, error) {
|
|
|
+ return d.output, nil
|
|
|
+}
|