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 
)
ACLRole is the level of access to grant.
type ACLRole string

const (
	RoleOwner  ACLRole = "OWNER"
	RoleReader ACLRole = "READER"
	RoleWriter ACLRole = "WRITER"
)
ACLEntity refers to a user or group. They are sometimes referred to as grantees. It could be in the form of: "user-<userId>", "user-<email>", "group-<groupId>", "group-<email>", "domain-<domain>" and "project-team-<projectId>". Or one of the predefined constants: AllUsers, AllAuthenticatedUsers.
type ACLEntity string

const (
	AllUsers              ACLEntity = "allUsers"
	AllAuthenticatedUsers ACLEntity = "allAuthenticatedUsers"
)
ACLRule represents a grant for a role to an entity (user, group or team) for a Google Cloud Storage object or bucket.
ProjectTeam is the project team associated with the entity, if any.
ACLHandle provides operations on an access control list for a Google Cloud Storage bucket or object.
type ACLHandle struct {
	c           *Client
	bucket      string
	object      string
	isDefault   bool
	userProject string // for requester-pays buckets
}
Delete permanently deletes the ACL entry for the given entity.
func ( *ACLHandle) ( context.Context,  ACLEntity) ( error) {
	 = trace.StartSpan(, "cloud.google.com/go/storage.ACL.Delete")
	defer func() { trace.EndSpan(, ) }()

	if .object != "" {
		return .objectDelete(, )
	}
	if .isDefault {
		return .bucketDefaultDelete(, )
	}
	return .bucketDelete(, )
}
Set sets the role for the given entity.
func ( *ACLHandle) ( context.Context,  ACLEntity,  ACLRole) ( error) {
	 = trace.StartSpan(, "cloud.google.com/go/storage.ACL.Set")
	defer func() { trace.EndSpan(, ) }()

	if .object != "" {
		return .objectSet(, , , false)
	}
	if .isDefault {
		return .objectSet(, , , true)
	}
	return .bucketSet(, , )
}
List retrieves ACL entries.
func ( *ACLHandle) ( context.Context) ( []ACLRule,  error) {
	 = trace.StartSpan(, "cloud.google.com/go/storage.ACL.List")
	defer func() { trace.EndSpan(, ) }()

	if .object != "" {
		return .objectList()
	}
	if .isDefault {
		return .bucketDefaultList()
	}
	return .bucketList()
}

func ( *ACLHandle) ( context.Context) ([]ACLRule, error) {
	var  *raw.ObjectAccessControls
	var  error
	 = runWithRetry(, func() error {
		 := .c.raw.DefaultObjectAccessControls.List(.bucket)
		.configureCall(, )
		,  = .Do()
		return 
	})
	if  != nil {
		return nil, 
	}
	return toObjectACLRules(.Items), nil
}

func ( *ACLHandle) ( context.Context,  ACLEntity) error {
	return runWithRetry(, func() error {
		 := .c.raw.DefaultObjectAccessControls.Delete(.bucket, string())
		.configureCall(, )
		return .Do()
	})
}

func ( *ACLHandle) ( context.Context) ([]ACLRule, error) {
	var  *raw.BucketAccessControls
	var  error
	 = runWithRetry(, func() error {
		 := .c.raw.BucketAccessControls.List(.bucket)
		.configureCall(, )
		,  = .Do()
		return 
	})
	if  != nil {
		return nil, 
	}
	return toBucketACLRules(.Items), nil
}

func ( *ACLHandle) ( context.Context,  ACLEntity,  ACLRole) error {
	 := &raw.BucketAccessControl{
		Bucket: .bucket,
		Entity: string(),
		Role:   string(),
	}
	 := runWithRetry(, func() error {
		 := .c.raw.BucketAccessControls.Update(.bucket, string(), )
		.configureCall(, )
		,  := .Do()
		return 
	})
	if  != nil {
		return 
	}
	return nil
}

func ( *ACLHandle) ( context.Context,  ACLEntity) error {
	return runWithRetry(, func() error {
		 := .c.raw.BucketAccessControls.Delete(.bucket, string())
		.configureCall(, )
		return .Do()
	})
}

func ( *ACLHandle) ( context.Context) ([]ACLRule, error) {
	var  *raw.ObjectAccessControls
	var  error
	 = runWithRetry(, func() error {
		 := .c.raw.ObjectAccessControls.List(.bucket, .object)
		.configureCall(, )
		,  = .Do()
		return 
	})
	if  != nil {
		return nil, 
	}
	return toObjectACLRules(.Items), nil
}

func ( *ACLHandle) ( context.Context,  ACLEntity,  ACLRole,  bool) error {
	type  interface {
		( ...googleapi.CallOption) (*raw.ObjectAccessControl, error)
		() http.Header
	}

	 := &raw.ObjectAccessControl{
		Bucket: .bucket,
		Entity: string(),
		Role:   string(),
	}
	var  
	if  {
		 = .c.raw.DefaultObjectAccessControls.Update(.bucket, string(), )
	} else {
		 = .c.raw.ObjectAccessControls.Update(.bucket, .object, string(), )
	}
	.configureCall(, )
	return runWithRetry(, func() error {
		,  := .()
		return 
	})
}

func ( *ACLHandle) ( context.Context,  ACLEntity) error {
	return runWithRetry(, func() error {
		 := .c.raw.ObjectAccessControls.Delete(.bucket, .object, string())
		.configureCall(, )
		return .Do()
	})
}

func ( *ACLHandle) ( context.Context,  interface{ () http.Header }) {
	 := reflect.ValueOf()
	.MethodByName("Context").Call([]reflect.Value{reflect.ValueOf()})
	if .userProject != "" {
		.MethodByName("UserProject").Call([]reflect.Value{reflect.ValueOf(.userProject)})
	}
	setClientHeader(.())
}

func ( []*raw.ObjectAccessControl) []ACLRule {
	var  []ACLRule
	for ,  := range  {
		 = append(, toObjectACLRule())
	}
	return 
}

func ( []*raw.BucketAccessControl) []ACLRule {
	var  []ACLRule
	for ,  := range  {
		 = append(, toBucketACLRule())
	}
	return 
}

func ( *raw.ObjectAccessControl) ACLRule {
	return ACLRule{
		Entity:      ACLEntity(.Entity),
		EntityID:    .EntityId,
		Role:        ACLRole(.Role),
		Domain:      .Domain,
		Email:       .Email,
		ProjectTeam: toObjectProjectTeam(.ProjectTeam),
	}
}

func ( *raw.BucketAccessControl) ACLRule {
	return ACLRule{
		Entity:      ACLEntity(.Entity),
		EntityID:    .EntityId,
		Role:        ACLRole(.Role),
		Domain:      .Domain,
		Email:       .Email,
		ProjectTeam: toBucketProjectTeam(.ProjectTeam),
	}
}

func ( []ACLRule) []*raw.ObjectAccessControl {
	if len() == 0 {
		return nil
	}
	 := make([]*raw.ObjectAccessControl, 0, len())
	for ,  := range  {
		 = append(, .toRawObjectAccessControl("")) // bucket name unnecessary
	}
	return 
}

func ( []ACLRule) []*raw.BucketAccessControl {
	if len() == 0 {
		return nil
	}
	 := make([]*raw.BucketAccessControl, 0, len())
	for ,  := range  {
		 = append(, .toRawBucketAccessControl("")) // bucket name unnecessary
	}
	return 
}

func ( ACLRule) ( string) *raw.BucketAccessControl {
	return &raw.BucketAccessControl{
		Bucket: ,
		Entity: string(.Entity),
The other fields are not settable.
The other fields are not settable.