Copyright 2014 Google LLC Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package storage

import (
	
	
	
	
	

	
	
	
	
	raw 
)
BucketHandle provides operations on a Google Cloud Storage bucket. Use Client.Bucket to get a handle.
Bucket returns a BucketHandle, which provides operations on the named bucket. This call does not perform any network operations. The supplied name must contain only lowercase letters, numbers, dashes, underscores, and dots. The full specification for valid bucket names can be found at: https://cloud.google.com/storage/docs/bucket-naming
func ( *Client) ( string) *BucketHandle {
	return &BucketHandle{
		c:    ,
		name: ,
		acl: ACLHandle{
			c:      ,
			bucket: ,
		},
		defaultObjectACL: ACLHandle{
			c:         ,
			bucket:    ,
			isDefault: true,
		},
	}
}
Create creates the Bucket in the project. If attrs is nil the API defaults will be used.
func ( *BucketHandle) ( context.Context,  string,  *BucketAttrs) ( error) {
	 = trace.StartSpan(, "cloud.google.com/go/storage.Bucket.Create")
	defer func() { trace.EndSpan(, ) }()

	var  *raw.Bucket
	if  != nil {
		 = .toRawBucket()
	} else {
		 = &raw.Bucket{}
	}
If there is lifecycle information but no location, explicitly set the location. This is a GCS quirk/bug.
	if .Location == "" && .Lifecycle != nil {
		.Location = "US"
	}
	 := .c.raw.Buckets.Insert(, )
	setClientHeader(.Header())
	if  != nil && .PredefinedACL != "" {
		.PredefinedAcl(.PredefinedACL)
	}
	if  != nil && .PredefinedDefaultObjectACL != "" {
		.PredefinedDefaultObjectAcl(.PredefinedDefaultObjectACL)
	}
	return runWithRetry(, func() error { ,  := .Context().Do(); return  })
}
Delete deletes the Bucket.
func ( *BucketHandle) ( context.Context) ( error) {
	 = trace.StartSpan(, "cloud.google.com/go/storage.Bucket.Delete")
	defer func() { trace.EndSpan(, ) }()

	,  := .newDeleteCall()
	if  != nil {
		return 
	}
	return runWithRetry(, func() error { return .Context().Do() })
}

func ( *BucketHandle) () (*raw.BucketsDeleteCall, error) {
	 := .c.raw.Buckets.Delete(.name)
	setClientHeader(.Header())
	if  := applyBucketConds("BucketHandle.Delete", .conds, );  != nil {
		return nil, 
	}
	if .userProject != "" {
		.UserProject(.userProject)
	}
	return , nil
}
ACL returns an ACLHandle, which provides access to the bucket's access control list. This controls who can list, create or overwrite the objects in a bucket. This call does not perform any network operations.
func ( *BucketHandle) () *ACLHandle {
	return &.acl
}
DefaultObjectACL returns an ACLHandle, which provides access to the bucket's default object ACLs. These ACLs are applied to newly created objects in this bucket that do not have a defined ACL. This call does not perform any network operations.
Object returns an ObjectHandle, which provides operations on the named object. This call does not perform any network operations. name must consist entirely of valid UTF-8-encoded runes. The full specification for valid object names can be found at: https://cloud.google.com/storage/docs/bucket-naming
func ( *BucketHandle) ( string) *ObjectHandle {
	return &ObjectHandle{
		c:      .c,
		bucket: .name,
		object: ,
		acl: ACLHandle{
			c:           .c,
			bucket:      .name,
			object:      ,
			userProject: .userProject,
		},
		gen:         -1,
		userProject: .userProject,
	}
}
Attrs returns the metadata for the bucket.
func ( *BucketHandle) ( context.Context) ( *BucketAttrs,  error) {
	 = trace.StartSpan(, "cloud.google.com/go/storage.Bucket.Attrs")
	defer func() { trace.EndSpan(, ) }()

	,  := .newGetCall()
	if  != nil {
		return nil, 
	}
	var  *raw.Bucket
	 = runWithRetry(, func() error {
		,  = .Context().Do()
		return 
	})
	if ,  := .(*googleapi.Error);  && .Code == http.StatusNotFound {
		return nil, ErrBucketNotExist
	}
	if  != nil {
		return nil, 
	}
	return newBucket()
}

