mirror of
https://github.com/vwxyzjn/portwarden
synced 2026-01-06 17:13:13 +00:00
API-6 # Save work
This commit is contained in:
@@ -7,12 +7,18 @@ import (
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-redis/redis"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
drive "google.golang.org/api/drive/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
GoogleDriveAppConfig *oauth2.Config
|
||||
RedisClient *redis.Client
|
||||
)
|
||||
|
||||
type PortwardenServer struct {
|
||||
Port int
|
||||
Router *gin.Engine
|
||||
@@ -26,11 +32,24 @@ func (ps *PortwardenServer) Run() {
|
||||
var err error
|
||||
ps.GoogleDriveContext = context.Background()
|
||||
ps.GoogleDriveAppConfig, err = google.ConfigFromJSON(ps.GoogleDriveAppCredentials, "https://www.googleapis.com/auth/userinfo.profile", drive.DriveScope)
|
||||
GoogleDriveAppConfig = ps.GoogleDriveAppConfig // quick hack
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to parse client secret file to config: %v", err)
|
||||
}
|
||||
// ps.GoogleClient = GetClient(ps.GoogleDriveContext, ps.GoogleDriveAppConfig)
|
||||
|
||||
// Setup Redis
|
||||
RedisClient := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password set
|
||||
DB: 0, // use default DB
|
||||
})
|
||||
|
||||
_, err = RedisClient.Ping().Result()
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to parse client secret file to config: %v", err)
|
||||
}
|
||||
|
||||
ps.Router = gin.Default()
|
||||
ps.Router.Use(cors.Default())
|
||||
|
||||
@@ -41,6 +60,8 @@ func (ps *PortwardenServer) Run() {
|
||||
ps.Router.POST("/encrypt", EncryptBackupHandler)
|
||||
ps.Router.POST("/decrypt", DecryptBackupHandler)
|
||||
ps.Router.GET("/gdrive/loginUrl", ps.GetGoogleDriveLoginURLHandler)
|
||||
|
||||
ps.Router.Use(TokenAuthMiddleware())
|
||||
ps.Router.GET("/gdrive/login", ps.GetGoogleDriveLoginHandler)
|
||||
|
||||
ps.Router.Run(":" + strconv.Itoa(ps.Port))
|
||||
|
||||
Reference in New Issue
Block a user