Permalink
Browse files

app: don't create bucket and iam credentials for apps by default

  • Loading branch information...
1 parent aa68bfb commit fd243625f4d15e8d1a0a7f7c4b76b0fafd021165 @fsouza fsouza committed Jan 21, 2013
Showing with 49 additions and 20 deletions.
  1. +16 −14 app/actions.go
  2. +22 −0 app/actions_test.go
  3. +10 −6 app/app.go
  4. +1 −0 etc/tsuru.conf
View
@@ -145,7 +145,6 @@ var createUserPolicyAction = action.Action{
var exportEnvironmentsAction = action.Action{
Forward: func(ctx action.FWContext) (action.Result, error) {
app := ctx.Params[0].(*App)
- env := ctx.Previous.(*s3Env)
err := app.Get()
if err != nil {
return nil, err
@@ -155,19 +154,22 @@ var exportEnvironmentsAction = action.Action{
{Name: "TSURU_APPNAME", Value: app.Name},
{Name: "TSURU_HOST", Value: host},
}
- variables := map[string]string{
- "ENDPOINT": env.endpoint,
- "LOCATIONCONSTRAINT": strconv.FormatBool(env.locationConstraint),
- "ACCESS_KEY_ID": env.AccessKey,
- "SECRET_KEY": env.SecretKey,
- "BUCKET": env.bucket,
- }
- for name, value := range variables {
- envVars = append(envVars, bind.EnvVar{
- Name: fmt.Sprintf("TSURU_S3_%s", name),
- Value: value,
- InstanceName: s3InstanceName,
- })
+ env, ok := ctx.Previous.(*s3Env)
+ if ok {
+ variables := map[string]string{
+ "ENDPOINT": env.endpoint,
+ "LOCATIONCONSTRAINT": strconv.FormatBool(env.locationConstraint),
+ "ACCESS_KEY_ID": env.AccessKey,
+ "SECRET_KEY": env.SecretKey,
+ "BUCKET": env.bucket,
+ }
+ for name, value := range variables {
+ envVars = append(envVars, bind.EnvVar{
+ Name: fmt.Sprintf("TSURU_S3_%s", name),
+ Value: value,
+ InstanceName: s3InstanceName,
+ })
+ }
}
err = app.SetEnvsToApp(envVars, false, true)
if err != nil {
View
@@ -294,6 +294,28 @@ func (s *S) TestExportEnvironmentsForward(c *C) {
c.Assert(message.Args, DeepEquals, []string{app.Name})
}
+func (s *S) TestExportEnvironmentsForwardWithoutS3Env(c *C) {
+ expectedHost := "localhost"
+ config.Set("host", expectedHost)
+ app := App{Name: "mist", Framework: "opeth"}
+ err := s.conn.Apps().Insert(app)
+ c.Assert(err, IsNil)
+ defer s.conn.Apps().Remove(bson.M{"name": app.Name})
+ ctx := action.FWContext{Params: []interface{}{&app}, Previous: &app}
+ result, err := exportEnvironmentsAction.Forward(ctx)
+ c.Assert(err, IsNil)
+ c.Assert(result, Equals, &app)
+ err = app.Get()
+ c.Assert(err, IsNil)
+ appEnv := app.InstanceEnv(s3InstanceName)
+ c.Assert(appEnv, DeepEquals, map[string]bind.EnvVar{})
+ appEnv = app.InstanceEnv("")
+ c.Assert(appEnv["TSURU_APPNAME"].Value, Equals, app.Name)
+ c.Assert(appEnv["TSURU_APPNAME"].Public, Equals, false)
+ c.Assert(appEnv["TSURU_HOST"].Value, Equals, expectedHost)
+ c.Assert(appEnv["TSURU_HOST"].Public, Equals, false)
+}
+
func (s *S) TestExportEnvironmentsBackward(c *C) {
envNames := []string{
"TSURU_S3_ACCESS_KEY_ID", "TSURU_S3_SECRET_KEY",
View
@@ -103,12 +103,16 @@ func CreateApp(a *App, units uint) error {
"starting with a letter."
return &ValidationError{Message: msg}
}
- pipeline := action.NewPipeline(
- &insertApp, &createIAMUserAction, &createIAMAccessKeyAction,
- &createBucketAction, &createUserPolicyAction,
- &exportEnvironmentsAction, &createRepository, &provisionApp,
- &provisionAddUnits,
- )
+ actions := []*action.Action{&insertApp}
+ useS3, _ := config.GetBool("bucket-support")
+ if useS3 {
+ actions = append(actions, &createIAMUserAction,
+ &createIAMAccessKeyAction,
+ &createBucketAction, &createUserPolicyAction)
+ }
+ actions = append(actions, &exportEnvironmentsAction,
+ &createRepository, &provisionApp, &provisionAddUnits)
+ pipeline := action.NewPipeline(actions...)
return pipeline.Execute(a, units)
}
View
@@ -10,6 +10,7 @@ git:
host: gandalf.plataformas.glb.com
protocol: http
port: 8080
+bucket-support: true
aws:
access-key-id: access-id-here
secret-access-key: secret-very-secret

0 comments on commit fd24362

Please sign in to comment.