func ( *BucketHandle) () (*raw.BucketsGetCall, error) {
	 := .c.raw.Buckets.Get(.name).Projection("full")
	setClientHeader(.Header())
	if  := applyBucketConds("BucketHandle.Attrs", .conds, );  != nil {
		return nil, 
	}
	if .userProject != "" {
		.UserProject(.userProject)
	}
	return , nil
}
Update updates a bucket's attributes.
func ( *BucketHandle) ( context.Context,  BucketAttrsToUpdate) ( *BucketAttrs,  error) {
	 = trace.StartSpan(, "cloud.google.com/go/storage.Bucket.Create")
	defer func() { trace.EndSpan(, ) }()

	,  := .newPatchCall(&)
	if  != nil {
		return nil, 
	}
	if .PredefinedACL != "" {
		.PredefinedAcl(.PredefinedACL)
	}
	if .PredefinedDefaultObjectACL != "" {
		.PredefinedDefaultObjectAcl(.PredefinedDefaultObjectACL)
TODO(jba): retry iff metagen is set?
	,  := .Context().Do()
	if  != nil {
		return nil, 
	}
	return newBucket()
}

func ( *BucketHandle) ( *BucketAttrsToUpdate) (*raw.BucketsPatchCall, error) {
	 := .toRawBucket()
	 := .c.raw.Buckets.Patch(.name, ).Projection("full")
	setClientHeader(.Header())
	if  := applyBucketConds("BucketHandle.Update", .conds, );  != nil {
		return nil, 
	}
	if .userProject != "" {
		.UserProject(.userProject)
	}
	return , nil
}
BucketAttrs represents the metadata for a Google Cloud Storage bucket. Read-only fields are ignored by BucketHandle.Create.
Name is the name of the bucket. This field is read-only.
ACL is the list of access control rules on the bucket.
BucketPolicyOnly is an alias for UniformBucketLevelAccess. Use of UniformBucketLevelAccess is recommended above the use of this field. Setting BucketPolicyOnly.Enabled OR UniformBucketLevelAccess.Enabled to true, will enable UniformBucketLevelAccess.
UniformBucketLevelAccess configures access checks to use only bucket-level IAM policies and ignore any ACL rules for the bucket. See https://cloud.google.com/storage/docs/uniform-bucket-level-access for more information.
DefaultObjectACL is the list of access controls to apply to new objects when no object ACL is provided.
DefaultEventBasedHold is the default value for event-based hold on newly created objects in this bucket. It defaults to false.
If not empty, applies a predefined set of access controls. It should be set only when creating a bucket. It is always empty for BucketAttrs returned from the service. See https://cloud.google.com/storage/docs/json_api/v1/buckets/insert for valid values.
If not empty, applies a predefined set of default object access controls. It should be set only when creating a bucket. It is always empty for BucketAttrs returned from the service. See https://cloud.google.com/storage/docs/json_api/v1/buckets/insert for valid values.
Location is the location of the bucket. It defaults to "US".
MetaGeneration is the metadata generation of the bucket. This field is read-only.
StorageClass is the default storage class of the bucket. This defines how objects in the bucket are stored and determines the SLA and the cost of storage. Typical values are "STANDARD", "NEARLINE", "COLDLINE" and "ARCHIVE". Defaults to "STANDARD". See https://cloud.google.com/storage/docs/storage-classes for all valid values.
Created is the creation time of the bucket. This field is read-only.
VersioningEnabled reports whether this bucket has versioning enabled.
Labels are the bucket's labels.
RequesterPays reports whether the bucket is a Requester Pays bucket. Clients performing operations on Requester Pays buckets must provide a user project (see BucketHandle.UserProject), which will be billed for the operations.
Lifecycle is the lifecycle configuration for objects in the bucket.
Retention policy enforces a minimum retention time for all objects contained in the bucket. A RetentionPolicy of nil implies the bucket has no minimum data retention. This feature is in private alpha release. It is not currently available to most customers. It might be changed in backwards-incompatible ways and is not subject to any SLA or deprecation policy.
The bucket's Cross-Origin Resource Sharing (CORS) configuration.
The encryption configuration used by default for newly inserted objects.
The logging configuration.
The website configuration.
Etag is the HTTP/1.1 Entity tag for the bucket. This field is read-only.
LocationType describes how data is stored and replicated. Typical values are "multi-region", "region" and "dual-region". This field is read-only.
BucketPolicyOnly is an alias for UniformBucketLevelAccess. Use of UniformBucketLevelAccess is preferred above BucketPolicyOnly.
Enabled specifies whether access checks use only bucket-level IAM policies. Enabled may be disabled until the locked time.
LockedTime specifies the deadline for changing Enabled from true to false.
UniformBucketLevelAccess configures access checks to use only bucket-level IAM policies.
Enabled specifies whether access checks use only bucket-level IAM policies. Enabled may be disabled until the locked time.
LockedTime specifies the deadline for changing Enabled from true to false.
Lifecycle is the lifecycle configuration for objects in the bucket.
type Lifecycle struct {
	Rules []LifecycleRule
}
RetentionPolicy enforces a minimum retention time for all objects contained in the bucket. Any attempt to overwrite or delete objects younger than the retention period will result in an error. An unlocked retention policy can be modified or removed from the bucket via the Update method. A locked retention policy cannot be removed or shortened in duration for the lifetime of the bucket. This feature is in private alpha release. It is not currently available to most customers. It might be changed in backwards-incompatible ways and is not subject to any SLA or deprecation policy.
RetentionPeriod specifies the duration that objects need to be retained. Retention duration must be greater than zero and less than 100 years. Note that enforcement of retention periods less than a day is not guaranteed. Such periods should only be used for testing purposes.
EffectiveTime is the time from which the policy was enforced and effective. This field is read-only.
IsLocked describes whether the bucket is locked. Once locked, an object retention policy cannot be modified. This field is read-only.
RFC3339 date with only the date segment, used for CreatedBefore in LifecycleRule.
	rfc3339Date = "2006-01-02"
DeleteAction is a lifecycle action that deletes a live and/or archived objects. Takes precedence over SetStorageClass actions.
	DeleteAction = "Delete"
SetStorageClassAction changes the storage class of live and/or archived objects.
	SetStorageClassAction = "SetStorageClass"
)
LifecycleRule is a lifecycle configuration rule. When all the configured conditions are met by an object in the bucket, the configured action will automatically be taken on that object.
Action is the action to take when all of the associated conditions are met.
Condition is the set of conditions that must be met for the associated action to be taken.
LifecycleAction is a lifecycle configuration action.
Type is the type of action to take on matching objects. Acceptable values are "Delete" to delete matching objects and "SetStorageClass" to set the storage class defined in StorageClass on matching objects.
StorageClass is the storage class to set on matching objects if the Action is "SetStorageClass".
Liveness specifies whether the object is live or not.
LiveAndArchived includes both live and archived objects.
Live specifies that the object is still live.
Archived specifies that the object is archived.
LifecycleCondition is a set of conditions used to match objects and take an action automatically. All configured conditions must be met for the associated action to be taken.
AgeInDays is the age of the object in days.
CreatedBefore is the time the object was created. This condition is satisfied when an object is created before midnight of the specified date in UTC.
Liveness specifies the object's liveness. Relevant only for versioned objects
MatchesStorageClasses is the condition matching the object's storage class. Values include "STANDARD", "NEARLINE", "COLDLINE" and "ARCHIVE".
NumNewerVersions is the condition matching objects with a number of newer versions. If the value is N, this condition is satisfied when there are at least N versions (including the live version) newer than this version of the object.
BucketLogging holds the bucket's logging configuration, which defines the destination bucket and optional name prefix for the current bucket's logs.
The destination bucket where the current bucket's logs should be placed.
A prefix for log object names.
BucketWebsite holds the bucket's website configuration, controlling how the service behaves when accessing bucket contents as a web site. See https://cloud.google.com/storage/docs/static-website for more information.
If the requested object path is missing, the service will ensure the path has a trailing '/', append this suffix, and attempt to retrieve the resulting object. This allows the creation of index.html objects to represent directory pages.
toRawBucket copies the editable attribute from b to the raw library's Bucket type.
Copy label map.
	var  map[string]string
	if len(.Labels) > 0 {
		 = make(map[string]string, len(.Labels))
		for ,  := range .Labels {
			[] = 
		}
CORS is the bucket's Cross-Origin Resource Sharing (CORS) configuration.
MaxAge is the value to return in the Access-Control-Max-Age header used in preflight responses.
Methods is the list of HTTP methods on which to include CORS response headers, (GET, OPTIONS, POST, etc) Note: "*" is permitted in the list of methods, and means "any method".
Origins is the list of Origins eligible to receive CORS response headers. Note: "*" is permitted in the list of origins, and means "any Origin".
ResponseHeaders is the list of HTTP headers other than the simple response headers to give permission for the user-agent to share across domains.
BucketEncryption is a bucket's encryption configuration.
A Cloud KMS key name, in the form projects/P/locations/L/keyRings/R/cryptoKeys/K, that will be used to encrypt objects inserted into this bucket, if no encryption method is specified. The key's location must be the same as the bucket's.
BucketAttrsToUpdate define the attributes to update during an Update call.
If set, updates whether the bucket uses versioning.
If set, updates whether the bucket is a Requester Pays bucket.
DefaultEventBasedHold is the default value for event-based hold on newly created objects in this bucket.
BucketPolicyOnly is an alias for UniformBucketLevelAccess. Use of UniformBucketLevelAccess is recommended above the use of this field. Setting BucketPolicyOnly.Enabled OR UniformBucketLevelAccess.Enabled to true, will enable UniformBucketLevelAccess. If both BucketPolicyOnly and UniformBucketLevelAccess are set, the value of UniformBucketLevelAccess will take precedence.
UniformBucketLevelAccess configures access checks to use only bucket-level IAM policies and ignore any ACL rules for the bucket. See https://cloud.google.com/storage/docs/uniform-bucket-level-access for more information.
If set, updates the retention policy of the bucket. Using RetentionPolicy.RetentionPeriod = 0 will delete the existing policy. This feature is in private alpha release. It is not currently available to most customers. It might be changed in backwards-incompatible ways and is not subject to any SLA or deprecation policy.
If set, replaces the CORS configuration with a new configuration. An empty (rather than nil) slice causes all CORS policies to be removed.
If set, replaces the encryption configuration of the bucket. Using BucketEncryption.DefaultKMSKeyName = "" will delete the existing configuration.
If set, replaces the lifecycle configuration of the bucket.
If set, replaces the logging configuration of the bucket.
If set, replaces the website configuration of the bucket.
If not empty, applies a predefined set of access controls. See https://cloud.google.com/storage/docs/json_api/v1/buckets/patch.
If not empty, applies a predefined set of default object access controls. See https://cloud.google.com/storage/docs/json_api/v1/buckets/patch.
SetLabel causes a label to be added or modified when ua is used in a call to Bucket.Update.
func ( *BucketAttrsToUpdate) (,  string) {
	if .setLabels == nil {
		.setLabels = map[string]string{}
	}
	.setLabels[] = 
}
DeleteLabel causes a label to be deleted when ua is used in a call to Bucket.Update.
func ( *BucketAttrsToUpdate) ( string) {
	if .deleteLabels == nil {
		.deleteLabels = map[string]bool{}
	}
	.deleteLabels[] = true
}

func ( *BucketAttrsToUpdate) () *raw.Bucket {
	 := &raw.Bucket{}
	if .CORS != nil {
		.Cors = toRawCORS(.CORS)
		.ForceSendFields = append(.ForceSendFields, "Cors")
	}
	if .DefaultEventBasedHold != nil {
		.DefaultEventBasedHold = optional.ToBool(.DefaultEventBasedHold)
		.ForceSendFields = append(.ForceSendFields, "DefaultEventBasedHold")
	}
	if .RetentionPolicy != nil {
		if .RetentionPolicy.RetentionPeriod == 0 {
			.NullFields = append(.NullFields, "RetentionPolicy")
			.RetentionPolicy = nil
		} else {
			.RetentionPolicy = .RetentionPolicy.toRawRetentionPolicy()
		}
	}
	if .VersioningEnabled != nil {
		.Versioning = &raw.BucketVersioning{
			Enabled:         optional.ToBool(.VersioningEnabled),
			ForceSendFields: []string{"Enabled"},
		}
	}
	if .RequesterPays != nil {
		.Billing = &raw.BucketBilling{
			RequesterPays:   optional.ToBool(.RequesterPays),
			ForceSendFields: []string{"RequesterPays"},
		}
	}
	if .BucketPolicyOnly != nil {
		.IamConfiguration = &raw.BucketIamConfiguration{
			UniformBucketLevelAccess: &raw.BucketIamConfigurationUniformBucketLevelAccess{
				Enabled:         .BucketPolicyOnly.Enabled,
				ForceSendFields: []string{"Enabled"},
			},
		}
	}
	if .UniformBucketLevelAccess != nil {
		.IamConfiguration = &raw.BucketIamConfiguration{
			UniformBucketLevelAccess: &raw.BucketIamConfigurationUniformBucketLevelAccess{
				Enabled:         .UniformBucketLevelAccess.Enabled,
				ForceSendFields: []string{"Enabled"},
			},
		}
	}
	if .Encryption != nil {
		if .Encryption.DefaultKMSKeyName == "" {
			.NullFields = append(.NullFields, "Encryption")
			.Encryption = nil
		} else {
			.Encryption = .Encryption.toRawBucketEncryption()
		}
	}
	if .Lifecycle != nil {
		.Lifecycle = toRawLifecycle(*.Lifecycle)
		.ForceSendFields = append(.ForceSendFields, "Lifecycle")
	}
	if .Logging != nil {
		if *.Logging == (BucketLogging{}) {
			.NullFields = append(.NullFields, "Logging")
			.Logging = nil
		} else {
			.Logging = .Logging.toRawBucketLogging()
		}
	}
	if .Website != nil {
		if *.Website == (BucketWebsite{}) {
			.NullFields = append(.NullFields, "Website")
			.Website = nil
		} else {
			.Website = .Website.toRawBucketWebsite()
		}
	}
Clear ACL or the call will fail.
		.Acl = nil
		.ForceSendFields = append(.ForceSendFields, "Acl")
	}
Clear ACLs or the call will fail.
		.DefaultObjectAcl = nil
		.ForceSendFields = append(.ForceSendFields, "DefaultObjectAcl")
	}
	if .setLabels != nil || .deleteLabels != nil {
		.Labels = map[string]string{}
		for ,  := range .setLabels {
			.Labels[] = 
		}
		if len(.Labels) == 0 && len(.deleteLabels) > 0 {
			.ForceSendFields = append(.ForceSendFields, "Labels")
		}
		for  := range .deleteLabels {
			.NullFields = append(.NullFields, "Labels."+)
		}
	}
	return 
}
If returns a new BucketHandle that applies a set of preconditions. Preconditions already set on the BucketHandle are ignored. Operations on the new handle will return an error if the preconditions are not satisfied. The only valid preconditions for buckets are MetagenerationMatch and MetagenerationNotMatch.
func ( *BucketHandle) ( BucketConditions) *BucketHandle {
	 := *
	.conds = &
	return &
}
BucketConditions constrain bucket methods to act on specific metagenerations. The zero value is an empty set of constraints.
MetagenerationMatch specifies that the bucket must have the given metageneration for the operation to occur. If MetagenerationMatch is zero, it has no effect.
MetagenerationNotMatch specifies that the bucket must not have the given metageneration for the operation to occur. If MetagenerationNotMatch is zero, it has no effect.
	MetagenerationNotMatch int64
}

