|
@@ -57,6 +57,13 @@ type Subscription struct {
|
|
|
|
|
|
var ArgoSubscriptionId = "argo_zone_ent_tryout"
|
|
var ArgoSubscriptionId = "argo_zone_ent_tryout"
|
|
|
|
|
|
|
|
+const TOKEN_PREFIX = "#pt"
|
|
|
|
+
|
|
|
|
+var (
|
|
|
|
+ api *cloudflare.API
|
|
|
|
+ err error
|
|
|
|
+)
|
|
|
|
+
|
|
func (s *ZoneServer) GetArgoSettingSubscription(ctx context.Context, request *zone.IdRequest) (*zone.ArgoSetting, error) {
|
|
func (s *ZoneServer) GetArgoSettingSubscription(ctx context.Context, request *zone.IdRequest) (*zone.ArgoSetting, error) {
|
|
|
|
|
|
//设置HTTP请求
|
|
//设置HTTP请求
|
|
@@ -65,10 +72,12 @@ func (s *ZoneServer) GetArgoSettingSubscription(ctx context.Context, request *zo
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
-
|
|
|
|
- req.Header.Add("X-Auth-Key", request.GetApiKey())
|
|
|
|
- req.Header.Add("X-Auth-Email", request.GetApiEmail())
|
|
|
|
-
|
|
|
|
|
|
+ if strings.HasPrefix(request.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ req.Header.Add("Authorization", ApiToken2Authorization(request.GetApiKey()[3:]))
|
|
|
|
+ } else {
|
|
|
|
+ req.Header.Add("X-Auth-Key", request.GetApiKey())
|
|
|
|
+ req.Header.Add("X-Auth-Email", request.GetApiEmail())
|
|
|
|
+ }
|
|
//执行HTTP请求
|
|
//执行HTTP请求
|
|
resp, err := client.Do(req)
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -148,10 +157,12 @@ func (s *ZoneServer) CreateArgoSettingSubscription(ctx context.Context, request
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
-
|
|
|
|
- req.Header.Add("X-Auth-Key", request.GetApiKey())
|
|
|
|
- req.Header.Add("X-Auth-Email", request.GetApiEmail())
|
|
|
|
-
|
|
|
|
|
|
+ if strings.HasPrefix(request.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ req.Header.Add("Authorization", ApiToken2Authorization(request.GetApiKey()[3:]))
|
|
|
|
+ } else {
|
|
|
|
+ req.Header.Add("X-Auth-Key", request.GetApiKey())
|
|
|
|
+ req.Header.Add("X-Auth-Email", request.GetApiEmail())
|
|
|
|
+ }
|
|
//执行HTTP请求
|
|
//执行HTTP请求
|
|
resp, err := client.Do(req)
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -182,8 +193,11 @@ func (s *ZoneServer) CreateArgoSettingSubscription(ctx context.Context, request
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) UpdateArgoSetting(ctx context.Context, requestCloudflare *zone.UpdateArgoRequestCloudflare) (*zone.ArgoSetting, error) {
|
|
func (s *ZoneServer) UpdateArgoSetting(ctx context.Context, requestCloudflare *zone.UpdateArgoRequestCloudflare) (*zone.ArgoSetting, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -199,8 +213,11 @@ func (s *ZoneServer) UpdateArgoSetting(ctx context.Context, requestCloudflare *z
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) GetArgoSetting(ctx context.Context, requestCloudflare *zone.IdRequest) (*zone.ArgoSetting, error) {
|
|
func (s *ZoneServer) GetArgoSetting(ctx context.Context, requestCloudflare *zone.IdRequest) (*zone.ArgoSetting, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -214,8 +231,11 @@ func (s *ZoneServer) GetArgoSetting(ctx context.Context, requestCloudflare *zone
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) ZoneIDByNameCloudflare(ctx context.Context, requestCloudflare *zone.ZoneIDByNameRequestCloudflare) (*zone.ZoneIDByNameReplyCloudflare, error) {
|
|
func (s *ZoneServer) ZoneIDByNameCloudflare(ctx context.Context, requestCloudflare *zone.ZoneIDByNameRequestCloudflare) (*zone.ZoneIDByNameReplyCloudflare, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -229,8 +249,11 @@ func (s *ZoneServer) ZoneIDByNameCloudflare(ctx context.Context, requestCloudfla
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) ZoneDetails(ctx context.Context, requestCloudflare *zone.ZoneDetailsRequestCloudflare) (*zone.ZoneDetailsReplyCloudflare, error) {
|
|
func (s *ZoneServer) ZoneDetails(ctx context.Context, requestCloudflare *zone.ZoneDetailsRequestCloudflare) (*zone.ZoneDetailsReplyCloudflare, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -248,8 +271,11 @@ func (s *ZoneServer) ZoneDetails(ctx context.Context, requestCloudflare *zone.Zo
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) GetZones(ctx context.Context, requestCloudflare *zone.GetZonesRequestCloudflare) (*zone.GetZonesReplyCloudflare, error) {
|
|
func (s *ZoneServer) GetZones(ctx context.Context, requestCloudflare *zone.GetZonesRequestCloudflare) (*zone.GetZonesReplyCloudflare, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -269,10 +295,13 @@ func (s *ZoneServer) GetZones(ctx context.Context, requestCloudflare *zone.GetZo
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) ListZones(ctx context.Context, requestCloudflare *zone.ListZonesRequestCloudflare) (*zone.ZonesList, error) {
|
|
func (s *ZoneServer) ListZones(ctx context.Context, requestCloudflare *zone.ListZonesRequestCloudflare) (*zone.ZonesList, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
- return nil, err
|
|
|
|
|
|
+ return nil, fmt.Errorf("failed to initialize Cloudflare API: %w", err)
|
|
}
|
|
}
|
|
|
|
|
|
ctxAPI := context.Background()
|
|
ctxAPI := context.Background()
|
|
@@ -291,8 +320,11 @@ func (s *ZoneServer) ListZones(ctx context.Context, requestCloudflare *zone.List
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) ListZonesByAccountId(ctx context.Context, requestCloudflare *zone.ListZonesByAccountIdRequestCloudflare) (*zone.ZonesList, error) {
|
|
func (s *ZoneServer) ListZonesByAccountId(ctx context.Context, requestCloudflare *zone.ListZonesByAccountIdRequestCloudflare) (*zone.ZonesList, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -313,8 +345,11 @@ func (s *ZoneServer) ListZonesByAccountId(ctx context.Context, requestCloudflare
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) EditZone(ctx context.Context, requestCloudflare *zone.EditZoneRequestCloudflare) (*zone.EditZoneReplyCloudflare, error) {
|
|
func (s *ZoneServer) EditZone(ctx context.Context, requestCloudflare *zone.EditZoneRequestCloudflare) (*zone.EditZoneReplyCloudflare, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -350,8 +385,11 @@ func (s *ZoneServer) EditZone(ctx context.Context, requestCloudflare *zone.EditZ
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) DeleteZone(ctx context.Context, requestCloudflare *zone.DeleteZoneRequestCloudflare) (*zone.DeleteZoneReplyCloudflare, error) {
|
|
func (s *ZoneServer) DeleteZone(ctx context.Context, requestCloudflare *zone.DeleteZoneRequestCloudflare) (*zone.DeleteZoneReplyCloudflare, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -370,8 +408,11 @@ func (s *ZoneServer) DeleteZone(ctx context.Context, requestCloudflare *zone.Del
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) CreateZone(ctx context.Context, requestCloudflare *zone.CreateZoneRequestCloudflare) (*zone.CreateZoneReplyCloudflare, error) {
|
|
func (s *ZoneServer) CreateZone(ctx context.Context, requestCloudflare *zone.CreateZoneRequestCloudflare) (*zone.CreateZoneReplyCloudflare, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -395,8 +436,11 @@ func (s *ZoneServer) CreateZone(ctx context.Context, requestCloudflare *zone.Cre
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) SetZonePlan(ctx context.Context, requestCloudflare *zone.SetZonePlanRequestCloudflare) (*zone.SetZonePlanReplyCloudflare, error) {
|
|
func (s *ZoneServer) SetZonePlan(ctx context.Context, requestCloudflare *zone.SetZonePlanRequestCloudflare) (*zone.SetZonePlanReplyCloudflare, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -413,8 +457,11 @@ func (s *ZoneServer) SetZonePlan(ctx context.Context, requestCloudflare *zone.Se
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) ActivationCheck(ctx context.Context, requestCloudflare *zone.ActivationCheckRequestCloudflare) (*zone.ActivationCheckReplyCloudflare, error) {
|
|
func (s *ZoneServer) ActivationCheck(ctx context.Context, requestCloudflare *zone.ActivationCheckRequestCloudflare) (*zone.ActivationCheckReplyCloudflare, error) {
|
|
-
|
|
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -452,7 +499,11 @@ var phaseMap = map[zone.Phase]string{
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) ListZoneRuleSets(ctx context.Context, requestCloudflare *zone.ListZoneRuleSetsRequestCloudflare) (*zone.RuleSetList, error) {
|
|
func (s *ZoneServer) ListZoneRuleSets(ctx context.Context, requestCloudflare *zone.ListZoneRuleSetsRequestCloudflare) (*zone.RuleSetList, error) {
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -471,7 +522,11 @@ func (s *ZoneServer) ListZoneRuleSets(ctx context.Context, requestCloudflare *zo
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) CreateZoneRuleSet(ctx context.Context, requestCloudflare *zone.CreateZoneRuleSetRequestCloudflare) (*zone.CreateZoneRuleSetReplyCloudflare, error) {
|
|
func (s *ZoneServer) CreateZoneRuleSet(ctx context.Context, requestCloudflare *zone.CreateZoneRuleSetRequestCloudflare) (*zone.CreateZoneRuleSetReplyCloudflare, error) {
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -499,7 +554,11 @@ func (s *ZoneServer) CreateZoneRuleSet(ctx context.Context, requestCloudflare *z
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) DeleteZoneRuleSet(ctx context.Context, requestCloudflare *zone.DeleteZoneRuleSetRequestCloudflare) (*zone.DeleteZoneRuleSetReplyCloudflare, error) {
|
|
func (s *ZoneServer) DeleteZoneRuleSet(ctx context.Context, requestCloudflare *zone.DeleteZoneRuleSetRequestCloudflare) (*zone.DeleteZoneRuleSetReplyCloudflare, error) {
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -513,7 +572,11 @@ func (s *ZoneServer) DeleteZoneRuleSet(ctx context.Context, requestCloudflare *z
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) UpdateRuleSetByRuleSetId(ctx context.Context, requestCloudflare *zone.UpdateRuleSetByRuleSetIdRequestCloudflare) (*zone.RuleSet, error) {
|
|
func (s *ZoneServer) UpdateRuleSetByRuleSetId(ctx context.Context, requestCloudflare *zone.UpdateRuleSetByRuleSetIdRequestCloudflare) (*zone.RuleSet, error) {
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -539,7 +602,11 @@ func (s *ZoneServer) UpdateRuleSetByRuleSetId(ctx context.Context, requestCloudf
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) GetRuleSet(ctx context.Context, requestCloudflare *zone.GetRuleSetRequestCloudflare) (*zone.RuleList, error) {
|
|
func (s *ZoneServer) GetRuleSet(ctx context.Context, requestCloudflare *zone.GetRuleSetRequestCloudflare) (*zone.RuleList, error) {
|
|
- api, err := cloudflare.New(requestCloudflare.ApiKey, requestCloudflare.ApiEmail)
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -571,7 +638,11 @@ func (s *ZoneServer) GetRuleSet(ctx context.Context, requestCloudflare *zone.Get
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) UpdateRuleSet(ctx context.Context, requestCloudflare *zone.UpdateRuleSetRequestCloudflare) (*zone.RuleList, error) {
|
|
func (s *ZoneServer) UpdateRuleSet(ctx context.Context, requestCloudflare *zone.UpdateRuleSetRequestCloudflare) (*zone.RuleList, error) {
|
|
- api, err := cloudflare.New(requestCloudflare.ApiKey, requestCloudflare.ApiEmail)
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -642,7 +713,11 @@ func (s *ZoneServer) UpdateRuleSet(ctx context.Context, requestCloudflare *zone.
|
|
//PageRule CURD
|
|
//PageRule CURD
|
|
|
|
|
|
func (s *ZoneServer) ListPageRule(ctx context.Context, requestCloudflare *zone.ListPageRuleRequestCloudflare) (*zone.PageRuleList, error) {
|
|
func (s *ZoneServer) ListPageRule(ctx context.Context, requestCloudflare *zone.ListPageRuleRequestCloudflare) (*zone.PageRuleList, error) {
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -659,7 +734,11 @@ func (s *ZoneServer) ListPageRule(ctx context.Context, requestCloudflare *zone.L
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) CreatePageRule(ctx context.Context, requestCloudflare *zone.CreatePageRuleRequestCloudflare) (*zone.PageRule, error) {
|
|
func (s *ZoneServer) CreatePageRule(ctx context.Context, requestCloudflare *zone.CreatePageRuleRequestCloudflare) (*zone.PageRule, error) {
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -676,7 +755,11 @@ func (s *ZoneServer) CreatePageRule(ctx context.Context, requestCloudflare *zone
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) UpdatePageRule(ctx context.Context, requestCloudflare *zone.UpdatePageRuleRequestCloudflare) (*zone.PageRule, error) {
|
|
func (s *ZoneServer) UpdatePageRule(ctx context.Context, requestCloudflare *zone.UpdatePageRuleRequestCloudflare) (*zone.PageRule, error) {
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -693,7 +776,11 @@ func (s *ZoneServer) UpdatePageRule(ctx context.Context, requestCloudflare *zone
|
|
}
|
|
}
|
|
|
|
|
|
func (s *ZoneServer) DeletePageRule(ctx context.Context, requestCloudflare *zone.DeletePageRuleRequestCloudflare) (*zone.PageRule, error) {
|
|
func (s *ZoneServer) DeletePageRule(ctx context.Context, requestCloudflare *zone.DeletePageRuleRequestCloudflare) (*zone.PageRule, error) {
|
|
- api, err := cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ api, err = cloudflare.NewWithAPIToken(requestCloudflare.GetApiKey()[3:])
|
|
|
|
+ } else {
|
|
|
|
+ api, err = cloudflare.New(requestCloudflare.GetApiKey(), requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
@@ -751,9 +838,12 @@ func (s *ZoneServer) UpdatePageRulesPriorities(ctx context.Context, requestCloud
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
- req.Header.Add("X-Auth-Key", requestCloudflare.GetApiKey())
|
|
|
|
- req.Header.Add("X-Auth-Email", requestCloudflare.GetApiEmail())
|
|
|
|
-
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ req.Header.Add("Authorization", ApiToken2Authorization(requestCloudflare.GetApiKey()[3:]))
|
|
|
|
+ } else {
|
|
|
|
+ req.Header.Add("X-Auth-Key", requestCloudflare.GetApiKey())
|
|
|
|
+ req.Header.Add("X-Auth-Email", requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
//执行HTTP请求
|
|
//执行HTTP请求
|
|
resp, err := client.Do(req)
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -802,10 +892,13 @@ func (s *ZoneServer) SetSmartTieredCache(ctx context.Context, requestCloudflare
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
- req.Header.Add("X-Auth-Key", requestCloudflare.GetApiKey())
|
|
|
|
req.Header.Add("Content-Type", "application/json")
|
|
req.Header.Add("Content-Type", "application/json")
|
|
- req.Header.Add("X-Auth-Email", requestCloudflare.GetApiEmail())
|
|
|
|
-
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ req.Header.Add("Authorization", ApiToken2Authorization(requestCloudflare.GetApiKey()[3:]))
|
|
|
|
+ } else {
|
|
|
|
+ req.Header.Add("X-Auth-Key", requestCloudflare.GetApiKey())
|
|
|
|
+ req.Header.Add("X-Auth-Email", requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
//执行HTTP请求
|
|
//执行HTTP请求
|
|
resp, err := client.Do(req)
|
|
resp, err := client.Do(req)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -854,9 +947,13 @@ func (s *ZoneServer) UpdateAlwaysUseHttps(ctx context.Context, requestCloudflare
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
}
|
|
}
|
|
- req.Header.Add("X-Auth-Key", requestCloudflare.GetApiKey())
|
|
|
|
req.Header.Add("Content-Type", "application/json")
|
|
req.Header.Add("Content-Type", "application/json")
|
|
- req.Header.Add("X-Auth-Email", requestCloudflare.GetApiEmail())
|
|
|
|
|
|
+ if strings.HasPrefix(requestCloudflare.GetApiKey(), TOKEN_PREFIX) {
|
|
|
|
+ req.Header.Add("Authorization", ApiToken2Authorization(requestCloudflare.GetApiKey()[3:]))
|
|
|
|
+ } else {
|
|
|
|
+ req.Header.Add("X-Auth-Key", requestCloudflare.GetApiKey())
|
|
|
|
+ req.Header.Add("X-Auth-Email", requestCloudflare.GetApiEmail())
|
|
|
|
+ }
|
|
|
|
|
|
//执行HTTP请求
|
|
//执行HTTP请求
|
|
resp, err := client.Do(req)
|
|
resp, err := client.Do(req)
|