2018-11-15 12:00:08 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-11-14 10:50:15 +00:00
|
|
|
package satelliteweb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/satellite"
|
|
|
|
"storj.io/storj/pkg/satellite/satelliteauth"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/provider"
|
|
|
|
"storj.io/storj/pkg/satellite/satellitedb"
|
|
|
|
"storj.io/storj/pkg/satellite/satelliteweb/satelliteql"
|
|
|
|
"storj.io/storj/pkg/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config contains info needed for satellite account related services
|
|
|
|
type Config struct {
|
|
|
|
GatewayConfig
|
|
|
|
SatelliteAddr string `help:"satellite main endpoint" default:""`
|
|
|
|
DatabaseURL string `help:"" default:"sqlite3://$CONFDIR/satellitedb.db"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run implements Responsibility interface
|
|
|
|
func (c Config) Run(ctx context.Context, server *provider.Provider) error {
|
2018-11-21 15:51:43 +00:00
|
|
|
log := zap.NewExample()
|
2018-11-14 10:50:15 +00:00
|
|
|
|
|
|
|
// Create satellite DB
|
|
|
|
dbURL, err := utils.ParseURL(c.DatabaseURL)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
db, err := satellitedb.New(dbURL.Scheme, dbURL.Path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = db.CreateTables()
|
2018-11-21 15:51:43 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err.Error())
|
|
|
|
}
|
2018-11-14 10:50:15 +00:00
|
|
|
|
|
|
|
service, err := satellite.NewService(
|
2018-11-21 15:51:43 +00:00
|
|
|
log,
|
2018-11-14 10:50:15 +00:00
|
|
|
&satelliteauth.Hmac{Secret: []byte("my-suppa-secret-key")},
|
|
|
|
db,
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
creator := satelliteql.TypeCreator{}
|
|
|
|
err = creator.Create(service)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
schema, err := graphql.NewSchema(graphql.SchemaConfig{
|
|
|
|
Query: creator.RootQuery(),
|
|
|
|
Mutation: creator.RootMutation(),
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
go (&gateway{
|
2018-11-27 14:20:58 +00:00
|
|
|
log: log,
|
|
|
|
schema: schema,
|
|
|
|
service: service,
|
|
|
|
config: c.GatewayConfig,
|
2018-11-14 10:50:15 +00:00
|
|
|
}).run()
|
|
|
|
|
|
|
|
return server.Run(ctx)
|
|
|
|
}
|