github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/infrastructure/infrastructure.go (about) 1 package infrastructure 2 3 import ( 4 "github.com/hashicorp/otto/appfile" 5 "github.com/hashicorp/otto/context" 6 "github.com/hashicorp/otto/ui" 7 ) 8 9 // Infrastructure is an interface that must be implemented by each 10 // infrastructure type with a method of creating it. 11 type Infrastructure interface { 12 // Creds is called when Otto determines that it needs credentials 13 // for this infrastructure provider. The Infra should query the 14 // user (or environment) for creds and return them. Otto will 15 // handle encrypting, storing, and retrieving the credentials. 16 Creds(*Context) (map[string]string, error) 17 18 // VerifyCreds is called with the result of either prompting or 19 // retrieving cached credentials. This gives Infrastructure 20 // implementations a chance to check that credentials are good before 21 // continuing to perform any operations. 22 VerifyCreds(*Context) error 23 24 Execute(*Context) error 25 Compile(*Context) (*CompileResult, error) 26 Flavors() []string 27 } 28 29 // Context is the context for operations on infrastructures. Some of 30 // the fields in this struct are only available for certain operations. 31 type Context struct { 32 context.Shared 33 34 // Action is the sub-action to take when being executed. 35 // 36 // ActionArgs is the list of arguments for this action. 37 // 38 // Both of these fields will only be set for the Execute call. 39 Action string 40 ActionArgs []string 41 42 // Dir is the directory that the compilation is allowed to write to 43 // for persistant storage of data. For other tasks, this will be the 44 // directory that was already populated by compilation. 45 Dir string 46 47 // The infrastructure configuration itself from the Appfile. This includes 48 // the flavor of the infrastructure we want to launch. 49 Infra *appfile.Infrastructure 50 } 51 52 // RouteName implements the router.Context interface so we can use Router 53 func (c *Context) RouteName() string { 54 return c.Action 55 } 56 57 // RouteArgs implements the router.Context interface so we can use Router 58 func (c *Context) RouteArgs() []string { 59 return c.ActionArgs 60 } 61 62 // UI implements router.Context so we can use this in router.Router 63 func (c *Context) UI() ui.Ui { 64 return c.Ui 65 } 66 67 // CompileResult is the structure containing compilation result values. 68 type CompileResult struct{}