func ( *BucketConditions) ( string) error {
	if * == (BucketConditions{}) {
		return fmt.Errorf("storage: %s: empty conditions", )
	}
	if .MetagenerationMatch != 0 && .MetagenerationNotMatch != 0 {
		return fmt.Errorf("storage: %s: multiple conditions specified for metageneration", )
	}
	return nil
}
UserProject returns a new BucketHandle that passes the project ID as the user project for all subsequent calls. Calls with a user project will be billed to that project rather than to the bucket's owning project. A user project is required for all operations on Requester Pays buckets.
func ( *BucketHandle) ( string) *BucketHandle {
	 := *
	.userProject = 
	.acl.userProject = 
	.defaultObjectACL.userProject = 
	return &
}
LockRetentionPolicy locks a bucket's retention policy until a previously-configured RetentionPeriod past the EffectiveTime. Note that if RetentionPeriod is set to less than a day, the retention policy is treated as a development configuration and locking will have no effect. The BucketHandle must have a metageneration condition that matches the bucket's metageneration. See BucketHandle.If. This feature is in private alpha release. It is not currently available to most customers. It might be changed in backwards-incompatible ways and is not subject to any SLA or deprecation policy.
func ( *BucketHandle) ( context.Context) error {
	var  int64
	if .conds != nil {
		 = .conds.MetagenerationMatch
	}
	 := .c.raw.Buckets.LockRetentionPolicy(.name, )
	,  := .Context().Do()
	return 
}
applyBucketConds modifies the provided call using the conditions in conds. call is something that quacks like a *raw.WhateverCall.
func ( string,  *BucketConditions,  interface{}) error {
	if  == nil {
		return nil
	}
	if  := .validate();  != nil {
		return 
	}
	 := reflect.ValueOf()
	switch {
	case .MetagenerationMatch != 0:
		if !setConditionField(, "IfMetagenerationMatch", .MetagenerationMatch) {
			return fmt.Errorf("storage: %s: ifMetagenerationMatch not supported", )
		}
	case .MetagenerationNotMatch != 0:
		if !setConditionField(, "IfMetagenerationNotMatch", .MetagenerationNotMatch) {
			return fmt.Errorf("storage: %s: ifMetagenerationNotMatch not supported", )
		}
	}
	return nil
}

