Initial commit
This commit is contained in:
36
domains/yandex/v1/auth.go
Normal file
36
domains/yandex/v1/auth.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// Yandex Disk File Pusher
|
||||
// Copyright (c) 2019 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package yandexv1
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// authorize autorizes user and saves token to config
|
||||
// Autorization made of two steps: providing user URL to create token and
|
||||
// getting token from provided code
|
||||
func authorize() {
|
||||
if !checkAuth() {
|
||||
baseURL := "https://oauth.yandex.ru/authorize?response_type=code&client_id={{ client_id }}"
|
||||
baseURL += "&device_id={{ device_id }}&device_name=yapusher-cli&force_confirm=yes"
|
||||
|
||||
baseURL = strings.Replace(baseURL, "{{ client_id }}", YANDEX_APPID, 1)
|
||||
baseURL = strings.Replace(baseURL, "{{ device_id }}", c.Config.DeviceID, 1)
|
||||
|
||||
dlog.Info().Msg("Please open in your browser this URL and authorize the app. After getting the code restart the app with -authCode param (see -h for details).")
|
||||
dlog.Info().Msgf("Auth URL: %s", baseURL)
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
// checkAuth detects if we have authorized already
|
||||
func checkAuth() bool {
|
||||
if c.Config.Token.AccessToken != "" {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
39
domains/yandex/v1/exported.go
Normal file
39
domains/yandex/v1/exported.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Yandex Disk File Pusher
|
||||
// Copyright (c) 2019 Vladimir "fat0troll" Hodakov
|
||||
|
||||
package yandexv1
|
||||
|
||||
import (
|
||||
"github.com/fat0troll/yapusher/internal/context"
|
||||
"github.com/rs/zerolog"
|
||||
"gitlab.com/pztrn/flagger"
|
||||
)
|
||||
|
||||
const YANDEX_APPID = "7d8a0561fdc44c05bb6695b464403f9c"
|
||||
|
||||
var (
|
||||
c *context.Context
|
||||
dlog zerolog.Logger
|
||||
)
|
||||
|
||||
// New initializes package
|
||||
func New(cc *context.Context) {
|
||||
c = cc
|
||||
dlog = c.Logger.With().Str("domain", "yandex").Int("version", 1).Logger()
|
||||
|
||||
_ = c.Flagger.AddFlag(&flagger.Flag{
|
||||
Name: "authCode",
|
||||
Description: "Auth code obtained from Yandex (seven digits).",
|
||||
Type: "int",
|
||||
DefaultValue: 0000000,
|
||||
})
|
||||
|
||||
dlog.Info().Msg("Domain initialized")
|
||||
}
|
||||
|
||||
// Process handles authorization and files
|
||||
func Process() {
|
||||
if !checkAuth() {
|
||||
authorize()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user