diff --git a/go.mod b/go.mod index bd0d7f12..73aa4880 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( require ( github.com/alibabacloud-go/openapi-util v0.1.0 github.com/alibabacloud-go/tea-utils v1.4.5 - github.com/alibabacloud-go/tea-utils/v2 v2.0.5 + github.com/alibabacloud-go/tea-utils/v2 v2.0.7 github.com/go-logr/zapr v1.3.0 github.com/olekukonko/tablewriter v0.0.6-0.20230925090304-df64c4bbad77 go.uber.org/zap v1.27.0 diff --git a/go.sum b/go.sum index 83c513a3..f1cf472a 100644 --- a/go.sum +++ b/go.sum @@ -48,8 +48,9 @@ github.com/alibabacloud-go/tea-utils v1.4.5 h1:h0/6Xd2f3bPE4XHTvkpjwxowIwRCJAJOq github.com/alibabacloud-go/tea-utils v1.4.5/go.mod h1:KNcT0oXlZZxOXINnZBs6YvgOd5aYp9U67G+E3R8fcQw= github.com/alibabacloud-go/tea-utils/v2 v2.0.0/go.mod h1:U5MTY10WwlquGPS34DOeomUGBB0gXbLueiq5Trwu0C4= github.com/alibabacloud-go/tea-utils/v2 v2.0.4/go.mod h1:sj1PbjPodAVTqGTA3olprfeeqqmwD0A5OQz94o9EuXQ= -github.com/alibabacloud-go/tea-utils/v2 v2.0.5 h1:EUakYEUAwr6L3wLT0vejIw2rc0IA1RSXDwLnIb3f2vU= github.com/alibabacloud-go/tea-utils/v2 v2.0.5/go.mod h1:dL6vbUT35E4F4bFTHL845eUloqaerYBYPsdWR2/jhe4= +github.com/alibabacloud-go/tea-utils/v2 v2.0.7 h1:WDx5qW3Xa5ZgJ1c8NfqJkF6w+AU5wB8835UdhPr6Ax0= +github.com/alibabacloud-go/tea-utils/v2 v2.0.7/go.mod h1:qxn986l+q33J5VkialKMqT/TTs3E+U9MJpd001iWQ9I= github.com/alibabacloud-go/tea-xml v1.1.2/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8= github.com/alibabacloud-go/tea-xml v1.1.3 h1:7LYnm+JbOq2B+T/B0fHC4Ies4/FofC4zHzYtqw7dgt0= github.com/alibabacloud-go/tea-xml v1.1.3/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8= diff --git a/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/semaphore_provider.go b/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/semaphore_provider.go index 47baedcb..9164dd8b 100644 --- a/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/semaphore_provider.go +++ b/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/semaphore_provider.go @@ -40,3 +40,9 @@ func (o *SemaphoreProviderOptions) applyDefaults() { o.MaxWeight = 1 } } + +func (p *SemaphoreProvider) Stop(ctx context.Context) { + if s, ok := p.cp.(Stopper); ok { + s.Stop(ctx) + } +} diff --git a/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/v1sdk.go b/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/v1sdk.go index c85b29a6..fd2981cc 100644 --- a/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/v1sdk.go +++ b/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/v1sdk.go @@ -3,23 +3,27 @@ package provider import ( "context" "fmt" + "time" ) type SignerForV1SDK struct { - p CredentialsProvider - Logger Logger + p CredentialsProvider + Logger Logger + credentialRetrievalTimeout time.Duration } type SignerForV1SDKOptions struct { - Logger Logger + Logger Logger + CredentialRetrievalTimeout time.Duration } func NewSignerForV1SDK(p CredentialsProvider, opts SignerForV1SDKOptions) *SignerForV1SDK { opts.applyDefaults() return &SignerForV1SDK{ - p: p, - Logger: opts.Logger, + p: p, + Logger: opts.Logger, + credentialRetrievalTimeout: opts.CredentialRetrievalTimeout, } } @@ -36,7 +40,9 @@ func (s *SignerForV1SDK) GetVersion() string { } func (s *SignerForV1SDK) GetAccessKeyId() (string, error) { - cred, err := s.p.Credentials(context.TODO()) + timeoutCtx, cancel := context.WithTimeout(context.Background(), s.credentialRetrievalTimeout) + defer cancel() + cred, err := s.p.Credentials(timeoutCtx) if err != nil { return "", err } @@ -44,7 +50,9 @@ func (s *SignerForV1SDK) GetAccessKeyId() (string, error) { } func (s *SignerForV1SDK) GetExtraParam() map[string]string { - cred, err := s.p.Credentials(context.TODO()) + timeoutCtx, cancel := context.WithTimeout(context.Background(), s.credentialRetrievalTimeout) + defer cancel() + cred, err := s.p.Credentials(timeoutCtx) if err != nil { s.logger().Error(err, fmt.Sprintf("get credentials failed: %s", err)) return nil @@ -56,7 +64,9 @@ func (s *SignerForV1SDK) GetExtraParam() map[string]string { } func (s *SignerForV1SDK) Sign(stringToSign, secretSuffix string) string { - cred, err := s.p.Credentials(context.TODO()) + timeoutCtx, cancel := context.WithTimeout(context.Background(), s.credentialRetrievalTimeout) + defer cancel() + cred, err := s.p.Credentials(timeoutCtx) if err != nil { s.logger().Error(err, fmt.Sprintf("get credentials failed: %s", err)) return "" @@ -76,4 +86,7 @@ func (o *SignerForV1SDKOptions) applyDefaults() { if o.Logger == nil { o.Logger = defaultLog } + if o.CredentialRetrievalTimeout <= 0 { + o.CredentialRetrievalTimeout = defaultTimeout + } } diff --git a/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/v2sdk.go b/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/v2sdk.go index c53f4478..71369599 100644 --- a/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/v2sdk.go +++ b/vendor/github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider/v2sdk.go @@ -2,28 +2,36 @@ package provider import ( "context" + "time" ) +var defaultTimeout = time.Minute * 10 + type CredentialForV2SDK struct { - p CredentialsProvider - Logger Logger + p CredentialsProvider + Logger Logger + credentialRetrievalTimeout time.Duration } type CredentialForV2SDKOptions struct { - Logger Logger + Logger Logger + CredentialRetrievalTimeout time.Duration } func NewCredentialForV2SDK(p CredentialsProvider, opts CredentialForV2SDKOptions) *CredentialForV2SDK { opts.applyDefaults() return &CredentialForV2SDK{ - p: p, - Logger: opts.Logger, + p: p, + Logger: opts.Logger, + credentialRetrievalTimeout: opts.CredentialRetrievalTimeout, } } func (c *CredentialForV2SDK) GetAccessKeyId() (*string, error) { - cred, err := c.p.Credentials(context.TODO()) + timeoutCtx, cancel := context.WithTimeout(context.Background(), c.credentialRetrievalTimeout) + defer cancel() + cred, err := c.p.Credentials(timeoutCtx) if err != nil { return nil, err } @@ -31,7 +39,9 @@ func (c *CredentialForV2SDK) GetAccessKeyId() (*string, error) { } func (c *CredentialForV2SDK) GetAccessKeySecret() (*string, error) { - cred, err := c.p.Credentials(context.TODO()) + timeoutCtx, cancel := context.WithTimeout(context.Background(), c.credentialRetrievalTimeout) + defer cancel() + cred, err := c.p.Credentials(timeoutCtx) if err != nil { return nil, err } @@ -39,7 +49,9 @@ func (c *CredentialForV2SDK) GetAccessKeySecret() (*string, error) { } func (c *CredentialForV2SDK) GetSecurityToken() (*string, error) { - cred, err := c.p.Credentials(context.TODO()) + timeoutCtx, cancel := context.WithTimeout(context.Background(), c.credentialRetrievalTimeout) + defer cancel() + cred, err := c.p.Credentials(timeoutCtx) if err != nil { return nil, err } @@ -65,6 +77,9 @@ func (o *CredentialForV2SDKOptions) applyDefaults() { if o.Logger == nil { o.Logger = defaultLog } + if o.CredentialRetrievalTimeout <= 0 { + o.CredentialRetrievalTimeout = defaultTimeout + } } func stringPointer(s string) *string { diff --git a/vendor/github.com/alibabacloud-go/tea-utils/v2/service/service.go b/vendor/github.com/alibabacloud-go/tea-utils/v2/service/service.go index 1714dcc0..071459ce 100644 --- a/vendor/github.com/alibabacloud-go/tea-utils/v2/service/service.go +++ b/vendor/github.com/alibabacloud-go/tea-utils/v2/service/service.go @@ -1,6 +1,7 @@ package service import ( + "bufio" "bytes" "crypto/md5" "encoding/hex" @@ -26,6 +27,7 @@ var defaultUserAgent = fmt.Sprintf("AlibabaCloud (%s; %s) Golang/%s Core/%s TeaD type ExtendsParameters struct { Headers map[string]*string `json:"headers,omitempty" xml:"headers,omitempty"` + Queries map[string]*string `json:"queries,omitempty" xml:"queries,omitempty"` } func (s ExtendsParameters) String() string { @@ -41,6 +43,11 @@ func (s *ExtendsParameters) SetHeaders(v map[string]*string) *ExtendsParameters return s } +func (s *ExtendsParameters) SetQueries(v map[string]*string) *ExtendsParameters { + s.Queries = v + return s +} + type RuntimeOptions struct { Autoretry *bool `json:"autoretry" xml:"autoretry"` IgnoreSSL *bool `json:"ignoreSSL" xml:"ignoreSSL"` @@ -66,6 +73,40 @@ type RuntimeOptions struct { var processStartTime int64 = time.Now().UnixNano() / 1e6 var seqId int64 = 0 +type SSEEvent struct { + ID *string + Event *string + Data *string + Retry *int +} + +func parseEvent(eventLines []string) (SSEEvent, error) { + var event SSEEvent + + for _, line := range eventLines { + if strings.HasPrefix(line, "data:") { + event.Data = tea.String(tea.StringValue(event.Data) + strings.TrimPrefix(line, "data:") + "\n") + } else if strings.HasPrefix(line, "id:") { + id := strings.TrimPrefix(line, "id:") + event.ID = tea.String(strings.Trim(id, " ")) + } else if strings.HasPrefix(line, "event:") { + eventName := strings.TrimPrefix(line, "event:") + event.Event = tea.String(strings.Trim(eventName, " ")) + } else if strings.HasPrefix(line, "retry:") { + trimmedLine := strings.TrimPrefix(line, "retry:") + trimmedLine = strings.Trim(trimmedLine, " ") + retryValue, _err := strconv.Atoi(trimmedLine) + if _err != nil { + return event, fmt.Errorf("retry %v is not a int", trimmedLine) + } + event.Retry = tea.Int(retryValue) + } + } + data := strings.TrimRight(tea.StringValue(event.Data), "\n") + event.Data = tea.String(strings.Trim(data, " ")) + return event, nil +} + func getGID() uint64 { // https://blog.sgmansfield.com/2015/12/goroutine-ids/ b := make([]byte, 64) @@ -549,3 +590,41 @@ func ToArray(in interface{}) []map[string]interface{} { } return tmp } + +func ReadAsSSE(body io.ReadCloser) (<-chan SSEEvent, <-chan error) { + eventChannel := make(chan SSEEvent) + errorChannel := make(chan error) + + go func() { + defer body.Close() + defer close(eventChannel) + + reader := bufio.NewReader(body) + var eventLines []string + + for { + line, err := reader.ReadString('\n') + if err == io.EOF { + break + } + if err != nil { + errorChannel <- err + } + + line = strings.TrimRight(line, "\n") + if line == "" { + if len(eventLines) > 0 { + event, err := parseEvent(eventLines) + if err != nil { + errorChannel <- err + } + eventChannel <- event + eventLines = []string{} + } + continue + } + eventLines = append(eventLines, line) + } + }() + return eventChannel, errorChannel +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 9ed9cb7e..4c285a40 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -40,7 +40,7 @@ github.com/alibabacloud-go/tea/utils # github.com/alibabacloud-go/tea-utils v1.4.5 ## explicit; go 1.14 github.com/alibabacloud-go/tea-utils/service -# github.com/alibabacloud-go/tea-utils/v2 v2.0.5 +# github.com/alibabacloud-go/tea-utils/v2 v2.0.7 ## explicit; go 1.14 github.com/alibabacloud-go/tea-utils/v2/service # github.com/alibabacloud-go/tea-xml v1.1.3