git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/eacl/types.go (about)

     1  package eacl
     2  
     3  import (
     4  	cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
     5  )
     6  
     7  // Header is an interface of string key-value header.
     8  type Header interface {
     9  	Key() string
    10  	Value() string
    11  }
    12  
    13  // TypedHeaderSource is the interface that wraps
    14  // method for selecting typed headers by type.
    15  type TypedHeaderSource interface {
    16  	// HeadersOfType returns the list of key-value headers
    17  	// of particular type.
    18  	//
    19  	// It returns any problem encountered through the boolean
    20  	// false value.
    21  	HeadersOfType(FilterHeaderType) ([]Header, bool)
    22  }
    23  
    24  // ValidationUnit represents unit of check for Validator.
    25  type ValidationUnit struct {
    26  	cid *cid.ID
    27  
    28  	role Role
    29  
    30  	op Operation
    31  
    32  	hdrSrc TypedHeaderSource
    33  
    34  	key []byte
    35  
    36  	table *Table
    37  }
    38  
    39  // WithContainerID configures ValidationUnit to use v as request's container ID.
    40  func (u *ValidationUnit) WithContainerID(v *cid.ID) *ValidationUnit {
    41  	if u != nil {
    42  		u.cid = v
    43  	}
    44  
    45  	return u
    46  }
    47  
    48  // WithRole configures ValidationUnit to use v as request's role.
    49  func (u *ValidationUnit) WithRole(v Role) *ValidationUnit {
    50  	if u != nil {
    51  		u.role = v
    52  	}
    53  
    54  	return u
    55  }
    56  
    57  // WithOperation configures ValidationUnit to use v as request's operation.
    58  func (u *ValidationUnit) WithOperation(v Operation) *ValidationUnit {
    59  	if u != nil {
    60  		u.op = v
    61  	}
    62  
    63  	return u
    64  }
    65  
    66  // WithHeaderSource configures ValidationUnit to use v as a source of headers.
    67  func (u *ValidationUnit) WithHeaderSource(v TypedHeaderSource) *ValidationUnit {
    68  	if u != nil {
    69  		u.hdrSrc = v
    70  	}
    71  
    72  	return u
    73  }
    74  
    75  // WithSenderKey configures ValidationUnit to use as sender's public key.
    76  func (u *ValidationUnit) WithSenderKey(v []byte) *ValidationUnit {
    77  	if u != nil {
    78  		u.key = v
    79  	}
    80  
    81  	return u
    82  }
    83  
    84  // WithBearerToken configures ValidationUnit to use v as request's bearer token.
    85  func (u *ValidationUnit) WithEACLTable(table *Table) *ValidationUnit {
    86  	if u != nil {
    87  		u.table = table
    88  	}
    89  
    90  	return u
    91  }