account_maintenance.go raw

   1  package linodego
   2  
   3  import (
   4  	"context"
   5  	"encoding/json"
   6  	"time"
   7  
   8  	"github.com/linode/linodego/internal/parseabletime"
   9  )
  10  
  11  // AccountMaintenance represents a Maintenance object for any entity a user has permissions to view
  12  type AccountMaintenance struct {
  13  	Entity *Entity `json:"entity"`
  14  	Reason string  `json:"reason"`
  15  	Status string  `json:"status"`
  16  	Type   string  `json:"type"`
  17  
  18  	// NOTE: MaintenancePolicySet can only be used with v4beta.
  19  	MaintenancePolicySet string `json:"maintenance_policy_set"`
  20  
  21  	Description  string     `json:"description"`
  22  	Source       string     `json:"source"`
  23  	NotBefore    *time.Time `json:"-"`
  24  	StartTime    *time.Time `json:"-"`
  25  	CompleteTime *time.Time `json:"-"`
  26  
  27  	// Deprecated: When is a deprecated property
  28  	When *time.Time `json:"when"`
  29  }
  30  
  31  // Entity represents the entity being affected by maintenance
  32  type Entity struct {
  33  	ID    int    `json:"id"`
  34  	Label string `json:"label"`
  35  	Type  string `json:"type"`
  36  	URL   string `json:"url"`
  37  }
  38  
  39  // UnmarshalJSON implements the json.Unmarshaler interface
  40  func (accountMaintenance *AccountMaintenance) UnmarshalJSON(b []byte) error {
  41  	type Mask AccountMaintenance
  42  
  43  	p := struct {
  44  		*Mask
  45  
  46  		NotBefore    *parseabletime.ParseableTime `json:"not_before"`
  47  		StartTime    *parseabletime.ParseableTime `json:"start_time"`
  48  		CompleteTime *parseabletime.ParseableTime `json:"complete_time"`
  49  		When         *parseabletime.ParseableTime `json:"when"`
  50  	}{
  51  		Mask: (*Mask)(accountMaintenance),
  52  	}
  53  
  54  	if err := json.Unmarshal(b, &p); err != nil {
  55  		return err
  56  	}
  57  
  58  	accountMaintenance.NotBefore = (*time.Time)(p.NotBefore)
  59  	accountMaintenance.StartTime = (*time.Time)(p.StartTime)
  60  	accountMaintenance.CompleteTime = (*time.Time)(p.CompleteTime)
  61  	accountMaintenance.When = (*time.Time)(p.When)
  62  
  63  	return nil
  64  }
  65  
  66  // ListMaintenances lists Account Maintenance objects for any entity a user has permissions to view
  67  func (c *Client) ListMaintenances(ctx context.Context, opts *ListOptions) ([]AccountMaintenance, error) {
  68  	return getPaginatedResults[AccountMaintenance](ctx, c, "account/maintenance", opts)
  69  }
  70