github.com/gophercloud/gophercloud@v1.11.0/openstack/sharedfilesystems/v2/shareaccessrules/results.go (about)

     1  package shareaccessrules
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/gophercloud/gophercloud"
     8  )
     9  
    10  // ShareAccess contains information associated with an OpenStack share access rule.
    11  type ShareAccess struct {
    12  	// The UUID of the share to which you are granted or denied access.
    13  	ShareID string `json:"share_id"`
    14  	// The date and time stamp when the resource was created within the service’s database.
    15  	CreatedAt time.Time `json:"-"`
    16  	// The date and time stamp when the resource was last updated within the service’s database.
    17  	UpdatedAt time.Time `json:"-"`
    18  	// The access rule type.
    19  	AccessType string `json:"access_type"`
    20  	// The value that defines the access. The back end grants or denies the access to it.
    21  	AccessTo string `json:"access_to"`
    22  	// The access credential of the entity granted share access.
    23  	AccessKey string `json:"access_key"`
    24  	// The state of the access rule.
    25  	State string `json:"state"`
    26  	// The access level to the share.
    27  	AccessLevel string `json:"access_level"`
    28  	// The access rule ID.
    29  	ID string `json:"id"`
    30  	// Access rule metadata.
    31  	Metadata map[string]interface{} `json:"metadata"`
    32  }
    33  
    34  func (r *ShareAccess) UnmarshalJSON(b []byte) error {
    35  	type tmp ShareAccess
    36  	var s struct {
    37  		tmp
    38  		CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
    39  		UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
    40  	}
    41  	err := json.Unmarshal(b, &s)
    42  	if err != nil {
    43  		return err
    44  	}
    45  	*r = ShareAccess(s.tmp)
    46  
    47  	r.CreatedAt = time.Time(s.CreatedAt)
    48  	r.UpdatedAt = time.Time(s.UpdatedAt)
    49  
    50  	return nil
    51  }
    52  
    53  // GetResult contains the response body and error from a Get request.
    54  type GetResult struct {
    55  	gophercloud.Result
    56  }
    57  
    58  // Extract will get the ShareAccess object from the GetResult.
    59  func (r GetResult) Extract() (*ShareAccess, error) {
    60  	var s struct {
    61  		ShareAccess *ShareAccess `json:"access"`
    62  	}
    63  	err := r.ExtractInto(&s)
    64  	return s.ShareAccess, err
    65  }
    66  
    67  // ListResult contains the response body and error from a List request.
    68  type ListResult struct {
    69  	gophercloud.Result
    70  }
    71  
    72  func (r ListResult) Extract() ([]ShareAccess, error) {
    73  	var s struct {
    74  		AccessList []ShareAccess `json:"access_list"`
    75  	}
    76  	err := r.ExtractInto(&s)
    77  	return s.AccessList, err
    78  }