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

     1  package securityservices
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/gophercloud/gophercloud"
     8  	"github.com/gophercloud/gophercloud/pagination"
     9  )
    10  
    11  // SecurityService contains all the information associated with an OpenStack
    12  // SecurityService.
    13  type SecurityService struct {
    14  	// The security service ID
    15  	ID string `json:"id"`
    16  	// The UUID of the project where the security service was created
    17  	ProjectID string `json:"project_id"`
    18  	// The security service domain
    19  	Domain string `json:"domain"`
    20  	// The security service status
    21  	Status string `json:"status"`
    22  	// The security service type. A valid value is ldap, kerberos, or active_directory
    23  	Type string `json:"type"`
    24  	// The security service name
    25  	Name string `json:"name"`
    26  	// The security service description
    27  	Description string `json:"description"`
    28  	// The DNS IP address that is used inside the tenant network
    29  	DNSIP string `json:"dns_ip"`
    30  	// The security service organizational unit (OU)
    31  	OU string `json:"ou"`
    32  	// The security service user or group name that is used by the tenant
    33  	User string `json:"user"`
    34  	// The user password, if you specify a user
    35  	Password string `json:"password"`
    36  	// The security service host name or IP address
    37  	Server string `json:"server"`
    38  	// The date and time stamp when the security service was created
    39  	CreatedAt time.Time `json:"-"`
    40  	// The date and time stamp when the security service was updated
    41  	UpdatedAt time.Time `json:"-"`
    42  }
    43  
    44  func (r *SecurityService) UnmarshalJSON(b []byte) error {
    45  	type tmp SecurityService
    46  	var s struct {
    47  		tmp
    48  		CreatedAt gophercloud.JSONRFC3339MilliNoZ `json:"created_at"`
    49  		UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"`
    50  	}
    51  	err := json.Unmarshal(b, &s)
    52  	if err != nil {
    53  		return err
    54  	}
    55  	*r = SecurityService(s.tmp)
    56  
    57  	r.CreatedAt = time.Time(s.CreatedAt)
    58  	r.UpdatedAt = time.Time(s.UpdatedAt)
    59  
    60  	return nil
    61  }
    62  
    63  type commonResult struct {
    64  	gophercloud.Result
    65  }
    66  
    67  // SecurityServicePage is a pagination.pager that is returned from a call to the List function.
    68  type SecurityServicePage struct {
    69  	pagination.SinglePageBase
    70  }
    71  
    72  // IsEmpty returns true if a ListResult contains no SecurityServices.
    73  func (r SecurityServicePage) IsEmpty() (bool, error) {
    74  	if r.StatusCode == 204 {
    75  		return true, nil
    76  	}
    77  
    78  	securityServices, err := ExtractSecurityServices(r)
    79  	return len(securityServices) == 0, err
    80  }
    81  
    82  // ExtractSecurityServices extracts and returns SecurityServices. It is used while
    83  // iterating over a securityservices.List call.
    84  func ExtractSecurityServices(r pagination.Page) ([]SecurityService, error) {
    85  	var s struct {
    86  		SecurityServices []SecurityService `json:"security_services"`
    87  	}
    88  	err := (r.(SecurityServicePage)).ExtractInto(&s)
    89  	return s.SecurityServices, err
    90  }
    91  
    92  // Extract will get the SecurityService object out of the commonResult object.
    93  func (r commonResult) Extract() (*SecurityService, error) {
    94  	var s struct {
    95  		SecurityService *SecurityService `json:"security_service"`
    96  	}
    97  	err := r.ExtractInto(&s)
    98  	return s.SecurityService, err
    99  }
   100  
   101  // CreateResult contains the response body and error from a Create request.
   102  type CreateResult struct {
   103  	commonResult
   104  }
   105  
   106  // DeleteResult contains the response body and error from a Delete request.
   107  type DeleteResult struct {
   108  	gophercloud.ErrResult
   109  }
   110  
   111  // GetResult contains the response body and error from a Get request.
   112  type GetResult struct {
   113  	commonResult
   114  }
   115  
   116  // UpdateResult contains the response body and error from an Update request.
   117  type UpdateResult struct {
   118  	commonResult
   119  }