Index: environs/open.go |
=== modified file 'environs/open.go' |
--- environs/open.go 2012-05-14 23:40:28 +0000 |
+++ environs/open.go 2012-05-17 01:43:20 +0000 |
@@ -2,9 +2,8 @@ |
import "fmt" |
-// New creates a new Environ using the |
-// environment configuration with the given name. |
-// If name is empty, the default environment will be used. |
+// Open creates a new Environ using the environment configuration with the |
+// given name. If name is empty, the default environment will be used. |
func (envs *Environs) Open(name string) (Environ, error) { |
if name == "" { |
name = envs.Default |
@@ -26,3 +25,20 @@ |
return env, nil |
} |
+ |
+// NewEnviron creates a new Environ of the registered kind using the configuration |
+// supplied. |
+func NewEnviron(kind string, config map[string]interface{}) (Environ, error) { |
+ p, ok := providers[kind] |
+ if !ok { |
+ return nil, fmt.Errorf("no registered provider for kind: %q", kind) |
+ } |
+ cfg, err := p.ConfigChecker().Coerce(config, nil) |
+ if err != nil { |
+ return nil, fmt.Errorf("error validating environment: %v", err) |
+ } |
+ |
+ // TODO(dfc) the name of the environment needs to be injected when it is |
+ // created from environments.yaml |
+ return p.Open("default", cfg) |
+} |