github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/identity/v3/agency/results.go (about)

     1  package agency
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/golangsdk/openstack/identity/v3/roles"
     6  	"github.com/chnsz/golangsdk/pagination"
     7  )
     8  
     9  type Agency struct {
    10  	ID                  string `json:"id"`
    11  	Name                string `json:"name"`
    12  	DomainID            string `json:"domain_id"`
    13  	DelegatedDomainID   string `json:"trust_domain_id"`
    14  	DelegatedDomainName string `json:"trust_domain_name"`
    15  	Description         string `json:"description"`
    16  	ExpireTime          string `json:"expire_time"`
    17  	CreateTime          string `json:"create_time"`
    18  	// validity period of the agency
    19  	// In create and update response, it can be "FOREVER" or validity hours in int, for example, 480
    20  	// In get response, it can be "FOREVER" or validity hours in string, for example, "480"
    21  	Duration interface{} `json:"duration"`
    22  }
    23  
    24  type commonResult struct {
    25  	golangsdk.Result
    26  }
    27  
    28  func (r commonResult) Extract() (*Agency, error) {
    29  	var s struct {
    30  		Agency *Agency `json:"agency"`
    31  	}
    32  	err := r.ExtractInto(&s)
    33  	return s.Agency, err
    34  }
    35  
    36  type GetResult struct {
    37  	commonResult
    38  }
    39  
    40  type CreateResult struct {
    41  	commonResult
    42  }
    43  
    44  type UpdateResult struct {
    45  	commonResult
    46  }
    47  
    48  type ErrResult struct {
    49  	golangsdk.ErrResult
    50  }
    51  
    52  type ListRolesResult struct {
    53  	golangsdk.Result
    54  }
    55  
    56  func (r ListRolesResult) ExtractRoles() ([]roles.Role, error) {
    57  	var s struct {
    58  		Roles []roles.Role `json:"roles"`
    59  	}
    60  	err := r.ExtractInto(&s)
    61  	return s.Roles, err
    62  }
    63  
    64  type InheritedRole struct {
    65  	ID   string `json:"id"`
    66  	Name string `json:"name"`
    67  
    68  	// Links contains referencing links to the role.
    69  	Links map[string]interface{} `json:"links"`
    70  }
    71  
    72  type ListInheritedRolesResult struct {
    73  	golangsdk.Result
    74  }
    75  
    76  func (r ListInheritedRolesResult) ExtractRoles() ([]InheritedRole, error) {
    77  	var s struct {
    78  		Roles []InheritedRole `json:"roles"`
    79  	}
    80  	err := r.ExtractInto(&s)
    81  	return s.Roles, err
    82  }
    83  
    84  type AgencyPage struct {
    85  	pagination.SinglePageBase
    86  }
    87  
    88  func ExtractList(r pagination.Page) ([]Agency, error) {
    89  	var s struct {
    90  		Agencies []Agency `json:"agencies"`
    91  	}
    92  	err := (r.(AgencyPage)).ExtractInto(&s)
    93  	return s.Agencies, err
    94  }