forked from parse-community/parse-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
54 lines (46 loc) · 1002 Bytes
/
context.go
File metadata and controls
54 lines (46 loc) · 1002 Bytes
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
44
45
46
47
48
49
50
51
52
53
54
package parsecli
import (
"fmt"
"net/http"
"github.com/facebookgo/parse"
)
type Context struct {
Config Config
AppName string
AppConfig AppConfig
}
func newContext(e *Env, appName string) (*Context, error) {
config, err := ConfigFromDir(e.Root)
if err != nil {
return nil, err
}
app, err := config.App(appName)
if err != nil {
return nil, err
}
masterKey, err := app.GetMasterKey(e)
if err != nil {
return nil, err
}
e.ParseAPIClient = e.ParseAPIClient.WithCredentials(
parse.MasterKey{
ApplicationID: app.GetApplicationID(),
MasterKey: masterKey,
},
)
if e.HerokuAPIClient != nil {
authToken, err := app.GetApplicationAuth(e)
if err != nil {
return nil, err
}
headers := make(http.Header)
headers.Add("Authorization", fmt.Sprintf("Bearer %s", authToken))
e.HerokuAPIClient.AdditionalHeaders = headers
e.HerokuAPIClient.UserAgent = UserAgent
}
return &Context{
AppName: appName,
AppConfig: app,
Config: config,
}, nil
}