Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加百度云支持 #63

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

SCFProxy 是一个基于多个云服务商提供的云函数及 API 网关实现 HTTP 代理、SOCKS 代理、反向代理的工具。

它当前支持将以下云服务商的函数计算服务转换为 HTTP 和 SOCKS 代理:

- 阿里云
- 腾讯云
- 华为云
- AWS(亚马逊网络服务)
- 百度云

# 安装

前往 [Release](https://github.com/shimmeris/SCFProxy/releases/) 页面下载对应系统压缩包即可。如仍需使用 Python
Expand Down
5 changes: 4 additions & 1 deletion cmd/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/shimmeris/SCFProxy/sdk"
"github.com/shimmeris/SCFProxy/sdk/provider/alibaba"
"github.com/shimmeris/SCFProxy/sdk/provider/aws"
"github.com/shimmeris/SCFProxy/sdk/provider/baidu"
"github.com/shimmeris/SCFProxy/sdk/provider/tencent"
)

Expand All @@ -21,7 +22,7 @@ const (

var (
allProviders = []string{"alibaba", "tencent", "aws"}
httpProviders = []string{"alibaba", "tencent", "aws"}
httpProviders = []string{"alibaba", "tencent", "aws", "baidu"}
socksProviders = []string{"alibaba", "tencent"}
reverseProviders = []string{"tencent"}
)
Expand All @@ -47,6 +48,8 @@ func listRegions(provider string) []string {
return tencent.Regions()
case "aws":
return aws.Regions()
case "baidu":
return baidu.Regions()
default:
return nil
}
Expand Down
31 changes: 31 additions & 0 deletions function/http/baidu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf8 -*-
import json
from base64 import b64decode, b64encode

import urllib3
urllib3.disable_warnings()


def handler(event: dict, context: dict):
data = event["body"]
kwargs = json.loads(data)
kwargs['body'] = b64decode(kwargs['body'])

http = urllib3.PoolManager(cert_reqs="CERT_NONE")
# Prohibit automatic redirect to avoid network errors such as connection reset
r = http.request(**kwargs, retries=False, decode_content=False)

headers = {k.lower(): v.lower() for k, v in r.headers.items()}

response = {
"headers": headers,
"status_code": r.status,
"content": b64encode(r._body).decode('utf-8')
}

return {
"isBase64Encoded": False,
"statusCode": 200,
"headers": {},
"body": json.dumps(response)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/aws/aws-sdk-go-v2/credentials v1.13.7
github.com/aws/aws-sdk-go-v2/service/apigateway v1.15.28
github.com/aws/aws-sdk-go-v2/service/lambda v1.26.2
github.com/baidubce/bce-sdk-go v0.9.191
github.com/google/martian/v3 v3.3.2
github.com/hashicorp/yamux v0.1.1
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.7
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.13.11/go.mod h1:TZSH7xLO7+phDtVi
github.com/aws/aws-sdk-go-v2/service/sts v1.17.7/go.mod h1:+lGbb3+1ugwKrNTWcf2RT05Xmp543B06zDFTwiTLp7I=
github.com/aws/smithy-go v1.13.5 h1:hgz0X/DX0dGqTYpGALqXJoRKRj5oQ7150i5FdTePzO8=
github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/baidubce/bce-sdk-go v0.9.191 h1:6bSwdrU4YKZDsbcN+KiZ2U/atW3omvCOWRdK3GoZGzI=
github.com/baidubce/bce-sdk-go v0.9.191/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
github.com/clbanning/mxj/v2 v2.5.7 h1:7q5lvUpaPF/WOkqgIDiwjBJaznaLCCBd78pi8ZyAnE0=
Expand Down
44 changes: 44 additions & 0 deletions sdk/provider/baidu/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package baidu

import (
"fmt"
"github.com/baidubce/bce-sdk-go/services/cfc"
)

type Provider struct {
region string
fClient *cfc.Client
}

func New(accessKeyId, accessKeySecret, region string) (*Provider, error) {

// 用户指定的Endpoint
endpoint := fmt.Sprintf("https://cfc.%s.baidubce.com", region)

// 初始化一个cfcClient
fClient, err := cfc.NewClient(accessKeyId, accessKeySecret, endpoint)
if err != nil {
return nil, err
}
provider := &Provider{
region: region,
fClient: fClient,
}
return provider, nil
}

func (p *Provider) Name() string {
return "baidu"
}

func (p *Provider) Region() string {
return p.region
}

func Regions() []string {
return []string{
"bj",
"gz",
"sz",
}
}