github.com/google/go-github/v57@v57.0.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  // ActorLocation contains information about reported location for an actor.
    33  type ActorLocation struct {
    34  	CountryCode *string `json:"country_code,omitempty"`
    35  }
    36  
    37  // PolicyOverrideReason contains user-supplied information about why a policy was overridden.
    38  type PolicyOverrideReason struct {
    39  	Code    *string `json:"code,omitempty"`
    40  	Message *string `json:"message,omitempty"`
    41  }
    42  
    43  // AuditEntry describes the fields that may be represented by various audit-log "action" entries.
    44  // For a list of actions see - https://docs.github.com/github/setting-up-and-managing-organizations-and-teams/reviewing-the-audit-log-for-your-organization#audit-log-actions
    45  type AuditEntry struct {
    46  	ActorIP                  *string                 `json:"actor_ip,omitempty"`
    47  	Action                   *string                 `json:"action,omitempty"` // The name of the action that was performed, for example `user.login` or `repo.create`.
    48  	Active                   *bool                   `json:"active,omitempty"`
    49  	ActiveWas                *bool                   `json:"active_was,omitempty"`
    50  	Actor                    *string                 `json:"actor,omitempty"` // The actor who performed the action.
    51  	ActorLocation            *ActorLocation          `json:"actor_location,omitempty"`
    52  	BlockedUser              *string                 `json:"blocked_user,omitempty"`
    53  	Business                 *string                 `json:"business,omitempty"`
    54  	CancelledAt              *Timestamp              `json:"cancelled_at,omitempty"`
    55  	CompletedAt              *Timestamp              `json:"completed_at,omitempty"`
    56  	Conclusion               *string                 `json:"conclusion,omitempty"`
    57  	Config                   *HookConfig             `json:"config,omitempty"`
    58  	ConfigWas                *HookConfig             `json:"config_was,omitempty"`
    59  	ContentType              *string                 `json:"content_type,omitempty"`
    60  	CreatedAt                *Timestamp              `json:"created_at,omitempty"`
    61  	DeployKeyFingerprint     *string                 `json:"deploy_key_fingerprint,omitempty"`
    62  	DocumentID               *string                 `json:"_document_id,omitempty"`
    63  	Emoji                    *string                 `json:"emoji,omitempty"`
    64  	EnvironmentName          *string                 `json:"environment_name,omitempty"`
    65  	Event                    *string                 `json:"event,omitempty"`
    66  	Events                   []string                `json:"events,omitempty"`
    67  	EventsWere               []string                `json:"events_were,omitempty"`
    68  	Explanation              *string                 `json:"explanation,omitempty"`
    69  	ExternalIdentityNameID   *string                 `json:"external_identity_nameid,omitempty"`
    70  	ExternalIdentityUsername *string                 `json:"external_identity_username,omitempty"`
    71  	Fingerprint              *string                 `json:"fingerprint,omitempty"`
    72  	HashedToken              *string                 `json:"hashed_token,omitempty"`
    73  	HeadBranch               *string                 `json:"head_branch,omitempty"`
    74  	HeadSHA                  *string                 `json:"head_sha,omitempty"`
    75  	HookID                   *int64                  `json:"hook_id,omitempty"`
    76  	IsHostedRunner           *bool                   `json:"is_hosted_runner,omitempty"`
    77  	JobName                  *string                 `json:"job_name,omitempty"`
    78  	JobWorkflowRef           *string                 `json:"job_workflow_ref,omitempty"`
    79  	LimitedAvailability      *bool                   `json:"limited_availability,omitempty"`
    80  	Message                  *string                 `json:"message,omitempty"`
    81  	Name                     *string                 `json:"name,omitempty"`
    82  	OAuthApplicationID       *int64                  `json:"oauth_application_id,omitempty"`
    83  	OldUser                  *string                 `json:"old_user,omitempty"`
    84  	OldPermission            *string                 `json:"old_permission,omitempty"` // The permission level for membership changes, for example `admin` or `read`.
    85  	OpenSSHPublicKey         *string                 `json:"openssh_public_key,omitempty"`
    86  	OperationType            *string                 `json:"operation_type,omitempty"`
    87  	Org                      *string                 `json:"org,omitempty"`
    88  	OrgID                    *int64                  `json:"org_id,omitempty"`
    89  	OverriddenCodes          []string                `json:"overridden_codes,omitempty"`
    90  	Permission               *string                 `json:"permission,omitempty"` // The permission level for membership changes, for example `admin` or `read`.
    91  	PreviousVisibility       *string                 `json:"previous_visibility,omitempty"`
    92  	ProgrammaticAccessType   *string                 `json:"programmatic_access_type,omitempty"`
    93  	PullRequestID            *int64                  `json:"pull_request_id,omitempty"`
    94  	PullRequestTitle         *string                 `json:"pull_request_title,omitempty"`
    95  	PullRequestURL           *string                 `json:"pull_request_url,omitempty"`
    96  	ReadOnly                 *string                 `json:"read_only,omitempty"`
    97  	Reasons                  []*PolicyOverrideReason `json:"reasons,omitempty"`
    98  	Repo                     *string                 `json:"repo,omitempty"`
    99  	Repository               *string                 `json:"repository,omitempty"`
   100  	RepositoryPublic         *bool                   `json:"repository_public,omitempty"`
   101  	RunAttempt               *int64                  `json:"run_attempt,omitempty"`
   102  	RunnerGroupID            *int64                  `json:"runner_group_id,omitempty"`
   103  	RunnerGroupName          *string                 `json:"runner_group_name,omitempty"`
   104  	RunnerID                 *int64                  `json:"runner_id,omitempty"`
   105  	RunnerLabels             []string                `json:"runner_labels,omitempty"`
   106  	RunnerName               *string                 `json:"runner_name,omitempty"`
   107  	RunNumber                *int64                  `json:"run_number,omitempty"`
   108  	SecretsPassed            []string                `json:"secrets_passed,omitempty"`
   109  	SourceVersion            *string                 `json:"source_version,omitempty"`
   110  	StartedAt                *Timestamp              `json:"started_at,omitempty"`
   111  	TargetLogin              *string                 `json:"target_login,omitempty"`
   112  	TargetVersion            *string                 `json:"target_version,omitempty"`
   113  	Team                     *string                 `json:"team,omitempty"`
   114  	Timestamp                *Timestamp              `json:"@timestamp,omitempty"` // The time the audit log event occurred, given as a [Unix timestamp](http://en.wikipedia.org/wiki/Unix_time).
   115  	TokenID                  *int64                  `json:"token_id,omitempty"`
   116  	TokenScopes              *string                 `json:"token_scopes,omitempty"`
   117  	Topic                    *string                 `json:"topic,omitempty"`
   118  	TransportProtocolName    *string                 `json:"transport_protocol_name,omitempty"` // A human readable name for the protocol (for example, HTTP or SSH) used to transfer Git data.
   119  	TransportProtocol        *int                    `json:"transport_protocol,omitempty"`      // The type of protocol (for example, HTTP=1 or SSH=2) used to transfer Git data.
   120  	TriggerID                *int64                  `json:"trigger_id,omitempty"`
   121  	User                     *string                 `json:"user,omitempty"` // The user that was affected by the action performed (if available).
   122  	UserAgent                *string                 `json:"user_agent,omitempty"`
   123  	Visibility               *string                 `json:"visibility,omitempty"` // The repository visibility, for example `public` or `private`.
   124  	WorkflowID               *int64                  `json:"workflow_id,omitempty"`
   125  	WorkflowRunID            *int64                  `json:"workflow_run_id,omitempty"`
   126  
   127  	Data *AuditEntryData `json:"data,omitempty"`
   128  }
   129  
   130  // AuditEntryData represents additional information stuffed into a `data` field.
   131  type AuditEntryData struct {
   132  	OldName  *string `json:"old_name,omitempty"`  // The previous name of the repository, for a name change
   133  	OldLogin *string `json:"old_login,omitempty"` // The previous name of the organization, for a name change
   134  }
   135  
   136  // GetAuditLog gets the audit-log entries for an organization.
   137  //
   138  // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/orgs/orgs#get-the-audit-log-for-an-organization
   139  //
   140  //meta:operation GET /orgs/{org}/audit-log
   141  func (s *OrganizationsService) GetAuditLog(ctx context.Context, org string, opts *GetAuditLogOptions) ([]*AuditEntry, *Response, error) {
   142  	u := fmt.Sprintf("orgs/%v/audit-log", org)
   143  	u, err := addOptions(u, opts)
   144  	if err != nil {
   145  		return nil, nil, err
   146  	}
   147  
   148  	req, err := s.client.NewRequest("GET", u, nil)
   149  	if err != nil {
   150  		return nil, nil, err
   151  	}
   152  
   153  	var auditEntries []*AuditEntry
   154  	resp, err := s.client.Do(ctx, req, &auditEntries)
   155  	if err != nil {
   156  		return nil, resp, err
   157  	}
   158  
   159  	return auditEntries, resp, nil
   160  }