forked from convox/rack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.go
43 lines (33 loc) · 916 Bytes
/
environment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package aws
import (
"fmt"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/convox/rack/api/crypt"
"github.com/convox/rack/api/structs"
)
func (p *AWSProvider) EnvironmentGet(app string) (structs.Environment, error) {
a, err := p.AppGet(app)
if err != nil {
return nil, err
}
if a.Status == "creating" {
return nil, fmt.Errorf("app is still being created: %s", app)
}
data, err := p.s3Get(a.Outputs["Settings"], "env")
if err != nil {
// if we get a 404 from aws just return an empty environment
if awsError, ok := err.(awserr.RequestFailure); ok && awsError.StatusCode() == 404 {
return structs.Environment{}, nil
}
return nil, err
}
if a.Parameters["Key"] != "" {
cr := crypt.New(p.Region, p.Access, p.Secret)
if d, err := cr.Decrypt(a.Parameters["Key"], data); err == nil {
data = d
}
}
env := structs.Environment{}
env.LoadEnvironment(data)
return env, nil
}