Source File
hmac.go
Belonging Package
cloud.google.com/go/storage
package storage
import (
raw
)
type HMACKeyHandle struct {
projectID string
accessID string
raw *raw.ProjectsHmacKeysService
}
func ( *Client) (, string) *HMACKeyHandle {
return &HMACKeyHandle{
projectID: ,
accessID: ,
raw: raw.NewProjectsHmacKeysService(.raw),
}
}
func ( *HMACKeyHandle) ( context.Context, ...HMACKeyOption) (*HMACKey, error) {
:= .raw.Get(.projectID, .accessID)
:= new(hmacKeyDesc)
for , := range {
.withHMACKeyDesc()
}
if .userProjectID != "" {
= .UserProject(.userProjectID)
}
setClientHeader(.Header())
var *raw.HmacKeyMetadata
var error
= runWithRetry(, func() error {
, = .Context().Do()
return
})
if != nil {
return nil,
}
:= &raw.HmacKey{
Metadata: ,
}
return pbHmacKeyToHMACKey(, false)
}
func ( *HMACKeyHandle) ( context.Context, ...HMACKeyOption) error {
:= .raw.Delete(.projectID, .accessID)
:= new(hmacKeyDesc)
for , := range {
.withHMACKeyDesc()
}
if .userProjectID != "" {
= .UserProject(.userProjectID)
}
setClientHeader(.Header())
return runWithRetry(, func() error {
return .Context().Do()
})
}
func ( *raw.HmacKey, bool) (*HMACKey, error) {
:= .Metadata
if == nil {
return nil, errors.New("field Metadata cannot be nil")
}
, := time.Parse(time.RFC3339, .TimeCreated)
if != nil {
return nil, fmt.Errorf("field CreatedTime: %v", )
}
, := time.Parse(time.RFC3339, .Updated)
if != nil && ! {
return nil, fmt.Errorf("field UpdatedTime: %v", )
}
:= &HMACKey{
AccessID: .AccessId,
Secret: .Secret,
Etag: .Etag,
ID: .Id,
State: HMACState(.State),
ProjectID: .ProjectId,
CreatedTime: ,
UpdatedTime: ,
ServiceAccountEmail: .ServiceAccountEmail,
}
return , nil
}
func ( *Client) ( context.Context, , string, ...HMACKeyOption) (*HMACKey, error) {
if == "" {
return nil, errors.New("storage: expecting a non-blank projectID")
}
if == "" {
return nil, errors.New("storage: expecting a non-blank service account email")
}
:= raw.NewProjectsHmacKeysService(.raw)
:= .Create(, )
:= new(hmacKeyDesc)
for , := range {
.withHMACKeyDesc()
}
if .userProjectID != "" {
= .UserProject(.userProjectID)
}
setClientHeader(.Header())
var *raw.HmacKey
var error
= runWithRetry(, func() error {
, = .Context().Do()
return
})
if != nil {
return nil,
}
return pbHmacKeyToHMACKey(, true)
}
func ( *HMACKeyHandle) ( context.Context, HMACKeyAttrsToUpdate, ...HMACKeyOption) (*HMACKey, error) {
if .State != Active && .State != Inactive {
return nil, fmt.Errorf("storage: invalid state %q for update, must be either %q or %q", .State, Active, Inactive)
}
:= .raw.Update(.projectID, .accessID, &raw.HmacKeyMetadata{
Etag: .Etag,
State: string(.State),
})
:= new(hmacKeyDesc)
for , := range {
.withHMACKeyDesc()
}
if .userProjectID != "" {
= .UserProject(.userProjectID)
}
setClientHeader(.Header())
var *raw.HmacKeyMetadata
var error
= runWithRetry(, func() error {
, = .Context().Do()
return
})
if != nil {
return nil,
}
:= &raw.HmacKey{
Metadata: ,
}
return pbHmacKeyToHMACKey(, false)
}
func ( *Client) ( context.Context, string, ...HMACKeyOption) *HMACKeysIterator {
:= &HMACKeysIterator{
ctx: ,
raw: raw.NewProjectsHmacKeysService(.raw),
projectID: ,
}
for , := range {
.withHMACKeyDesc(&.desc)
}
.pageInfo, .nextFunc = iterator.NewPageInfo(
.fetch,
func() int { return len(.hmacKeys) - .index },
func() interface{} {
:= .hmacKeys
.hmacKeys = .hmacKeys[:0]
.index = 0
return
})
return
}
func ( *HMACKeysIterator) () *iterator.PageInfo { return .pageInfo }
func ( *HMACKeysIterator) ( int, string) ( string, error) {
:= .raw.List(.projectID)
setClientHeader(.Header())
if != "" {
= .PageToken()
}
if .desc.showDeletedKeys {
= .ShowDeletedKeys(true)
}
if .desc.userProjectID != "" {
= .UserProject(.desc.userProjectID)
}
if .desc.forServiceAccountEmail != "" {
= .ServiceAccountEmail(.desc.forServiceAccountEmail)
}
if > 0 {
= .MaxResults(int64())
}
:= .ctx
var *raw.HmacKeysMetadata
= runWithRetry(.ctx, func() error {
, = .Context().Do()
return
})
if != nil {
return "",
}
for , := range .Items {
:= &raw.HmacKey{
Metadata: ,
}
, := pbHmacKeyToHMACKey(, true)
if != nil {
return "",
}
.hmacKeys = append(.hmacKeys, )
}
return .NextPageToken, nil
}
type hmacKeyDesc struct {
forServiceAccountEmail string
showDeletedKeys bool
userProjectID string
}
type HMACKeyOption interface {
withHMACKeyDesc(*hmacKeyDesc)
}
type hmacKeyDescFunc func(*hmacKeyDesc)
func ( hmacKeyDescFunc) ( *hmacKeyDesc) {
()
}
func ( string) HMACKeyOption {
return hmacKeyDescFunc(func( *hmacKeyDesc) {
.forServiceAccountEmail =
})
}
func () HMACKeyOption {
return hmacKeyDescFunc(func( *hmacKeyDesc) {
.showDeletedKeys = true
})
}
func ( string) HMACKeyOption {
return hmacKeyDescFunc(func( *hmacKeyDesc) {
.userProjectID =
})
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |