mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-31 14:08:06 +08:00
feat: 适配世纪互联版本 OneDrive (#3763)
This commit is contained in:
parent
3804942ae4
commit
42828d0a48
@ -17,11 +17,11 @@ type cosClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewCosClient(vars map[string]interface{}) (*cosClient, error) {
|
func NewCosClient(vars map[string]interface{}) (*cosClient, error) {
|
||||||
region := loadParamFromVars("region", true, vars)
|
region := loadParamFromVars("region", vars)
|
||||||
accessKey := loadParamFromVars("accessKey", true, vars)
|
accessKey := loadParamFromVars("accessKey", vars)
|
||||||
secretKey := loadParamFromVars("secretKey", true, vars)
|
secretKey := loadParamFromVars("secretKey", vars)
|
||||||
bucket := loadParamFromVars("bucket", true, vars)
|
bucket := loadParamFromVars("bucket", vars)
|
||||||
scType := loadParamFromVars("scType", true, vars)
|
scType := loadParamFromVars("scType", vars)
|
||||||
if len(scType) == 0 {
|
if len(scType) == 0 {
|
||||||
scType = "Standard"
|
scType = "Standard"
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/1Panel-dev/1Panel/backend/global"
|
"github.com/1Panel-dev/1Panel/backend/global"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadParamFromVars(key string, isString bool, vars map[string]interface{}) string {
|
func loadParamFromVars(key string, vars map[string]interface{}) string {
|
||||||
if _, ok := vars[key]; !ok {
|
if _, ok := vars[key]; !ok {
|
||||||
if key != "bucket" {
|
if key != "bucket" {
|
||||||
global.LOG.Errorf("load param %s from vars failed, err: not exist!", key)
|
global.LOG.Errorf("load param %s from vars failed, err: not exist!", key)
|
||||||
|
@ -17,10 +17,10 @@ type kodoClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewKodoClient(vars map[string]interface{}) (*kodoClient, error) {
|
func NewKodoClient(vars map[string]interface{}) (*kodoClient, error) {
|
||||||
accessKey := loadParamFromVars("accessKey", true, vars)
|
accessKey := loadParamFromVars("accessKey", vars)
|
||||||
secretKey := loadParamFromVars("secretKey", true, vars)
|
secretKey := loadParamFromVars("secretKey", vars)
|
||||||
bucket := loadParamFromVars("bucket", true, vars)
|
bucket := loadParamFromVars("bucket", vars)
|
||||||
domain := loadParamFromVars("domain", true, vars)
|
domain := loadParamFromVars("domain", vars)
|
||||||
|
|
||||||
conn := auth.New(accessKey, secretKey)
|
conn := auth.New(accessKey, secretKey)
|
||||||
cfg := storage.Config{
|
cfg := storage.Config{
|
||||||
|
@ -14,7 +14,7 @@ type localClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewLocalClient(vars map[string]interface{}) (*localClient, error) {
|
func NewLocalClient(vars map[string]interface{}) (*localClient, error) {
|
||||||
dir := loadParamFromVars("dir", true, vars)
|
dir := loadParamFromVars("dir", vars)
|
||||||
return &localClient{dir: dir}, nil
|
return &localClient{dir: dir}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,10 +19,10 @@ type minIoClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewMinIoClient(vars map[string]interface{}) (*minIoClient, error) {
|
func NewMinIoClient(vars map[string]interface{}) (*minIoClient, error) {
|
||||||
endpoint := loadParamFromVars("endpoint", true, vars)
|
endpoint := loadParamFromVars("endpoint", vars)
|
||||||
accessKeyID := loadParamFromVars("accessKey", true, vars)
|
accessKeyID := loadParamFromVars("accessKey", vars)
|
||||||
secretAccessKey := loadParamFromVars("secretKey", true, vars)
|
secretAccessKey := loadParamFromVars("secretKey", vars)
|
||||||
bucket := loadParamFromVars("bucket", true, vars)
|
bucket := loadParamFromVars("bucket", vars)
|
||||||
ssl := strings.Split(endpoint, ":")[0]
|
ssl := strings.Split(endpoint, ":")[0]
|
||||||
if len(ssl) == 0 || (ssl != "https" && ssl != "http") {
|
if len(ssl) == 0 || (ssl != "https" && ssl != "http") {
|
||||||
return nil, constant.ErrInvalidParams
|
return nil, constant.ErrInvalidParams
|
||||||
|
@ -25,7 +25,8 @@ type oneDriveClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewOneDriveClient(vars map[string]interface{}) (*oneDriveClient, error) {
|
func NewOneDriveClient(vars map[string]interface{}) (*oneDriveClient, error) {
|
||||||
token := loadParamFromVars("accessToken", true, vars)
|
token := loadParamFromVars("accessToken", vars)
|
||||||
|
isCN := loadParamFromVars("isCN", vars)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ts := oauth2.StaticTokenSource(
|
ts := oauth2.StaticTokenSource(
|
||||||
&oauth2.Token{AccessToken: token},
|
&oauth2.Token{AccessToken: token},
|
||||||
@ -33,6 +34,9 @@ func NewOneDriveClient(vars map[string]interface{}) (*oneDriveClient, error) {
|
|||||||
tc := oauth2.NewClient(ctx, ts)
|
tc := oauth2.NewClient(ctx, ts)
|
||||||
|
|
||||||
client := odsdk.NewClient(tc)
|
client := odsdk.NewClient(tc)
|
||||||
|
if isCN == "true" {
|
||||||
|
client.BaseURL, _ = url.Parse("https://microsoftgraph.chinacloudapi.cn/v1.0/")
|
||||||
|
}
|
||||||
return &oneDriveClient{client: *client}, nil
|
return &oneDriveClient{client: *client}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,18 +196,23 @@ func (o *oneDriveClient) loadIDByPath(path string) (string, error) {
|
|||||||
|
|
||||||
func RefreshToken(grantType string, varMap map[string]interface{}) (string, string, error) {
|
func RefreshToken(grantType string, varMap map[string]interface{}) (string, string, error) {
|
||||||
data := url.Values{}
|
data := url.Values{}
|
||||||
data.Set("client_id", loadParamFromVars("client_id", true, varMap))
|
isCN := loadParamFromVars("isCN", varMap)
|
||||||
data.Set("client_secret", loadParamFromVars("client_secret", true, varMap))
|
data.Set("client_id", loadParamFromVars("client_id", varMap))
|
||||||
|
data.Set("client_secret", loadParamFromVars("client_secret", varMap))
|
||||||
if grantType == "refresh_token" {
|
if grantType == "refresh_token" {
|
||||||
data.Set("grant_type", "refresh_token")
|
data.Set("grant_type", "refresh_token")
|
||||||
data.Set("refresh_token", loadParamFromVars("refresh_token", true, varMap))
|
data.Set("refresh_token", loadParamFromVars("refresh_token", varMap))
|
||||||
} else {
|
} else {
|
||||||
data.Set("grant_type", "authorization_code")
|
data.Set("grant_type", "authorization_code")
|
||||||
data.Set("code", loadParamFromVars("code", true, varMap))
|
data.Set("code", loadParamFromVars("code", varMap))
|
||||||
}
|
}
|
||||||
data.Set("redirect_uri", loadParamFromVars("redirect_uri", true, varMap))
|
data.Set("redirect_uri", loadParamFromVars("redirect_uri", varMap))
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
req, err := http.NewRequest("POST", "https://login.microsoftonline.com/common/oauth2/v2.0/token", strings.NewReader(data.Encode()))
|
url := "https://login.microsoftonline.com/common/oauth2/v2.0/token"
|
||||||
|
if isCN == "true" {
|
||||||
|
url = "https://login.chinacloudapi.cn/common/oauth2/v2.0/token"
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", url, strings.NewReader(data.Encode()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", fmt.Errorf("new http post client for access token failed, err: %v", err)
|
return "", "", fmt.Errorf("new http post client for access token failed, err: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,11 @@ type ossClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewOssClient(vars map[string]interface{}) (*ossClient, error) {
|
func NewOssClient(vars map[string]interface{}) (*ossClient, error) {
|
||||||
endpoint := loadParamFromVars("endpoint", true, vars)
|
endpoint := loadParamFromVars("endpoint", vars)
|
||||||
accessKey := loadParamFromVars("accessKey", true, vars)
|
accessKey := loadParamFromVars("accessKey", vars)
|
||||||
secretKey := loadParamFromVars("secretKey", true, vars)
|
secretKey := loadParamFromVars("secretKey", vars)
|
||||||
bucketStr := loadParamFromVars("bucket", true, vars)
|
bucketStr := loadParamFromVars("bucket", vars)
|
||||||
scType := loadParamFromVars("scType", true, vars)
|
scType := loadParamFromVars("scType", vars)
|
||||||
if len(scType) == 0 {
|
if len(scType) == 0 {
|
||||||
scType = "Standard"
|
scType = "Standard"
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@ type s3Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewS3Client(vars map[string]interface{}) (*s3Client, error) {
|
func NewS3Client(vars map[string]interface{}) (*s3Client, error) {
|
||||||
accessKey := loadParamFromVars("accessKey", true, vars)
|
accessKey := loadParamFromVars("accessKey", vars)
|
||||||
secretKey := loadParamFromVars("secretKey", true, vars)
|
secretKey := loadParamFromVars("secretKey", vars)
|
||||||
endpoint := loadParamFromVars("endpoint", true, vars)
|
endpoint := loadParamFromVars("endpoint", vars)
|
||||||
region := loadParamFromVars("region", true, vars)
|
region := loadParamFromVars("region", vars)
|
||||||
bucket := loadParamFromVars("bucket", true, vars)
|
bucket := loadParamFromVars("bucket", vars)
|
||||||
scType := loadParamFromVars("scType", true, vars)
|
scType := loadParamFromVars("scType", vars)
|
||||||
if len(scType) == 0 {
|
if len(scType) == 0 {
|
||||||
scType = "Standard"
|
scType = "Standard"
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ type sftpClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewSftpClient(vars map[string]interface{}) (*sftpClient, error) {
|
func NewSftpClient(vars map[string]interface{}) (*sftpClient, error) {
|
||||||
address := loadParamFromVars("address", true, vars)
|
address := loadParamFromVars("address", vars)
|
||||||
port := loadParamFromVars("port", false, vars)
|
port := loadParamFromVars("port", vars)
|
||||||
password := loadParamFromVars("password", true, vars)
|
password := loadParamFromVars("password", vars)
|
||||||
username := loadParamFromVars("username", true, vars)
|
username := loadParamFromVars("username", vars)
|
||||||
bucket := loadParamFromVars("bucket", true, vars)
|
bucket := loadParamFromVars("bucket", vars)
|
||||||
|
|
||||||
auth := []ssh.AuthMethod{ssh.Password(password)}
|
auth := []ssh.AuthMethod{ssh.Password(password)}
|
||||||
clientConfig := &ssh.ClientConfig{
|
clientConfig := &ssh.ClientConfig{
|
||||||
|
@ -17,11 +17,11 @@ type webDAVClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewWebDAVClient(vars map[string]interface{}) (*webDAVClient, error) {
|
func NewWebDAVClient(vars map[string]interface{}) (*webDAVClient, error) {
|
||||||
address := loadParamFromVars("address", true, vars)
|
address := loadParamFromVars("address", vars)
|
||||||
port := loadParamFromVars("port", true, vars)
|
port := loadParamFromVars("port", vars)
|
||||||
password := loadParamFromVars("password", true, vars)
|
password := loadParamFromVars("password", vars)
|
||||||
username := loadParamFromVars("username", true, vars)
|
username := loadParamFromVars("username", vars)
|
||||||
bucket := loadParamFromVars("bucket", true, vars)
|
bucket := loadParamFromVars("bucket", vars)
|
||||||
|
|
||||||
url := fmt.Sprintf("%s:%s", address, port)
|
url := fmt.Sprintf("%s:%s", address, port)
|
||||||
if len(port) == 0 {
|
if len(port) == 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user