mirror of
https://github.com/status-im/consul.git
synced 2025-02-22 18:38:19 +00:00
* Update AWS SDK to use PCA features. * Add AWS PCA provider * Add plumbing for config, config validation tests, add test for inheriting existing CA resources created by user * Unparallel the tests so we don't exhaust PCA limits * Merge updates * More aggressive polling; rate limit pass through on sign; Timeout on Sign and CA create * Add AWS PCA docs * Fix Vault doc typo too * Doc typo * Apply suggestions from code review Co-Authored-By: R.B. Boyer <rb@hashicorp.com> Co-Authored-By: kaitlincarter-hc <43049322+kaitlincarter-hc@users.noreply.github.com> * Doc fixes; tests for erroring if State is modified via API * More review cleanup * Uncomment tests! * Minor suggested clean ups
66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package request
|
|
|
|
import (
|
|
"io"
|
|
"sync"
|
|
|
|
"github.com/aws/aws-sdk-go/internal/sdkio"
|
|
)
|
|
|
|
// offsetReader is a thread-safe io.ReadCloser to prevent racing
|
|
// with retrying requests
|
|
type offsetReader struct {
|
|
buf io.ReadSeeker
|
|
lock sync.Mutex
|
|
closed bool
|
|
}
|
|
|
|
func newOffsetReader(buf io.ReadSeeker, offset int64) (*offsetReader, error) {
|
|
reader := &offsetReader{}
|
|
_, err := buf.Seek(offset, sdkio.SeekStart)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
reader.buf = buf
|
|
return reader, nil
|
|
}
|
|
|
|
// Close will close the instance of the offset reader's access to
|
|
// the underlying io.ReadSeeker.
|
|
func (o *offsetReader) Close() error {
|
|
o.lock.Lock()
|
|
defer o.lock.Unlock()
|
|
o.closed = true
|
|
return nil
|
|
}
|
|
|
|
// Read is a thread-safe read of the underlying io.ReadSeeker
|
|
func (o *offsetReader) Read(p []byte) (int, error) {
|
|
o.lock.Lock()
|
|
defer o.lock.Unlock()
|
|
|
|
if o.closed {
|
|
return 0, io.EOF
|
|
}
|
|
|
|
return o.buf.Read(p)
|
|
}
|
|
|
|
// Seek is a thread-safe seeking operation.
|
|
func (o *offsetReader) Seek(offset int64, whence int) (int64, error) {
|
|
o.lock.Lock()
|
|
defer o.lock.Unlock()
|
|
|
|
return o.buf.Seek(offset, whence)
|
|
}
|
|
|
|
// CloseAndCopy will return a new offsetReader with a copy of the old buffer
|
|
// and close the old buffer.
|
|
func (o *offsetReader) CloseAndCopy(offset int64) (*offsetReader, error) {
|
|
if err := o.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
return newOffsetReader(o.buf, offset)
|
|
}
|