github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/environs/environ.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package environs 5 6 import ( 7 "github.com/juju/errors" 8 9 "github.com/juju/juju/environs/config" 10 ) 11 12 // EnvironConfigGetter exposes a model configuration to its clients. 13 type EnvironConfigGetter interface { 14 ModelConfig() (*config.Config, error) 15 CloudSpec() (CloudSpec, error) 16 } 17 18 // NewEnvironFunc is the type of a function that, given a model config, 19 // returns an Environ. This will typically be environs.New. 20 type NewEnvironFunc func(OpenParams) (Environ, error) 21 22 // GetEnviron returns the environs.Environ ("provider") associated 23 // with the model. 24 func GetEnviron(st EnvironConfigGetter, newEnviron NewEnvironFunc) (Environ, error) { 25 modelConfig, err := st.ModelConfig() 26 if err != nil { 27 return nil, errors.Trace(err) 28 } 29 cloudSpec, err := st.CloudSpec() 30 if err != nil { 31 return nil, errors.Trace(err) 32 } 33 env, err := newEnviron(OpenParams{ 34 Cloud: cloudSpec, 35 Config: modelConfig, 36 }) 37 if err != nil { 38 return nil, errors.Trace(err) 39 } 40 return env, nil 41 }