github.com/google/go-github/v70@v70.0.0/github/enterprise_manage_ghes_config.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 "errors" 11 ) 12 13 // ConfigApplyOptions is a struct to hold the options for the ConfigApply API and the response. 14 type ConfigApplyOptions struct { 15 // RunID is the ID of the run to get the status of. If empty a random one will be generated. 16 RunID *string `json:"run_id,omitempty"` 17 } 18 19 // ConfigApplyStatus is a struct to hold the response from the ConfigApply API. 20 type ConfigApplyStatus struct { 21 Running *bool `json:"running,omitempty"` 22 Successful *bool `json:"successful,omitempty"` 23 Nodes []*ConfigApplyStatusNode `json:"nodes"` 24 } 25 26 // ConfigApplyStatusNode is a struct to hold the response from the ConfigApply API. 27 type ConfigApplyStatusNode struct { 28 Hostname *string `json:"hostname,omitempty"` 29 Running *bool `json:"running,omitempty"` 30 Successful *bool `json:"successful,omitempty"` 31 RunID *string `json:"run_id,omitempty"` 32 } 33 34 // ConfigApplyEventsOptions is used to enable pagination. 35 type ConfigApplyEventsOptions struct { 36 LastRequestID *string `url:"last_request_id,omitempty"` 37 } 38 39 // ConfigApplyEvents is a struct to hold the response from the ConfigApplyEvents API. 40 type ConfigApplyEvents struct { 41 Nodes []*ConfigApplyEventsNode `json:"nodes"` 42 } 43 44 // ConfigApplyEventsNode is a struct to hold the response from the ConfigApplyEvents API. 45 type ConfigApplyEventsNode struct { 46 Node *string `json:"node,omitempty"` 47 LastRequestID *string `json:"last_request_id,omitempty"` 48 Events []*ConfigApplyEventsNodeEvent `json:"events"` 49 } 50 51 // ConfigApplyEventsNodeEvent is a struct to hold the response from the ConfigApplyEvents API. 52 type ConfigApplyEventsNodeEvent struct { 53 Timestamp *Timestamp `json:"timestamp,omitempty"` 54 SeverityText *string `json:"severity_text,omitempty"` 55 Body *string `json:"body,omitempty"` 56 EventName *string `json:"event_name,omitempty"` 57 Topology *string `json:"topology,omitempty"` 58 Hostname *string `json:"hostname,omitempty"` 59 ConfigRunID *string `json:"config_run_id,omitempty"` 60 TraceID *string `json:"trace_id,omitempty"` 61 SpanID *string `json:"span_id,omitempty"` 62 SpanParentID *int64 `json:"span_parent_id,omitempty"` 63 SpanDepth *int `json:"span_depth,omitempty"` 64 } 65 66 // InitialConfigOptions is a struct to hold the options for the InitialConfig API. 67 type InitialConfigOptions struct { 68 License string `url:"license"` 69 Password string `url:"password"` 70 } 71 72 // LicenseStatus is a struct to hold the response from the License API. 73 type LicenseStatus struct { 74 AdvancedSecurityEnabled *bool `json:"advancedSecurityEnabled,omitempty"` 75 AdvancedSecuritySeats *int `json:"advancedSecuritySeats,omitempty"` 76 ClusterSupport *bool `json:"clusterSupport,omitempty"` 77 Company *string `json:"company,omitempty"` 78 CroquetSupport *bool `json:"croquetSupport,omitempty"` 79 CustomTerms *bool `json:"customTerms,omitempty"` 80 Evaluation *bool `json:"evaluation,omitempty"` 81 ExpireAt *Timestamp `json:"expireAt,omitempty"` 82 InsightsEnabled *bool `json:"insightsEnabled,omitempty"` 83 InsightsExpireAt *Timestamp `json:"insightsExpireAt,omitempty"` 84 LearningLabEvaluationExpires *Timestamp `json:"learningLabEvaluationExpires,omitempty"` 85 LearningLabSeats *int `json:"learningLabSeats,omitempty"` 86 Perpetual *bool `json:"perpetual,omitempty"` 87 ReferenceNumber *string `json:"referenceNumber,omitempty"` 88 Seats *int `json:"seats,omitempty"` 89 SSHAllowed *bool `json:"sshAllowed,omitempty"` 90 SupportKey *string `json:"supportKey,omitempty"` 91 UnlimitedSeating *bool `json:"unlimitedSeating,omitempty"` 92 } 93 94 // UploadLicenseOptions is a struct to hold the options for the UploadLicense API. 95 type UploadLicenseOptions struct { 96 License string `url:"license"` 97 } 98 99 // LicenseCheck is a struct to hold the response from the LicenseStatus API. 100 type LicenseCheck struct { 101 Status *string `json:"status,omitempty"` 102 } 103 104 // ConfigSettings is a struct to hold the response from the Settings API. 105 // There are many fields that link to other structs. 106 type ConfigSettings struct { 107 PrivateMode *bool `json:"private_mode,omitempty"` 108 PublicPages *bool `json:"public_pages,omitempty"` 109 SubdomainIsolation *bool `json:"subdomain_isolation,omitempty"` 110 SignupEnabled *bool `json:"signup_enabled,omitempty"` 111 GithubHostname *string `json:"github_hostname,omitempty"` 112 IdenticonsHost *string `json:"identicons_host,omitempty"` 113 HTTPProxy *string `json:"http_proxy,omitempty"` 114 AuthMode *string `json:"auth_mode,omitempty"` 115 ExpireSessions *bool `json:"expire_sessions,omitempty"` 116 AdminPassword *string `json:"admin_password,omitempty"` 117 ConfigurationID *int64 `json:"configuration_id,omitempty"` 118 ConfigurationRunCount *int `json:"configuration_run_count,omitempty"` 119 Avatar *ConfigSettingsAvatar `json:"avatar,omitempty"` 120 Customer *ConfigSettingsCustomer `json:"customer,omitempty"` 121 License *ConfigSettingsLicenseSettings `json:"license,omitempty"` 122 GithubSSL *ConfigSettingsGithubSSL `json:"github_ssl,omitempty"` 123 LDAP *ConfigSettingsLDAP `json:"ldap,omitempty"` 124 CAS *ConfigSettingsCAS `json:"cas,omitempty"` 125 SAML *ConfigSettingsSAML `json:"saml,omitempty"` 126 GithubOAuth *ConfigSettingsGithubOAuth `json:"github_oauth,omitempty"` 127 SMTP *ConfigSettingsSMTP `json:"smtp,omitempty"` 128 NTP *ConfigSettingsNTP `json:"ntp,omitempty"` 129 Timezone *string `json:"timezone,omitempty"` 130 SNMP *ConfigSettingsSNMP `json:"snmp,omitempty"` 131 Syslog *ConfigSettingsSyslog `json:"syslog,omitempty"` 132 Assets *string `json:"assets,omitempty"` 133 Pages *ConfigSettingsPagesSettings `json:"pages,omitempty"` 134 Collectd *ConfigSettingsCollectd `json:"collectd,omitempty"` 135 Mapping *ConfigSettingsMapping `json:"mapping,omitempty"` 136 LoadBalancer *string `json:"load_balancer,omitempty"` 137 } 138 139 // ConfigSettingsAvatar is a struct to hold the response from the Settings API. 140 type ConfigSettingsAvatar struct { 141 Enabled *bool `json:"enabled,omitempty"` 142 URI *string `json:"uri,omitempty"` 143 } 144 145 // ConfigSettingsCustomer is a struct to hold the response from the Settings API. 146 type ConfigSettingsCustomer struct { 147 Name *string `json:"name,omitempty"` 148 Email *string `json:"email,omitempty"` 149 UUID *string `json:"uuid,omitempty"` 150 Secret *string `json:"secret,omitempty"` 151 PublicKeyData *string `json:"public_key_data,omitempty"` 152 } 153 154 // ConfigSettingsLicenseSettings is a struct to hold the response from the Settings API. 155 type ConfigSettingsLicenseSettings struct { 156 Seats *int `json:"seats,omitempty"` 157 Evaluation *bool `json:"evaluation,omitempty"` 158 Perpetual *bool `json:"perpetual,omitempty"` 159 UnlimitedSeating *bool `json:"unlimited_seating,omitempty"` 160 SupportKey *string `json:"support_key,omitempty"` 161 SSHAllowed *bool `json:"ssh_allowed,omitempty"` 162 ClusterSupport *bool `json:"cluster_support,omitempty"` 163 ExpireAt *Timestamp `json:"expire_at,omitempty"` 164 } 165 166 // ConfigSettingsGithubSSL is a struct to hold the response from the Settings API. 167 type ConfigSettingsGithubSSL struct { 168 Enabled *bool `json:"enabled,omitempty"` 169 Cert *string `json:"cert,omitempty"` 170 Key *string `json:"key,omitempty"` 171 } 172 173 // ConfigSettingsLDAP is a struct to hold the response from the Settings API. 174 type ConfigSettingsLDAP struct { 175 Host *string `json:"host,omitempty"` 176 Port *int `json:"port,omitempty"` 177 Base []string `json:"base,omitempty"` 178 UID *string `json:"uid,omitempty"` 179 BindDN *string `json:"bind_dn,omitempty"` 180 Password *string `json:"password,omitempty"` 181 Method *string `json:"method,omitempty"` 182 SearchStrategy *string `json:"search_strategy,omitempty"` 183 UserGroups []string `json:"user_groups,omitempty"` 184 AdminGroup *string `json:"admin_group,omitempty"` 185 VirtualAttributeEnabled *bool `json:"virtual_attribute_enabled,omitempty"` 186 RecursiveGroupSearch *bool `json:"recursive_group_search,omitempty"` 187 PosixSupport *bool `json:"posix_support,omitempty"` 188 UserSyncEmails *bool `json:"user_sync_emails,omitempty"` 189 UserSyncKeys *bool `json:"user_sync_keys,omitempty"` 190 UserSyncInterval *int `json:"user_sync_interval,omitempty"` 191 TeamSyncInterval *int `json:"team_sync_interval,omitempty"` 192 SyncEnabled *bool `json:"sync_enabled,omitempty"` 193 Reconciliation *ConfigSettingsLDAPReconciliation `json:"reconciliation,omitempty"` 194 Profile *ConfigSettingsLDAPProfile `json:"profile,omitempty"` 195 } 196 197 // ConfigSettingsLDAPReconciliation is part of the ConfigSettingsLDAP struct. 198 type ConfigSettingsLDAPReconciliation struct { 199 User *string `json:"user,omitempty"` 200 Org *string `json:"org,omitempty"` 201 } 202 203 // ConfigSettingsLDAPProfile is part of the ConfigSettingsLDAP struct. 204 type ConfigSettingsLDAPProfile struct { 205 UID *string `json:"uid,omitempty"` 206 Name *string `json:"name,omitempty"` 207 Mail *string `json:"mail,omitempty"` 208 Key *string `json:"key,omitempty"` 209 } 210 211 // ConfigSettingsCAS is a struct to hold the response from the Settings API. 212 type ConfigSettingsCAS struct { 213 URL *string `json:"url,omitempty"` 214 } 215 216 // ConfigSettingsSAML is a struct to hold the response from the Settings API. 217 type ConfigSettingsSAML struct { 218 SSOURL *string `json:"sso_url,omitempty"` 219 Certificate *string `json:"certificate,omitempty"` 220 CertificatePath *string `json:"certificate_path,omitempty"` 221 Issuer *string `json:"issuer,omitempty"` 222 IDPInitiatedSSO *bool `json:"idp_initiated_sso,omitempty"` 223 DisableAdminDemote *bool `json:"disable_admin_demote,omitempty"` 224 } 225 226 // ConfigSettingsGithubOAuth is a struct to hold the response from the Settings API. 227 type ConfigSettingsGithubOAuth struct { 228 ClientID *string `json:"client_id,omitempty"` 229 ClientSecret *string `json:"client_secret,omitempty"` 230 OrganizationName *string `json:"organization_name,omitempty"` 231 OrganizationTeam *string `json:"organization_team,omitempty"` 232 } 233 234 // ConfigSettingsSMTP is a struct to hold the response from the Settings API. 235 type ConfigSettingsSMTP struct { 236 Enabled *bool `json:"enabled,omitempty"` 237 Address *string `json:"address,omitempty"` 238 Authentication *string `json:"authentication,omitempty"` 239 Port *string `json:"port,omitempty"` 240 Domain *string `json:"domain,omitempty"` 241 Username *string `json:"username,omitempty"` 242 UserName *string `json:"user_name,omitempty"` 243 EnableStarttlsAuto *bool `json:"enable_starttls_auto,omitempty"` 244 Password *string `json:"password,omitempty"` 245 DiscardToNoreplyAddress *bool `json:"discard-to-noreply-address,omitempty"` 246 SupportAddress *string `json:"support_address,omitempty"` 247 SupportAddressType *string `json:"support_address_type,omitempty"` 248 NoreplyAddress *string `json:"noreply_address,omitempty"` 249 } 250 251 // ConfigSettingsNTP is a struct to hold the response from the Settings API. 252 type ConfigSettingsNTP struct { 253 PrimaryServer *string `json:"primary_server,omitempty"` 254 SecondaryServer *string `json:"secondary_server,omitempty"` 255 } 256 257 // ConfigSettingsSNMP is a struct to hold the response from the Settings API. 258 type ConfigSettingsSNMP struct { 259 Enabled *bool `json:"enabled,omitempty"` 260 Community *string `json:"community,omitempty"` 261 } 262 263 // ConfigSettingsSyslog is a struct to hold the response from the Settings API. 264 type ConfigSettingsSyslog struct { 265 Enabled *bool `json:"enabled,omitempty"` 266 Server *string `json:"server,omitempty"` 267 ProtocolName *string `json:"protocol_name,omitempty"` 268 } 269 270 // ConfigSettingsPagesSettings is a struct to hold the response from the Settings API. 271 type ConfigSettingsPagesSettings struct { 272 Enabled *bool `json:"enabled,omitempty"` 273 } 274 275 // ConfigSettingsCollectd is a struct to hold the response from the Settings API. 276 type ConfigSettingsCollectd struct { 277 Enabled *bool `json:"enabled,omitempty"` 278 Server *string `json:"server,omitempty"` 279 Port *int `json:"port,omitempty"` 280 Encryption *string `json:"encryption,omitempty"` 281 Username *string `json:"username,omitempty"` 282 Password *string `json:"password,omitempty"` 283 } 284 285 // ConfigSettingsMapping is a struct to hold the response from the Settings API. 286 type ConfigSettingsMapping struct { 287 Enabled *bool `json:"enabled,omitempty"` 288 Tileserver *string `json:"tileserver,omitempty"` 289 Basemap *string `json:"basemap,omitempty"` 290 Token *string `json:"token,omitempty"` 291 } 292 293 // NodeMetadataStatus is a struct to hold the response from the NodeMetadata API. 294 type NodeMetadataStatus struct { 295 Topology *string `json:"topology,omitempty"` 296 Nodes []*NodeDetails `json:"nodes"` 297 } 298 299 // NodeDetails is a struct to hold the response from the NodeMetadata API. 300 type NodeDetails struct { 301 Hostname *string `json:"hostname,omitempty"` 302 UUID *string `json:"uuid,omitempty"` 303 ClusterRoles []string `json:"cluster_roles,omitempty"` 304 } 305 306 // ConfigApplyEvents gets events from the command ghe-config-apply. 307 // 308 // GitHub API docs: https://docs.github.com/enterprise-server@3.15/rest/enterprise-admin/manage-ghes#list-events-from-ghe-config-apply 309 // 310 //meta:operation GET /manage/v1/config/apply/events 311 func (s *EnterpriseService) ConfigApplyEvents(ctx context.Context, opts *ConfigApplyEventsOptions) (*ConfigApplyEvents, *Response, error) { 312 u, err := addOptions("manage/v1/config/apply/events", opts) 313 if err != nil { 314 return nil, nil, err 315 } 316 req, err := s.client.NewRequest("GET", u, nil) 317 if err != nil { 318 return nil, nil, err 319 } 320 321 configApplyEvents := new(ConfigApplyEvents) 322 resp, err := s.client.Do(ctx, req, configApplyEvents) 323 if err != nil { 324 return nil, resp, err 325 } 326 327 return configApplyEvents, resp, nil 328 } 329 330 // InitialConfig initializes the GitHub Enterprise instance with a license and password. 331 // After initializing the instance, you need to run an apply to apply the configuration. 332 // 333 // GitHub API docs: https://docs.github.com/enterprise-server@3.15/rest/enterprise-admin/manage-ghes#initialize-instance-configuration-with-license-and-password 334 // 335 //meta:operation POST /manage/v1/config/init 336 func (s *EnterpriseService) InitialConfig(ctx context.Context, license, password string) (*Response, error) { 337 u := "manage/v1/config/init" 338 339 opts := &InitialConfigOptions{ 340 License: license, 341 Password: password, 342 } 343 344 req, err := s.client.NewRequest("POST", u, opts) 345 if err != nil { 346 return nil, err 347 } 348 349 return s.client.Do(ctx, req, nil) 350 } 351 352 // License gets the current license information for the GitHub Enterprise instance. 353 // 354 // GitHub API docs: https://docs.github.com/enterprise-server@3.15/rest/enterprise-admin/manage-ghes#get-the-enterprise-license-information 355 // 356 //meta:operation GET /manage/v1/config/license 357 func (s *EnterpriseService) License(ctx context.Context) ([]*LicenseStatus, *Response, error) { 358 u := "manage/v1/config/license" 359 req, err := s.client.NewRequest("GET", u, nil) 360 if err != nil { 361 return nil, nil, err 362 } 363 364 var licenseStatus []*LicenseStatus 365 resp, err := s.client.Do(ctx, req, &licenseStatus) 366 if err != nil { 367 return nil, resp, err 368 } 369 370 return licenseStatus, resp, nil 371 } 372 373 // UploadLicense uploads a new license to the GitHub Enterprise instance. 374 // 375 // GitHub API docs: https://docs.github.com/enterprise-server@3.15/rest/enterprise-admin/manage-ghes#upload-an-enterprise-license 376 // 377 //meta:operation PUT /manage/v1/config/license 378 func (s *EnterpriseService) UploadLicense(ctx context.Context, license string) (*Response, error) { 379 u := "manage/v1/config/license" 380 opts := &UploadLicenseOptions{ 381 License: license, 382 } 383 req, err := s.client.NewRequest("PUT", u, opts) 384 if err != nil { 385 return nil, err 386 } 387 388 return s.client.Do(ctx, req, nil) 389 } 390 391 // LicenseStatus gets the current license status for the GitHub Enterprise instance. 392 // 393 // GitHub API docs: https://docs.github.com/enterprise-server@3.15/rest/enterprise-admin/manage-ghes#check-a-license 394 // 395 //meta:operation GET /manage/v1/config/license/check 396 func (s *EnterpriseService) LicenseStatus(ctx context.Context) ([]*LicenseCheck, *Response, error) { 397 u := "manage/v1/config/license/check" 398 req, err := s.client.NewRequest("GET", u, nil) 399 if err != nil { 400 return nil, nil, err 401 } 402 403 var checks []*LicenseCheck 404 resp, err := s.client.Do(ctx, req, &checks) 405 if err != nil { 406 return nil, resp, err 407 } 408 409 return checks, resp, nil 410 } 411 412 // NodeMetadata gets the metadata for all nodes in the GitHub Enterprise instance. 413 // This is required for clustered setups. 414 // 415 // GitHub API docs: https://docs.github.com/enterprise-server@3.15/rest/enterprise-admin/manage-ghes#get-ghes-node-metadata-for-all-nodes 416 // 417 //meta:operation GET /manage/v1/config/nodes 418 func (s *EnterpriseService) NodeMetadata(ctx context.Context, opts *NodeQueryOptions) (*NodeMetadataStatus, *Response, error) { 419 u, err := addOptions("manage/v1/config/nodes", opts) 420 if err != nil { 421 return nil, nil, err 422 } 423 req, err := s.client.NewRequest("GET", u, nil) 424 if err != nil { 425 return nil, nil, err 426 } 427 428 status := new(NodeMetadataStatus) 429 resp, err := s.client.Do(ctx, req, status) 430 if err != nil { 431 return nil, resp, err 432 } 433 434 return status, resp, nil 435 } 436 437 // Settings gets the current configuration settings for the GitHub Enterprise instance. 438 // 439 // GitHub API docs: https://docs.github.com/enterprise-server@3.15/rest/enterprise-admin/manage-ghes#get-the-ghes-settings 440 // 441 //meta:operation GET /manage/v1/config/settings 442 func (s *EnterpriseService) Settings(ctx context.Context) (*ConfigSettings, *Response, error) { 443 u := "manage/v1/config/settings" 444 req, err := s.client.NewRequest("GET", u, nil) 445 if err != nil { 446 return nil, nil, err 447 } 448 449 configSettings := new(ConfigSettings) 450 resp, err := s.client.Do(ctx, req, configSettings) 451 if err != nil { 452 return nil, resp, err 453 } 454 455 return configSettings, resp, nil 456 } 457 458 // UpdateSettings updates the configuration settings for the GitHub Enterprise instance. 459 // 460 // GitHub API docs: https://docs.github.com/enterprise-server@3.15/rest/enterprise-admin/manage-ghes#set-settings 461 // 462 //meta:operation PUT /manage/v1/config/settings 463 func (s *EnterpriseService) UpdateSettings(ctx context.Context, opts *ConfigSettings) (*Response, error) { 464 u := "manage/v1/config/settings" 465 466 if opts == nil { 467 return nil, errors.New("opts should not be nil") 468 } 469 req, err := s.client.NewRequest("PUT", u, opts) 470 if err != nil { 471 return nil, err 472 } 473 474 return s.client.Do(ctx, req, nil) 475 } 476 477 // ConfigApply triggers a configuration apply run on the GitHub Enterprise instance. 478 // 479 // GitHub API docs: https://docs.github.com/enterprise-server@3.15/rest/enterprise-admin/manage-ghes#trigger-a-ghe-config-apply-run 480 // 481 //meta:operation POST /manage/v1/config/apply 482 func (s *EnterpriseService) ConfigApply(ctx context.Context, opts *ConfigApplyOptions) (*ConfigApplyOptions, *Response, error) { 483 u := "manage/v1/config/apply" 484 req, err := s.client.NewRequest("POST", u, opts) 485 if err != nil { 486 return nil, nil, err 487 } 488 489 configApplyOptions := new(ConfigApplyOptions) 490 resp, err := s.client.Do(ctx, req, configApplyOptions) 491 if err != nil { 492 return nil, resp, err 493 } 494 return configApplyOptions, resp, nil 495 } 496 497 // ConfigApplyStatus gets the status of a ghe-config-apply run on the GitHub Enterprise instance. 498 // You can request lat one or specific id one. 499 // 500 // GitHub API docs: https://docs.github.com/enterprise-server@3.15/rest/enterprise-admin/manage-ghes#get-the-status-of-a-ghe-config-apply-run 501 // 502 //meta:operation GET /manage/v1/config/apply 503 func (s *EnterpriseService) ConfigApplyStatus(ctx context.Context, opts *ConfigApplyOptions) (*ConfigApplyStatus, *Response, error) { 504 u := "manage/v1/config/apply" 505 req, err := s.client.NewRequest("GET", u, opts) 506 if err != nil { 507 return nil, nil, err 508 } 509 510 status := new(ConfigApplyStatus) 511 resp, err := s.client.Do(ctx, req, status) 512 if err != nil { 513 return nil, resp, err 514 } 515 return status, resp, nil 516 }