func ( *RetentionPolicy) () *raw.BucketRetentionPolicy {
	if  == nil {
		return nil
	}
	return &raw.BucketRetentionPolicy{
		RetentionPeriod: int64(.RetentionPeriod / time.Second),
	}
}

func ( *raw.BucketRetentionPolicy) (*RetentionPolicy, error) {
	if  == nil {
		return nil, nil
	}
	,  := time.Parse(time.RFC3339, .EffectiveTime)
	if  != nil {
		return nil, 
	}
	return &RetentionPolicy{
		RetentionPeriod: time.Duration(.RetentionPeriod) * time.Second,
		EffectiveTime:   ,
		IsLocked:        .IsLocked,
	}, nil
}

func ( []CORS) []*raw.BucketCors {
	var  []*raw.BucketCors
	for ,  := range  {
		 = append(, &raw.BucketCors{
			MaxAgeSeconds:  int64(.MaxAge / time.Second),
			Method:         .Methods,
			Origin:         .Origins,
			ResponseHeader: .ResponseHeaders,
		})
	}
	return 
}

func ( []*raw.BucketCors) []CORS {
	var  []CORS
	for ,  := range  {
		 = append(, CORS{
			MaxAge:          time.Duration(.MaxAgeSeconds) * time.Second,
			Methods:         .Method,
			Origins:         .Origin,
			ResponseHeaders: .ResponseHeader,
		})
	}
	return 
}

