Skip to content

Commit 470d43a

Browse files
authored
feat: Add support for network-configurations endpoints (#3497)
1 parent d0976cc commit 470d43a

File tree

4 files changed

+727
-0
lines changed

4 files changed

+727
-0
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
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+
"fmt"
11+
)
12+
13+
// ComputeService represents a hosted compute service the network configuration supports.
14+
type ComputeService string
15+
16+
const (
17+
ComputeServiceNone ComputeService = "none"
18+
ComputeServiceActions ComputeService = "actions"
19+
)
20+
21+
// EnterpriseNetworkConfiguration represents a hosted compute network configuration.
22+
type EnterpriseNetworkConfiguration struct {
23+
ID *string `json:"id,omitempty"`
24+
Name *string `json:"name,omitempty"`
25+
ComputeService *ComputeService `json:"compute_service,omitempty"`
26+
NetworkSettingsIDs []string `json:"network_settings_ids,omitempty"`
27+
CreatedOn *Timestamp `json:"created_on,omitempty"`
28+
}
29+
30+
// EnterpriseNetworkConfigurations represents a hosted compute network configurations.
31+
type EnterpriseNetworkConfigurations struct {
32+
TotalCount *int64 `json:"total_count,omitempty"`
33+
NetworkConfigurations []*EnterpriseNetworkConfiguration `json:"network_configurations,omitempty"`
34+
}
35+
36+
// EnterpriseNetworkSettingsResource represents a hosted compute network settings resource.
37+
type EnterpriseNetworkSettingsResource struct {
38+
ID *string `json:"id,omitempty"`
39+
Name *string `json:"name,omitempty"`
40+
NetworkConfigurationID *string `json:"network_configuration_id,omitempty"`
41+
SubnetID *string `json:"subnet_id,omitempty"`
42+
Region *string `json:"region,omitempty"`
43+
}
44+
45+
// EnterpriseNetworkConfigurationRequest represents a request to create or update a network configuration for an enterprise.
46+
type EnterpriseNetworkConfigurationRequest struct {
47+
Name *string `json:"name,omitempty"`
48+
ComputeService *ComputeService `json:"compute_service,omitempty"`
49+
NetworkSettingsIDs []string `json:"network_settings_ids,omitempty"`
50+
}
51+
52+
// ListEnterpriseNetworkConfigurations lists all hosted compute network configurations configured in an enterprise.
53+
//
54+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/network-configurations#list-hosted-compute-network-configurations-for-an-enterprise
55+
//
56+
//meta:operation GET /enterprises/{enterprise}/network-configurations
57+
func (s *EnterpriseService) ListEnterpriseNetworkConfigurations(ctx context.Context, enterprise string, opts *ListOptions) (*EnterpriseNetworkConfigurations, *Response, error) {
58+
u := fmt.Sprintf("enterprises/%v/network-configurations", enterprise)
59+
u, err := addOptions(u, opts)
60+
if err != nil {
61+
return nil, nil, err
62+
}
63+
64+
req, err := s.client.NewRequest("GET", u, nil)
65+
if err != nil {
66+
return nil, nil, err
67+
}
68+
69+
networks := &EnterpriseNetworkConfigurations{}
70+
resp, err := s.client.Do(ctx, req, networks)
71+
if err != nil {
72+
return nil, resp, err
73+
}
74+
return networks, resp, nil
75+
}
76+
77+
// CreateEnterpriseNetworkConfiguration creates a hosted compute network configuration for an enterprise.
78+
//
79+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/network-configurations#create-a-hosted-compute-network-configuration-for-an-enterprise
80+
//
81+
//meta:operation POST /enterprises/{enterprise}/network-configurations
82+
func (s *EnterpriseService) CreateEnterpriseNetworkConfiguration(ctx context.Context, enterprise string, createReq EnterpriseNetworkConfigurationRequest) (*EnterpriseNetworkConfiguration, *Response, error) {
83+
u := fmt.Sprintf("enterprises/%v/network-configurations", enterprise)
84+
req, err := s.client.NewRequest("POST", u, createReq)
85+
if err != nil {
86+
return nil, nil, err
87+
}
88+
89+
network := &EnterpriseNetworkConfiguration{}
90+
resp, err := s.client.Do(ctx, req, network)
91+
if err != nil {
92+
return nil, resp, err
93+
}
94+
95+
return network, resp, nil
96+
}
97+
98+
// GetEnterpriseNetworkConfiguration gets a hosted compute network configuration configured in an enterprise.
99+
//
100+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/network-configurations#get-a-hosted-compute-network-configuration-for-an-enterprise
101+
//
102+
//meta:operation GET /enterprises/{enterprise}/network-configurations/{network_configuration_id}
103+
func (s *EnterpriseService) GetEnterpriseNetworkConfiguration(ctx context.Context, enterprise, networkID string) (*EnterpriseNetworkConfiguration, *Response, error) {
104+
u := fmt.Sprintf("enterprises/%v/network-configurations/%v", enterprise, networkID)
105+
req, err := s.client.NewRequest("GET", u, nil)
106+
if err != nil {
107+
return nil, nil, err
108+
}
109+
110+
network := &EnterpriseNetworkConfiguration{}
111+
resp, err := s.client.Do(ctx, req, network)
112+
if err != nil {
113+
return nil, resp, err
114+
}
115+
return network, resp, nil
116+
}
117+
118+
// UpdateEnterpriseNetworkConfiguration updates a hosted compute network configuration for an enterprise.
119+
//
120+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/network-configurations#update-a-hosted-compute-network-configuration-for-an-enterprise
121+
//
122+
//meta:operation PATCH /enterprises/{enterprise}/network-configurations/{network_configuration_id}
123+
func (s *EnterpriseService) UpdateEnterpriseNetworkConfiguration(ctx context.Context, enterprise, networkID string, updateReq EnterpriseNetworkConfigurationRequest) (*EnterpriseNetworkConfiguration, *Response, error) {
124+
u := fmt.Sprintf("enterprises/%v/network-configurations/%v", enterprise, networkID)
125+
req, err := s.client.NewRequest("PATCH", u, updateReq)
126+
if err != nil {
127+
return nil, nil, err
128+
}
129+
130+
network := &EnterpriseNetworkConfiguration{}
131+
resp, err := s.client.Do(ctx, req, network)
132+
if err != nil {
133+
return nil, resp, err
134+
}
135+
return network, resp, nil
136+
}
137+
138+
// DeleteEnterpriseNetworkConfiguration deletes a hosted compute network configuration from an enterprise.
139+
//
140+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/network-configurations#delete-a-hosted-compute-network-configuration-from-an-enterprise
141+
//
142+
//meta:operation DELETE /enterprises/{enterprise}/network-configurations/{network_configuration_id}
143+
func (s *EnterpriseService) DeleteEnterpriseNetworkConfiguration(ctx context.Context, enterprise, networkID string) (*Response, error) {
144+
u := fmt.Sprintf("enterprises/%v/network-configurations/%v", enterprise, networkID)
145+
req, err := s.client.NewRequest("DELETE", u, nil)
146+
if err != nil {
147+
return nil, err
148+
}
149+
return s.client.Do(ctx, req, nil)
150+
}
151+
152+
// GetEnterpriseNetworkSettingsResource gets a hosted compute network settings resource configured for an enterprise.
153+
//
154+
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/network-configurations#get-a-hosted-compute-network-settings-resource-for-an-enterprise
155+
//
156+
//meta:operation GET /enterprises/{enterprise}/network-settings/{network_settings_id}
157+
func (s *EnterpriseService) GetEnterpriseNetworkSettingsResource(ctx context.Context, enterprise, networkID string) (*EnterpriseNetworkSettingsResource, *Response, error) {
158+
u := fmt.Sprintf("enterprises/%v/network-settings/%v", enterprise, networkID)
159+
req, err := s.client.NewRequest("GET", u, nil)
160+
if err != nil {
161+
return nil, nil, err
162+
}
163+
164+
resource := &EnterpriseNetworkSettingsResource{}
165+
resp, err := s.client.Do(ctx, req, resource)
166+
if err != nil {
167+
return nil, resp, err
168+
}
169+
return resource, resp, err
170+
}

0 commit comments

Comments
 (0)