-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
227 changed files
with
13,917 additions
and
2,973 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,6 @@ staticcheck: | |
|
||
generate: | ||
go generate ./storagev2/ | ||
go generate ./iam/ | ||
go generate ./media/ | ||
go generate ./audit/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule api-specs
updated
52 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// THIS FILE IS GENERATED BY api-generator, DO NOT EDIT DIRECTLY! | ||
|
||
package apis | ||
|
||
import ( | ||
"context" | ||
querylog "github.com/qiniu/go-sdk/v7/audit/apis/query_log" | ||
auth "github.com/qiniu/go-sdk/v7/auth" | ||
uplog "github.com/qiniu/go-sdk/v7/internal/uplog" | ||
errors "github.com/qiniu/go-sdk/v7/storagev2/errors" | ||
httpclient "github.com/qiniu/go-sdk/v7/storagev2/http_client" | ||
region "github.com/qiniu/go-sdk/v7/storagev2/region" | ||
uptoken "github.com/qiniu/go-sdk/v7/storagev2/uptoken" | ||
"net/url" | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
type innerQueryLogRequest querylog.Request | ||
|
||
func (query *innerQueryLogRequest) buildQuery() (url.Values, error) { | ||
allQuery := make(url.Values) | ||
if query.StartTime != "" { | ||
allQuery.Set("start_time", query.StartTime) | ||
} else { | ||
return nil, errors.MissingRequiredFieldError{Name: "StartTime"} | ||
} | ||
if query.EndTime != "" { | ||
allQuery.Set("end_time", query.EndTime) | ||
} else { | ||
return nil, errors.MissingRequiredFieldError{Name: "EndTime"} | ||
} | ||
if query.ServiceName != "" { | ||
allQuery.Set("service_name", query.ServiceName) | ||
} | ||
if len(query.EventNames) > 0 { | ||
for _, value := range query.EventNames { | ||
allQuery.Add("event_names", value) | ||
} | ||
} | ||
if query.PrincipalId != "" { | ||
allQuery.Set("principal_id", query.PrincipalId) | ||
} | ||
if query.AccessKeyId != "" { | ||
allQuery.Set("access_key_id", query.AccessKeyId) | ||
} | ||
if query.Limit != 0 { | ||
allQuery.Set("limit", strconv.FormatInt(query.Limit, 10)) | ||
} | ||
if query.NextMark != "" { | ||
allQuery.Set("next_mark", query.NextMark) | ||
} | ||
return allQuery, nil | ||
} | ||
|
||
type QueryLogRequest = querylog.Request | ||
type QueryLogResponse = querylog.Response | ||
|
||
// 审计日志查询 | ||
func (audit *Audit) QueryLog(ctx context.Context, request *QueryLogRequest, options *Options) (*QueryLogResponse, error) { | ||
if options == nil { | ||
options = &Options{} | ||
} | ||
innerRequest := (*innerQueryLogRequest)(request) | ||
serviceNames := []region.ServiceName{region.ServiceApi} | ||
if innerRequest.Credentials == nil && audit.client.GetCredentials() == nil { | ||
return nil, errors.MissingRequiredFieldError{Name: "Credentials"} | ||
} | ||
pathSegments := make([]string, 0, 2) | ||
pathSegments = append(pathSegments, "audit", "log-query") | ||
path := "/" + strings.Join(pathSegments, "/") | ||
var rawQuery string | ||
if query, err := innerRequest.buildQuery(); err != nil { | ||
return nil, err | ||
} else { | ||
rawQuery += query.Encode() | ||
} | ||
uplogInterceptor, err := uplog.NewRequestUplog("queryLog", "", "", func() (string, error) { | ||
credentials := innerRequest.Credentials | ||
if credentials == nil { | ||
credentials = audit.client.GetCredentials() | ||
} | ||
putPolicy, err := uptoken.NewPutPolicy("", time.Now().Add(time.Hour)) | ||
if err != nil { | ||
return "", err | ||
} | ||
return uptoken.NewSigner(putPolicy, credentials).GetUpToken(ctx) | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req := httpclient.Request{Method: "GET", ServiceNames: serviceNames, Path: path, RawQuery: rawQuery, Endpoints: options.OverwrittenEndpoints, Region: options.OverwrittenRegion, Interceptors: []httpclient.Interceptor{uplogInterceptor}, AuthType: auth.TokenQiniu, Credentials: innerRequest.Credentials, BufferResponse: true, OnRequestProgress: options.OnRequestProgress} | ||
if options.OverwrittenEndpoints == nil && options.OverwrittenRegion == nil && audit.client.GetRegions() == nil { | ||
bucketHosts := httpclient.DefaultBucketHosts() | ||
|
||
req.Region = audit.client.GetAllRegions() | ||
if req.Region == nil { | ||
if options.OverwrittenBucketHosts != nil { | ||
if bucketHosts, err = options.OverwrittenBucketHosts.GetEndpoints(ctx); err != nil { | ||
return nil, err | ||
} | ||
} | ||
allRegionsOptions := region.AllRegionsProviderOptions{UseInsecureProtocol: audit.client.UseInsecureProtocol(), HostFreezeDuration: audit.client.GetHostFreezeDuration(), Resolver: audit.client.GetResolver(), Chooser: audit.client.GetChooser(), BeforeSign: audit.client.GetBeforeSignCallback(), AfterSign: audit.client.GetAfterSignCallback(), SignError: audit.client.GetSignErrorCallback(), BeforeResolve: audit.client.GetBeforeResolveCallback(), AfterResolve: audit.client.GetAfterResolveCallback(), ResolveError: audit.client.GetResolveErrorCallback(), BeforeBackoff: audit.client.GetBeforeBackoffCallback(), AfterBackoff: audit.client.GetAfterBackoffCallback(), BeforeRequest: audit.client.GetBeforeRequestCallback(), AfterResponse: audit.client.GetAfterResponseCallback()} | ||
if hostRetryConfig := audit.client.GetHostRetryConfig(); hostRetryConfig != nil { | ||
allRegionsOptions.RetryMax = hostRetryConfig.RetryMax | ||
allRegionsOptions.Backoff = hostRetryConfig.Backoff | ||
} | ||
credentials := innerRequest.Credentials | ||
if credentials == nil { | ||
credentials = audit.client.GetCredentials() | ||
} | ||
if req.Region, err = region.NewAllRegionsProvider(credentials, bucketHosts, &allRegionsOptions); err != nil { | ||
return nil, err | ||
} | ||
} | ||
} | ||
var respBody QueryLogResponse | ||
if err := audit.client.DoAndAcceptJSON(ctx, &req, &respBody); err != nil { | ||
return nil, err | ||
} | ||
return &respBody, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// THIS FILE IS GENERATED BY api-generator, DO NOT EDIT DIRECTLY! | ||
|
||
package apis | ||
|
||
import ( | ||
httpclient "github.com/qiniu/go-sdk/v7/storagev2/http_client" | ||
region "github.com/qiniu/go-sdk/v7/storagev2/region" | ||
) | ||
|
||
// API 客户端 | ||
type Audit struct { | ||
client *httpclient.Client | ||
} | ||
|
||
// 创建 API 客户端 | ||
func NewAudit(options *httpclient.Options) *Audit { | ||
return &Audit{client: httpclient.NewClient(options)} | ||
} | ||
|
||
// API 客户端选项 | ||
type Options struct { | ||
OverwrittenBucketHosts region.EndpointsProvider | ||
OverwrittenBucketName string | ||
OverwrittenEndpoints region.EndpointsProvider | ||
OverwrittenRegion region.RegionsProvider | ||
OnRequestProgress func(uint64, uint64) | ||
} |
Oops, something went wrong.