func ( Lifecycle) *raw.BucketLifecycle {
	var  raw.BucketLifecycle
	if len(.Rules) == 0 {
		.ForceSendFields = []string{"Rule"}
	}
	for ,  := range .Rules {
		 := &raw.BucketLifecycleRule{
			Action: &raw.BucketLifecycleRuleAction{
				Type:         .Action.Type,
				StorageClass: .Action.StorageClass,
			},
			Condition: &raw.BucketLifecycleRuleCondition{
				Age:                 .Condition.AgeInDays,
				MatchesStorageClass: .Condition.MatchesStorageClasses,
				NumNewerVersions:    .Condition.NumNewerVersions,
			},
		}

		switch .Condition.Liveness {
		case LiveAndArchived:
			.Condition.IsLive = nil
		case Live:
			.Condition.IsLive = googleapi.Bool(true)
		case Archived:
			.Condition.IsLive = googleapi.Bool(false)
		}

		if !.Condition.CreatedBefore.IsZero() {
			.Condition.CreatedBefore = .Condition.CreatedBefore.Format(rfc3339Date)
		}
		.Rule = append(.Rule, )
	}
	return &
}

func ( *raw.BucketLifecycle) Lifecycle {
	var  Lifecycle
	if  == nil {
		return 
	}
	for ,  := range .Rule {
		 := LifecycleRule{
			Action: LifecycleAction{
				Type:         .Action.Type,
				StorageClass: .Action.StorageClass,
			},
			Condition: LifecycleCondition{
				AgeInDays:             .Condition.Age,
				MatchesStorageClasses: .Condition.MatchesStorageClass,
				NumNewerVersions:      .Condition.NumNewerVersions,
			},
		}

		if .Condition.IsLive == nil {
			.Condition.Liveness = LiveAndArchived
		} else if *.Condition.IsLive {
			.Condition.Liveness = Live
		} else {
			.Condition.Liveness = Archived
		}

		if .Condition.CreatedBefore != "" {
			.Condition.CreatedBefore, _ = time.Parse(rfc3339Date, .Condition.CreatedBefore)
		}
		.Rules = append(.Rules, )
	}
	return 
}

