github.com/google/go-github/v49@v49.1.0/github/orgs_audit_log.go (about) 1 // Copyright 2021 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 // GetAuditLogOptions sets up optional parameters to query audit-log endpoint. 14 type GetAuditLogOptions struct { 15 Phrase *string `url:"phrase,omitempty"` // A search phrase. (Optional.) 16 Include *string `url:"include,omitempty"` // Event type includes. Can be one of "web", "git", "all". Default: "web". (Optional.) 17 Order *string `url:"order,omitempty"` // The order of audit log events. Can be one of "asc" or "desc". Default: "desc". (Optional.) 18 19 ListCursorOptions 20 } 21 22 // HookConfig describes metadata about a webhook configuration. 23 type HookConfig struct { 24 ContentType *string `json:"content_type,omitempty"` 25 InsecureSSL *string `json:"insecure_ssl,omitempty"` 26 URL *string `json:"url,omitempty"` 27 28 // Secret is returned obfuscated by GitHub, but it can be set for outgoing requests. 29 Secret *string `json:"secret,omitempty"` 30 } 31 32 // AuditEntry describes the fields that may be represented by various audit-log "action" entries. 33 // 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 34 type AuditEntry struct { 35 Action *string `json:"action,omitempty"` // The name of the action that was performed, for example `user.login` or `repo.create`. 36 Active *bool `json:"active,omitempty"` 37 ActiveWas *bool `json:"active_was,omitempty"` 38 Actor *string `json:"actor,omitempty"` // The actor who performed the action. 39 BlockedUser *string `json:"blocked_user,omitempty"` 40 Business *string `json:"business,omitempty"` 41 CancelledAt *Timestamp `json:"cancelled_at,omitempty"` 42 CompletedAt *Timestamp `json:"completed_at,omitempty"` 43 Conclusion *string `json:"conclusion,omitempty"` 44 Config *HookConfig `json:"config,omitempty"` 45 ConfigWas *HookConfig `json:"config_was,omitempty"` 46 ContentType *string `json:"content_type,omitempty"` 47 CreatedAt *Timestamp `json:"created_at,omitempty"` 48 DeployKeyFingerprint *string `json:"deploy_key_fingerprint,omitempty"` 49 DocumentID *string `json:"_document_id,omitempty"` 50 Emoji *string `json:"emoji,omitempty"` 51 EnvironmentName *string `json:"environment_name,omitempty"` 52 Event *string `json:"event,omitempty"` 53 Events []string `json:"events,omitempty"` 54 EventsWere []string `json:"events_were,omitempty"` 55 Explanation *string `json:"explanation,omitempty"` 56 Fingerprint *string `json:"fingerprint,omitempty"` 57 HeadBranch *string `json:"head_branch,omitempty"` 58 HeadSHA *string `json:"head_sha,omitempty"` 59 HookID *int64 `json:"hook_id,omitempty"` 60 IsHostedRunner *bool `json:"is_hosted_runner,omitempty"` 61 JobName *string `json:"job_name,omitempty"` 62 LimitedAvailability *bool `json:"limited_availability,omitempty"` 63 Message *string `json:"message,omitempty"` 64 Name *string `json:"name,omitempty"` 65 OldUser *string `json:"old_user,omitempty"` 66 OpenSSHPublicKey *string `json:"openssh_public_key,omitempty"` 67 Org *string `json:"org,omitempty"` 68 PreviousVisibility *string `json:"previous_visibility,omitempty"` 69 ReadOnly *string `json:"read_only,omitempty"` 70 Repo *string `json:"repo,omitempty"` 71 Repository *string `json:"repository,omitempty"` 72 RepositoryPublic *bool `json:"repository_public,omitempty"` 73 RunAttempt *int64 `json:"run_attempt,omitempty"` 74 RunnerGroupID *int64 `json:"runner_group_id,omitempty"` 75 RunnerGroupName *string `json:"runner_group_name,omitempty"` 76 RunnerID *int64 `json:"runner_id,omitempty"` 77 RunnerLabels []string `json:"runner_labels,omitempty"` 78 RunnerName *string `json:"runner_name,omitempty"` 79 SecretsPassed []string `json:"secrets_passed,omitempty"` 80 SourceVersion *string `json:"source_version,omitempty"` 81 StartedAt *Timestamp `json:"started_at,omitempty"` 82 TargetLogin *string `json:"target_login,omitempty"` 83 TargetVersion *string `json:"target_version,omitempty"` 84 Team *string `json:"team,omitempty"` 85 Timestamp *Timestamp `json:"@timestamp,omitempty"` // The time the audit log event occurred, given as a [Unix timestamp](http://en.wikipedia.org/wiki/Unix_time). 86 TransportProtocolName *string `json:"transport_protocol_name,omitempty"` // A human readable name for the protocol (for example, HTTP or SSH) used to transfer Git data. 87 TransportProtocol *int `json:"transport_protocol,omitempty"` // The type of protocol (for example, HTTP=1 or SSH=2) used to transfer Git data. 88 TriggerID *int64 `json:"trigger_id,omitempty"` 89 User *string `json:"user,omitempty"` // The user that was affected by the action performed (if available). 90 Visibility *string `json:"visibility,omitempty"` // The repository visibility, for example `public` or `private`. 91 WorkflowID *int64 `json:"workflow_id,omitempty"` 92 WorkflowRunID *int64 `json:"workflow_run_id,omitempty"` 93 } 94 95 // GetAuditLog gets the audit-log entries for an organization. 96 // 97 // GitHub API docs: https://docs.github.com/en/rest/orgs/orgs#get-the-audit-log-for-an-organization 98 func (s *OrganizationsService) GetAuditLog(ctx context.Context, org string, opts *GetAuditLogOptions) ([]*AuditEntry, *Response, error) { 99 u := fmt.Sprintf("orgs/%v/audit-log", org) 100 u, err := addOptions(u, opts) 101 if err != nil { 102 return nil, nil, err 103 } 104 105 req, err := s.client.NewRequest("GET", u, nil) 106 if err != nil { 107 return nil, nil, err 108 } 109 110 var auditEntries []*AuditEntry 111 resp, err := s.client.Do(ctx, req, &auditEntries) 112 if err != nil { 113 return nil, resp, err 114 } 115 116 return auditEntries, resp, nil 117 }