-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathenterprise_billing_cost_centers.go
More file actions
233 lines (193 loc) · 8.13 KB
/
enterprise_billing_cost_centers.go
File metadata and controls
233 lines (193 loc) · 8.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// Copyright 2025 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"fmt"
)
// CostCenter represents an enterprise cost center.
type CostCenter struct {
ID string `json:"id"`
Name string `json:"name"`
Resources []*CostCenterResource `json:"resources"`
State *string `json:"state,omitempty"`
AzureSubscription *string `json:"azure_subscription,omitempty"`
}
// CostCenterResource represents a resource assigned to a cost center.
type CostCenterResource struct {
Type string `json:"type"`
Name string `json:"name"`
}
// CostCenters represents a list of cost centers.
type CostCenters struct {
CostCenters []*CostCenter `json:"costCenters,omitempty"`
}
// ListCostCenterOptions specifies optional parameters to the EnterpriseService.ListCostCenters method.
type ListCostCenterOptions struct {
// Set to `active` or `deleted` to only list cost centers in a specific state.
State *string `url:"state,omitempty"`
}
// CostCenterRequest represents a request to create or update a cost center.
type CostCenterRequest struct {
Name string `json:"name"`
}
// CostCenterResourceRequest represents a request to add or remove resources from a cost center.
type CostCenterResourceRequest struct {
Users []string `json:"users,omitempty"`
Organizations []string `json:"organizations,omitempty"`
Repositories []string `json:"repositories,omitempty"`
}
// AddResourcesToCostCenterResponse represents a response from adding resources to a cost center.
type AddResourcesToCostCenterResponse struct {
Message *string `json:"message,omitempty"`
ReassignedResources []*ReassignedResource `json:"reassigned_resources,omitempty"`
}
// ReassignedResource represents a resource that was reassigned from another cost center.
type ReassignedResource struct {
ResourceType *string `json:"resource_type,omitempty"`
Name *string `json:"name,omitempty"`
PreviousCostCenter *string `json:"previous_cost_center,omitempty"`
}
// RemoveResourcesFromCostCenterResponse represents a response from removing resources from a cost center.
type RemoveResourcesFromCostCenterResponse struct {
Message *string `json:"message,omitempty"`
}
// DeleteCostCenterResponse represents a response from deleting a cost center.
type DeleteCostCenterResponse struct {
Message string `json:"message"`
ID string `json:"id"`
Name string `json:"name"`
CostCenterState string `json:"costCenterState"`
}
// ListCostCenters lists all cost centers for an enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/cost-centers#get-all-cost-centers-for-an-enterprise
//
//meta:operation GET /enterprises/{enterprise}/settings/billing/cost-centers
func (s *EnterpriseService) ListCostCenters(ctx context.Context, enterprise string, opts *ListCostCenterOptions) (*CostCenters, *Response, error) {
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers", enterprise)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
costCenters := &CostCenters{}
resp, err := s.client.Do(ctx, req, costCenters)
if err != nil {
return nil, resp, err
}
return costCenters, resp, nil
}
// CreateCostCenter creates a new cost center for an enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/cost-centers#create-a-new-cost-center
//
//meta:operation POST /enterprises/{enterprise}/settings/billing/cost-centers
func (s *EnterpriseService) CreateCostCenter(ctx context.Context, enterprise string, costCenter CostCenterRequest) (*CostCenter, *Response, error) {
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers", enterprise)
req, err := s.client.NewRequest("POST", u, costCenter)
if err != nil {
return nil, nil, err
}
result := &CostCenter{}
resp, err := s.client.Do(ctx, req, result)
if err != nil {
return nil, resp, err
}
return result, resp, nil
}
// GetCostCenter gets a cost center by ID for an enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/cost-centers#get-a-cost-center-by-id
//
//meta:operation GET /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}
func (s *EnterpriseService) GetCostCenter(ctx context.Context, enterprise, costCenterID string) (*CostCenter, *Response, error) {
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers/%v", enterprise, costCenterID)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
costCenter := &CostCenter{}
resp, err := s.client.Do(ctx, req, costCenter)
if err != nil {
return nil, resp, err
}
return costCenter, resp, nil
}
// UpdateCostCenter updates the name of a cost center.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/cost-centers#update-a-cost-center-name
//
//meta:operation PATCH /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}
func (s *EnterpriseService) UpdateCostCenter(ctx context.Context, enterprise, costCenterID string, costCenter CostCenterRequest) (*CostCenter, *Response, error) {
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers/%v", enterprise, costCenterID)
req, err := s.client.NewRequest("PATCH", u, costCenter)
if err != nil {
return nil, nil, err
}
result := &CostCenter{}
resp, err := s.client.Do(ctx, req, result)
if err != nil {
return nil, resp, err
}
return result, resp, nil
}
// DeleteCostCenter deletes a cost center.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/cost-centers#delete-a-cost-center
//
//meta:operation DELETE /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}
func (s *EnterpriseService) DeleteCostCenter(ctx context.Context, enterprise, costCenterID string) (*DeleteCostCenterResponse, *Response, error) {
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers/%v", enterprise, costCenterID)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, nil, err
}
result := &DeleteCostCenterResponse{}
resp, err := s.client.Do(ctx, req, result)
if err != nil {
return nil, resp, err
}
return result, resp, nil
}
// AddResourcesToCostCenter adds resources to a cost center.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/cost-centers#add-resources-to-a-cost-center
//
//meta:operation POST /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}/resource
func (s *EnterpriseService) AddResourcesToCostCenter(ctx context.Context, enterprise, costCenterID string, resources CostCenterResourceRequest) (*AddResourcesToCostCenterResponse, *Response, error) {
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers/%v/resource", enterprise, costCenterID)
req, err := s.client.NewRequest("POST", u, resources)
if err != nil {
return nil, nil, err
}
result := &AddResourcesToCostCenterResponse{}
resp, err := s.client.Do(ctx, req, result)
if err != nil {
return nil, resp, err
}
return result, resp, nil
}
// RemoveResourcesFromCostCenter removes resources from a cost center.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/billing/cost-centers#remove-resources-from-a-cost-center
//
//meta:operation DELETE /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}/resource
func (s *EnterpriseService) RemoveResourcesFromCostCenter(ctx context.Context, enterprise, costCenterID string, resources CostCenterResourceRequest) (*RemoveResourcesFromCostCenterResponse, *Response, error) {
u := fmt.Sprintf("enterprises/%v/settings/billing/cost-centers/%v/resource", enterprise, costCenterID)
req, err := s.client.NewRequest("DELETE", u, resources)
if err != nil {
return nil, nil, err
}
result := &RemoveResourcesFromCostCenterResponse{}
resp, err := s.client.Do(ctx, req, result)
if err != nil {
return nil, resp, err
}
return result, resp, nil
}