--- /dev/null
+package app
+
+import (
+ "context"
+
+ "google.golang.org/appengine/datastore"
+ "google.golang.org/appengine/log"
+)
+
+var Config struct {
+ ProjectNumber string
+
+ FitbitClientID string
+ FitbitClientSecret string
+ FitbitSubscriberCode string
+
+ GoogleClientID string
+ GoogleClientSecret string
+}
+
+func LoadConfig(ctx context.Context) error {
+ key := datastore.NewKey(ctx, "Config", "Production", 0, nil)
+ if err := datastore.Get(ctx, key, &Config); err != nil {
+ log.Errorf(ctx, `datastore.Get("Config", "Production") = %v`, err)
+ return err
+ }
+ return nil
+}
)
var oauth2Config = &oauth2.Config{
- ClientID: "@FITBIT_CLIENT_ID@",
- ClientSecret: "@FITBIT_CLIENT_SECRET@",
+ ClientID: app.Config.FitbitClientID,
+ ClientSecret: app.Config.FitbitClientSecret,
Endpoint: oauth2fitbit.Endpoint,
RedirectURL: "https://kraftakt.octo.it/fitbit/grant",
Scopes: []string{
)
var oauthConfig = &oauth2.Config{
- ClientID: "@GOOGLE_CLIENT_ID@",
- ClientSecret: "@GOOGLE_CLIENT_SECRET@",
+ ClientID: app.Config.GoogleClientID,
+ ClientSecret: app.Config.GoogleClientSecret,
Endpoint: oauth2google.Endpoint,
RedirectURL: "https://kraftakt.octo.it/google/grant",
Scopes: []string{
func Application(ctx context.Context) *fitness.Application {
return &fitness.Application{
- Name: "Fitbit to Google Fit sync",
+ Name: "Kraftakt",
Version: appengine.VersionID(ctx),
DetailsUrl: "", // optional
}
fields := []string{
dataSource.Type,
dataSource.DataType.Name,
- "@PROJECT_NUMBER@", // FIXME
+ app.Config.ProjectNumber,
}
if dev := dataSource.Device; dev != nil {
http.HandleFunc("/google/setup", googleSetupHandler)
http.Handle("/google/grant", AuthenticatedHandler(googleGrantHandler))
http.Handle("/", AuthenticatedHandler(indexHandler))
+
+ if err := app.LoadConfig(context.Background()); err != nil {
+ panic(err)
+ }
}
// ContextHandler implements http.Handler
// this is used when setting up a new subscriber in the UI. Once set
// up, this code path should not be triggered.
if verify := r.FormValue("verify"); verify != "" {
- if verify == "@FITBIT_SUBSCRIBER_CODE@" {
+ if verify == app.Config.FitbitSubscriberCode {
w.WriteHeader(http.StatusNoContent)
} else {
w.WriteHeader(http.StatusNotFound)