func ( *BucketEncryption) () *raw.BucketEncryption {
	if  == nil {
		return nil
	}
	return &raw.BucketEncryption{
		DefaultKmsKeyName: .DefaultKMSKeyName,
	}
}

func ( *raw.BucketEncryption) *BucketEncryption {
	if  == nil {
		return nil
	}
	return &BucketEncryption{DefaultKMSKeyName: .DefaultKmsKeyName}
}

func ( *BucketLogging) () *raw.BucketLogging {
	if  == nil {
		return nil
	}
	return &raw.BucketLogging{
		LogBucket:       .LogBucket,
		LogObjectPrefix: .LogObjectPrefix,
	}
}

func ( *raw.BucketLogging) *BucketLogging {
	if  == nil {
		return nil
	}
	return &BucketLogging{
		LogBucket:       .LogBucket,
		LogObjectPrefix: .LogObjectPrefix,
	}
}

func ( *BucketWebsite) () *raw.BucketWebsite {
	if  == nil {
		return nil
	}
	return &raw.BucketWebsite{
		MainPageSuffix: .MainPageSuffix,
		NotFoundPage:   .NotFoundPage,
	}
}

func ( *raw.BucketWebsite) *BucketWebsite {
	if  == nil {
		return nil
	}
	return &BucketWebsite{
		MainPageSuffix: .MainPageSuffix,
		NotFoundPage:   .NotFoundPage,
	}
}

