github.com/google/go-github/v74@v74.0.0/github/enterprise_network_configurations.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 "fmt" 11 ) 12 13 // ListEnterpriseNetworkConfigurations lists all hosted compute network configurations configured in an enterprise. 14 // 15 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/network-configurations#list-hosted-compute-network-configurations-for-an-enterprise 16 // 17 //meta:operation GET /enterprises/{enterprise}/network-configurations 18 func (s *EnterpriseService) ListEnterpriseNetworkConfigurations(ctx context.Context, enterprise string, opts *ListOptions) (*NetworkConfigurations, *Response, error) { 19 u := fmt.Sprintf("enterprises/%v/network-configurations", enterprise) 20 u, err := addOptions(u, opts) 21 if err != nil { 22 return nil, nil, err 23 } 24 25 req, err := s.client.NewRequest("GET", u, nil) 26 if err != nil { 27 return nil, nil, err 28 } 29 30 networks := &NetworkConfigurations{} 31 resp, err := s.client.Do(ctx, req, networks) 32 if err != nil { 33 return nil, resp, err 34 } 35 return networks, resp, nil 36 } 37 38 // CreateEnterpriseNetworkConfiguration creates a hosted compute network configuration for an enterprise. 39 // 40 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/network-configurations#create-a-hosted-compute-network-configuration-for-an-enterprise 41 // 42 //meta:operation POST /enterprises/{enterprise}/network-configurations 43 func (s *EnterpriseService) CreateEnterpriseNetworkConfiguration(ctx context.Context, enterprise string, createReq NetworkConfigurationRequest) (*NetworkConfiguration, *Response, error) { 44 if err := validateNetworkConfigurationRequest(createReq); err != nil { 45 return nil, nil, fmt.Errorf("validation failed: %w", err) 46 } 47 48 u := fmt.Sprintf("enterprises/%v/network-configurations", enterprise) 49 req, err := s.client.NewRequest("POST", u, createReq) 50 if err != nil { 51 return nil, nil, err 52 } 53 54 network := &NetworkConfiguration{} 55 resp, err := s.client.Do(ctx, req, network) 56 if err != nil { 57 return nil, resp, err 58 } 59 60 return network, resp, nil 61 } 62 63 // GetEnterpriseNetworkConfiguration gets a hosted compute network configuration configured in an enterprise. 64 // 65 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/network-configurations#get-a-hosted-compute-network-configuration-for-an-enterprise 66 // 67 //meta:operation GET /enterprises/{enterprise}/network-configurations/{network_configuration_id} 68 func (s *EnterpriseService) GetEnterpriseNetworkConfiguration(ctx context.Context, enterprise, networkID string) (*NetworkConfiguration, *Response, error) { 69 u := fmt.Sprintf("enterprises/%v/network-configurations/%v", enterprise, networkID) 70 req, err := s.client.NewRequest("GET", u, nil) 71 if err != nil { 72 return nil, nil, err 73 } 74 75 network := &NetworkConfiguration{} 76 resp, err := s.client.Do(ctx, req, network) 77 if err != nil { 78 return nil, resp, err 79 } 80 return network, resp, nil 81 } 82 83 // UpdateEnterpriseNetworkConfiguration updates a hosted compute network configuration for an enterprise. 84 // 85 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/network-configurations#update-a-hosted-compute-network-configuration-for-an-enterprise 86 // 87 //meta:operation PATCH /enterprises/{enterprise}/network-configurations/{network_configuration_id} 88 func (s *EnterpriseService) UpdateEnterpriseNetworkConfiguration(ctx context.Context, enterprise, networkID string, updateReq NetworkConfigurationRequest) (*NetworkConfiguration, *Response, error) { 89 if err := validateNetworkConfigurationRequest(updateReq); err != nil { 90 return nil, nil, fmt.Errorf("validation failed: %w", err) 91 } 92 93 u := fmt.Sprintf("enterprises/%v/network-configurations/%v", enterprise, networkID) 94 req, err := s.client.NewRequest("PATCH", u, updateReq) 95 if err != nil { 96 return nil, nil, err 97 } 98 99 network := &NetworkConfiguration{} 100 resp, err := s.client.Do(ctx, req, network) 101 if err != nil { 102 return nil, resp, err 103 } 104 return network, resp, nil 105 } 106 107 // DeleteEnterpriseNetworkConfiguration deletes a hosted compute network configuration from an enterprise. 108 // 109 // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/network-configurations#delete-a-hosted-compute-network-configuration-from-an-enterprise 110 // 111 //meta:operation DELETE /enterprises/{enterprise}/network-configurations/{network_configuration_id} 112 func (s *EnterpriseService) DeleteEnterpriseNetworkConfiguration(ctx context.Context, enterprise, networkID string) (*Response, error) { 113 u := fmt.Sprintf("enterprises/%v/network-configurations/%v", enterprise, networkID) 114 req, err := s.client.NewRequest("DELETE", u, nil) 115 if err != nil { 116 return nil, err 117 } 118 return s.client.Do(ctx, req, nil) 119 } 120 121 // GetEnterpriseNetworkSettingsResource gets a hosted compute network settings resource configured for an enterprise. 122 // 123 // 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 124 // 125 //meta:operation GET /enterprises/{enterprise}/network-settings/{network_settings_id} 126 func (s *EnterpriseService) GetEnterpriseNetworkSettingsResource(ctx context.Context, enterprise, networkID string) (*NetworkSettingsResource, *Response, error) { 127 u := fmt.Sprintf("enterprises/%v/network-settings/%v", enterprise, networkID) 128 req, err := s.client.NewRequest("GET", u, nil) 129 if err != nil { 130 return nil, nil, err 131 } 132 133 resource := &NetworkSettingsResource{} 134 resp, err := s.client.Do(ctx, req, resource) 135 if err != nil { 136 return nil, resp, err 137 } 138 return resource, resp, err 139 }