/
init.go
80 lines (62 loc) · 2.36 KB
/
init.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"os"
"github.com/bjorge/friendlyreservations/config"
"github.com/bjorge/friendlyreservations/frapi"
"github.com/bjorge/friendlyreservations/gae_platform"
"github.com/bjorge/friendlyreservations/logger"
graphql "github.com/graph-gophers/graphql-go"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
)
var log = logger.New()
var namespace string
var corsOriginURI string
var destinationURI string
var adminSchema *graphql.Schema
var memberSchema *graphql.Schema
var homeSchema *graphql.Schema
// variables from environment
// var hostedDomain string // example "mydomain.com"
var secure bool // if true, use https, otherwise http (PLATFORM_SECURE)
var clientID string // the oauth client id
var clientSecret string // the oauth client secret
// package variables
var googleOauthConfig *oauth2.Config
var oauthStateString string
var redirectURL string
var redirectLabel string
func init() {
corsOriginURI = config.GetConfig("PLATFORM_CORS_ORIGIN_URI")
redirectURL = config.GetConfig("REDIRECT_URL")
redirectLabel = config.GetConfig("REDIRECT_LABEL")
frapi.PersistedEmailStore = gaeplatform.NewPersistedEmailStore()
frapi.PersistedVersionedEvents = gaeplatform.NewPersistedVersionedEvents()
frapi.PersistedPropertyList = gaeplatform.NewPersistedPropertyList()
frapi.EmailSender = gaeplatform.NewEmailSender()
adminSchema = graphql.MustParseSchema(frapi.AdminSchema, &frapi.Resolver{})
memberSchema = graphql.MustParseSchema(frapi.MemberSchema, &frapi.Resolver{})
homeSchema = graphql.MustParseSchema(frapi.HomeSchema, &frapi.Resolver{})
namespace = os.Getenv("PLATFORM_NAMESPACE")
if namespace == "" {
panic(fmt.Errorf("must define PLATFORM_NAMESPACE in app.yaml"))
}
destinationURI = config.GetConfig("PLATFORM_DESTINATION_URI")
if destinationURI == "" {
panic(fmt.Errorf("PLATFORM_DESTINATION_URI is not set"))
}
// load settings from environment
secure = os.Getenv("PLATFORM_SECURE") == "true"
clientID = os.Getenv("PLATFORM_CLIENT_ID")
clientSecret = os.Getenv("PLATFORM_CLIENT_SECRET")
oauthStateString = os.Getenv("PLATFORM_OAUTH_STATE")
//hostedDomain = os.Getenv("PLATFORM_HOSTED_DOMAIN")
googleOauthConfig = &oauth2.Config{
RedirectURL: destinationURI + "/oauth2callback",
ClientID: clientID,
ClientSecret: clientSecret,
Scopes: []string{"email", "profile"},
Endpoint: google.Endpoint,
}
}