func ( *raw.BucketIamConfiguration) BucketPolicyOnly {
	if  == nil || .BucketPolicyOnly == nil || !.BucketPolicyOnly.Enabled {
		return BucketPolicyOnly{}
	}
	,  := time.Parse(time.RFC3339, .BucketPolicyOnly.LockedTime)
	if  != nil {
		return BucketPolicyOnly{
			Enabled: true,
		}
	}
	return BucketPolicyOnly{
		Enabled:    true,
		LockedTime: ,
	}
}

func ( *raw.BucketIamConfiguration) UniformBucketLevelAccess {
	if  == nil || .UniformBucketLevelAccess == nil || !.UniformBucketLevelAccess.Enabled {
		return UniformBucketLevelAccess{}
	}
	,  := time.Parse(time.RFC3339, .UniformBucketLevelAccess.LockedTime)
	if  != nil {
		return UniformBucketLevelAccess{
			Enabled: true,
		}
	}
	return UniformBucketLevelAccess{
		Enabled:    true,
		LockedTime: ,
	}
}
Objects returns an iterator over the objects in the bucket that match the Query q. If q is nil, no filtering is done. Note: The returned iterator is not safe for concurrent operations without explicit synchronization.
func ( *BucketHandle) ( context.Context,  *Query) *ObjectIterator {
	 := &ObjectIterator{
		ctx:    ,
		bucket: ,
	}
	.pageInfo, .nextFunc = iterator.NewPageInfo(
		.fetch,
		func() int { return len(.items) },
		func() interface{} {  := .items; .items = nil; return  })
	if  != nil {
		.query = *
	}
	return 
}
An ObjectIterator is an iterator over ObjectAttrs. Note: This iterator is not safe for concurrent operations without explicit synchronization.
PageInfo supports pagination. See the google.golang.org/api/iterator package for details. Note: This method is not safe for concurrent operations without explicit synchronization.
func ( *ObjectIterator) () *iterator.PageInfo { return .pageInfo }
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns iterator.Done, all subsequent calls will return iterator.Done. If Query.Delimiter is non-empty, some of the ObjectAttrs returned by Next will have a non-empty Prefix field, and a zero value for all other fields. These represent prefixes. Note: This method is not safe for concurrent operations without explicit synchronization.
func ( *ObjectIterator) () (*ObjectAttrs, error) {
	if  := .nextFunc();  != nil {
		return nil, 
	}
	 := .items[0]
	.items = .items[1:]
	return , nil
}

