github.com/google/go-github/v74@v74.0.0/github/enterprise_manage_ghes_maintenance.go (about)

     1  // Copyright 2025 The go-github AUTHORS. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package github
     7  
     8  import (
     9  	"context"
    10  )
    11  
    12  // MaintenanceOperationStatus represents the message to be displayed when the instance gets a maintenance operation request.
    13  type MaintenanceOperationStatus struct {
    14  	Hostname *string `json:"hostname,omitempty"`
    15  	UUID     *string `json:"uuid,omitempty"`
    16  	Message  *string `json:"message,omitempty"`
    17  }
    18  
    19  // MaintenanceStatus represents the status of maintenance mode for all nodes.
    20  type MaintenanceStatus struct {
    21  	Hostname               *string                  `json:"hostname,omitempty"`
    22  	UUID                   *string                  `json:"uuid,omitempty"`
    23  	Status                 *string                  `json:"status,omitempty"`
    24  	ScheduledTime          *Timestamp               `json:"scheduled_time,omitempty"`
    25  	ConnectionServices     []*ConnectionServiceItem `json:"connection_services,omitempty"`
    26  	CanUnsetMaintenance    *bool                    `json:"can_unset_maintenance,omitempty"`
    27  	IPExceptionList        []string                 `json:"ip_exception_list,omitempty"`
    28  	MaintenanceModeMessage *string                  `json:"maintenance_mode_message,omitempty"`
    29  }
    30  
    31  // ConnectionServiceItem represents the connection services for the maintenance status.
    32  type ConnectionServiceItem struct {
    33  	Name   *string `json:"name,omitempty"`
    34  	Number *int    `json:"number,omitempty"`
    35  }
    36  
    37  // MaintenanceOptions represents the options for setting the maintenance mode for the instance.
    38  // When can be a string, so we can't use a Timestamp type.
    39  type MaintenanceOptions struct {
    40  	Enabled                bool     `json:"enabled"`
    41  	UUID                   *string  `json:"uuid,omitempty"`
    42  	When                   *string  `json:"when,omitempty"`
    43  	IPExceptionList        []string `json:"ip_exception_list,omitempty"`
    44  	MaintenanceModeMessage *string  `json:"maintenance_mode_message,omitempty"`
    45  }
    46  
    47  // GetMaintenanceStatus gets the status of maintenance mode for all nodes.
    48  //
    49  // GitHub API docs: https://docs.github.com/enterprise-server@3.17/rest/enterprise-admin/manage-ghes#get-the-status-of-maintenance-mode
    50  //
    51  //meta:operation GET /manage/v1/maintenance
    52  func (s *EnterpriseService) GetMaintenanceStatus(ctx context.Context, opts *NodeQueryOptions) ([]*MaintenanceStatus, *Response, error) {
    53  	u, err := addOptions("manage/v1/maintenance", opts)
    54  	if err != nil {
    55  		return nil, nil, err
    56  	}
    57  	req, err := s.client.NewRequest("GET", u, nil)
    58  	if err != nil {
    59  		return nil, nil, err
    60  	}
    61  
    62  	var status []*MaintenanceStatus
    63  	resp, err := s.client.Do(ctx, req, &status)
    64  	if err != nil {
    65  		return nil, resp, err
    66  	}
    67  
    68  	return status, resp, nil
    69  }
    70  
    71  // CreateMaintenance sets the maintenance mode for the instance.
    72  // With the enable parameter we can control to put instance into maintenance mode or not. With false we can disable the maintenance mode.
    73  //
    74  // GitHub API docs: https://docs.github.com/enterprise-server@3.17/rest/enterprise-admin/manage-ghes#set-the-status-of-maintenance-mode
    75  //
    76  //meta:operation POST /manage/v1/maintenance
    77  func (s *EnterpriseService) CreateMaintenance(ctx context.Context, enable bool, opts *MaintenanceOptions) ([]*MaintenanceOperationStatus, *Response, error) {
    78  	u := "manage/v1/maintenance"
    79  
    80  	opts.Enabled = enable
    81  
    82  	req, err := s.client.NewRequest("POST", u, opts)
    83  	if err != nil {
    84  		return nil, nil, err
    85  	}
    86  
    87  	var i []*MaintenanceOperationStatus
    88  	resp, err := s.client.Do(ctx, req, &i)
    89  	if err != nil {
    90  		return nil, resp, err
    91  	}
    92  
    93  	return i, resp, nil
    94  }