gitea

Development moved to Codeberg

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
  101. 101
  102. 102
  103. 103
  104. 104
  105. 105
  106. 106
  107. 107
  108. 108
  109. 109
  110. 110
  111. 111
  112. 112
  113. 113
  114. 114
  115. 115
  116. 116
// Copyright 2021 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"
)

// GetAuditLogOptions sets up optional parameters to query audit-log endpoint.
type GetAuditLogOptions struct {
	Phrase  *string `json:"phrase,omitempty"`  // A search phrase. (Optional.)
	Include *string `json:"include,omitempty"` // Event type includes. Can be one of "web", "git", "all". Default: "web". (Optional.)
	Order   *string `json:"order,omitempty"`   // The order of audit log events. Can be one of "asc" or "desc". Default: "desc". (Optional.)

	ListCursorOptions
}

// HookConfig describes metadata about a webhook configuration.
type HookConfig struct {
	ContentType *string `json:"content_type,omitempty"`
	InsecureSSL *string `json:"insecure_ssl,omitempty"`
	URL         *string `json:"url,omitempty"`

	// Secret is returned obfuscated by GitHub, but it can be set for outgoing requests.
	Secret *string `json:"secret,omitempty"`
}

// AuditEntry describes the fields that may be represented by various audit-log "action" entries.
// For a list of actions see - https://docs.github.com/en/github/setting-up-and-managing-organizations-and-teams/reviewing-the-audit-log-for-your-organization#audit-log-actions
type AuditEntry struct {
	Action                *string     `json:"action,omitempty"` // The name of the action that was performed, for example `user.login` or `repo.create`.
	Active                *bool       `json:"active,omitempty"`
	ActiveWas             *bool       `json:"active_was,omitempty"`
	Actor                 *string     `json:"actor,omitempty"` // The actor who performed the action.
	BlockedUser           *string     `json:"blocked_user,omitempty"`
	Business              *string     `json:"business,omitempty"`
	CancelledAt           *Timestamp  `json:"cancelled_at,omitempty"`
	CompletedAt           *Timestamp  `json:"completed_at,omitempty"`
	Conclusion            *string     `json:"conclusion,omitempty"`
	Config                *HookConfig `json:"config,omitempty"`
	ConfigWas             *HookConfig `json:"config_was,omitempty"`
	ContentType           *string     `json:"content_type,omitempty"`
	CreatedAt             *Timestamp  `json:"created_at,omitempty"`
	DeployKeyFingerprint  *string     `json:"deploy_key_fingerprint,omitempty"`
	DocumentID            *string     `json:"_document_id,omitempty"`
	Emoji                 *string     `json:"emoji,omitempty"`
	EnvironmentName       *string     `json:"environment_name,omitempty"`
	Event                 *string     `json:"event,omitempty"`
	Events                []string    `json:"events,omitempty"`
	EventsWere            []string    `json:"events_were,omitempty"`
	Explanation           *string     `json:"explanation,omitempty"`
	Fingerprint           *string     `json:"fingerprint,omitempty"`
	HeadBranch            *string     `json:"head_branch,omitempty"`
	HeadSHA               *string     `json:"head_sha,omitempty"`
	HookID                *int64      `json:"hook_id,omitempty"`
	IsHostedRunner        *bool       `json:"is_hosted_runner,omitempty"`
	JobName               *string     `json:"job_name,omitempty"`
	LimitedAvailability   *bool       `json:"limited_availability,omitempty"`
	Message               *string     `json:"message,omitempty"`
	Name                  *string     `json:"name,omitempty"`
	OldUser               *string     `json:"old_user,omitempty"`
	OpenSSHPublicKey      *string     `json:"openssh_public_key,omitempty"`
	Org                   *string     `json:"org,omitempty"`
	PreviousVisibility    *string     `json:"previous_visibility,omitempty"`
	ReadOnly              *string     `json:"read_only,omitempty"`
	Repo                  *string     `json:"repo,omitempty"`
	Repository            *string     `json:"repository,omitempty"`
	RepositoryPublic      *bool       `json:"repository_public,omitempty"`
	RunnerGroupID         *string     `json:"runner_group_id,omitempty"`
	RunnerGroupName       *string     `json:"runner_group_name,omitempty"`
	RunnerID              *string     `json:"runner_id,omitempty"`
	RunnerLabels          []string    `json:"runner_labels,omitempty"`
	RunnerName            *string     `json:"runner_name,omitempty"`
	SecretsPassed         []string    `json:"secrets_passed,omitempty"`
	SourceVersion         *string     `json:"source_version,omitempty"`
	StartedAt             *Timestamp  `json:"started_at,omitempty"`
	TargetLogin           *string     `json:"target_login,omitempty"`
	TargetVersion         *string     `json:"target_version,omitempty"`
	Team                  *string     `json:"team,omitempty"`
	Timestamp             *Timestamp  `json:"@timestamp,omitempty"`              // The time the audit log event occurred, given as a [Unix timestamp](http://en.wikipedia.org/wiki/Unix_time).
	TransportProtocolName *string     `json:"transport_protocol_name,omitempty"` // A human readable name for the protocol (for example, HTTP or SSH) used to transfer Git data.
	TransportProtocol     *int        `json:"transport_protocol,omitempty"`      // The type of protocol (for example, HTTP=1 or SSH=2) used to transfer Git data.
	TriggerID             *int64      `json:"trigger_id,omitempty"`
	User                  *string     `json:"user,omitempty"`       // The user that was affected by the action performed (if available).
	Visibility            *string     `json:"visibility,omitempty"` // The repository visibility, for example `public` or `private`.
	WorkflowID            *int64      `json:"workflow_id,omitempty"`
	WorkflowRunID         *int64      `json:"workflow_run_id,omitempty"`
}

// GetAuditLog gets the audit-log entries for an organization.
//
// GitHub API docs: https://docs.github.com/en/rest/reference/orgs#get-the-audit-log-for-an-organization
func (s *OrganizationsService) GetAuditLog(ctx context.Context, org string, opts *GetAuditLogOptions) ([]*AuditEntry, *Response, error) {
	u := fmt.Sprintf("orgs/%v/audit-log", org)
	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
	}

	var auditEntries []*AuditEntry
	resp, err := s.client.Do(ctx, req, &auditEntries)
	if err != nil {
		return nil, resp, err
	}

	return auditEntries, resp, nil
}