func ( *ObjectIterator) ( int,  string) (string, error) {
	 := .bucket.c.raw.Objects.List(.bucket.name)
	setClientHeader(.Header())
	.Projection("full")
	.Delimiter(.query.Delimiter)
	.Prefix(.query.Prefix)
	.Versions(.query.Versions)
	if len(.query.fieldSelection) > 0 {
		.Fields("nextPageToken", googleapi.Field(.query.fieldSelection))
	}
	.PageToken()
	if .bucket.userProject != "" {
		.UserProject(.bucket.userProject)
	}
	if  > 0 {
		.MaxResults(int64())
	}
	var  *raw.Objects
	var  error
	 = runWithRetry(.ctx, func() error {
		,  = .Context(.ctx).Do()
		return 
	})
	if  != nil {
		if ,  := .(*googleapi.Error);  && .Code == http.StatusNotFound {
			 = ErrBucketNotExist
		}
		return "", 
	}
	for ,  := range .Items {
		.items = append(.items, newObject())
	}
	for ,  := range .Prefixes {
		.items = append(.items, &ObjectAttrs{Prefix: })
	}
	return .NextPageToken, nil
}
Buckets returns an iterator over the buckets in the project. You may optionally set the iterator's Prefix field to restrict the list to buckets whose names begin with the prefix. By default, all buckets in the project are returned. Note: The returned iterator is not safe for concurrent operations without explicit synchronization.
func ( *Client) ( context.Context,  string) *BucketIterator {
	 := &BucketIterator{
		ctx:       ,
		client:    ,
		projectID: ,
	}
	.pageInfo, .nextFunc = iterator.NewPageInfo(
		.fetch,
		func() int { return len(.buckets) },
		func() interface{} {  := .buckets; .buckets = nil; return  })

	return 
}
A BucketIterator is an iterator over BucketAttrs. Note: This iterator is not safe for concurrent operations without explicit synchronization.
Prefix restricts the iterator to buckets whose names begin with it.
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns iterator.Done, all subsequent calls will return iterator.Done. Note: This method is not safe for concurrent operations without explicit synchronization.
func ( *BucketIterator) () (*BucketAttrs, error) {
	if  := .nextFunc();  != nil {
		return nil, 
	}
	 := .buckets[0]
	.buckets = .buckets[1:]
	return , nil
}
PageInfo supports pagination. See the google.golang.org/api/iterator package for details. Note: This method is not safe for concurrent operations without explicit synchronization.
func ( *BucketIterator) () *iterator.PageInfo { return .pageInfo }

func ( *BucketIterator) ( int,  string) ( string,  error) {
	 := .client.raw.Buckets.List(.projectID)
	setClientHeader(.Header())
	.Projection("full")
	.Prefix(.Prefix)
	.PageToken()
	if  > 0 {
		.MaxResults(int64())
	}
	var  *raw.Buckets
	 = runWithRetry(.ctx, func() error {
		,  = .Context(.ctx).Do()
		return 
	})
	if  != nil {
		return "", 
	}
	for ,  := range .Items {
		,  := newBucket()
		if  != nil {
			return "", 
		}
		.buckets = append(.buckets, )
	}
	return .NextPageToken, nil