...

Source file src/github.com/google/go-github/v55/github/orgs_audit_log.go

Documentation: github.com/google/go-github/v55/github

     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/en/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  	Fingerprint            *string                 `json:"fingerprint,omitempty"`
    70  	HashedToken            *string                 `json:"hashed_token,omitempty"`
    71  	HeadBranch             *string                 `json:"head_branch,omitempty"`
    72  	HeadSHA                *string                 `json:"head_sha,omitempty"`
    73  	HookID                 *int64                  `json:"hook_id,omitempty"`
    74  	IsHostedRunner         *bool                   `json:"is_hosted_runner,omitempty"`
    75  	JobName                *string                 `json:"job_name,omitempty"`
    76  	JobWorkflowRef         *string                 `json:"job_workflow_ref,omitempty"`
    77  	LimitedAvailability    *bool                   `json:"limited_availability,omitempty"`
    78  	Message                *string                 `json:"message,omitempty"`
    79  	Name                   *string                 `json:"name,omitempty"`
    80  	OAuthApplicationID     *int64                  `json:"oauth_application_id,omitempty"`
    81  	OldUser                *string                 `json:"old_user,omitempty"`
    82  	OldPermission          *string                 `json:"old_permission,omitempty"` // The permission level for membership changes, for example `admin` or `read`.
    83  	OpenSSHPublicKey       *string                 `json:"openssh_public_key,omitempty"`
    84  	OperationType          *string                 `json:"operation_type,omitempty"`
    85  	Org                    *string                 `json:"org,omitempty"`
    86  	OrgID                  *int64                  `json:"org_id,omitempty"`
    87  	OverriddenCodes        []string                `json:"overridden_codes,omitempty"`
    88  	Permission             *string                 `json:"permission,omitempty"` // The permission level for membership changes, for example `admin` or `read`.
    89  	PreviousVisibility     *string                 `json:"previous_visibility,omitempty"`
    90  	ProgrammaticAccessType *string                 `json:"programmatic_access_type,omitempty"`
    91  	PullRequestID          *int64                  `json:"pull_request_id,omitempty"`
    92  	PullRequestTitle       *string                 `json:"pull_request_title,omitempty"`
    93  	PullRequestURL         *string                 `json:"pull_request_url,omitempty"`
    94  	ReadOnly               *string                 `json:"read_only,omitempty"`
    95  	Reasons                []*PolicyOverrideReason `json:"reasons,omitempty"`
    96  	Repo                   *string                 `json:"repo,omitempty"`
    97  	Repository             *string                 `json:"repository,omitempty"`
    98  	RepositoryPublic       *bool                   `json:"repository_public,omitempty"`
    99  	RunAttempt             *int64                  `json:"run_attempt,omitempty"`
   100  	RunnerGroupID          *int64                  `json:"runner_group_id,omitempty"`
   101  	RunnerGroupName        *string                 `json:"runner_group_name,omitempty"`
   102  	RunnerID               *int64                  `json:"runner_id,omitempty"`
   103  	RunnerLabels           []string                `json:"runner_labels,omitempty"`
   104  	RunnerName             *string                 `json:"runner_name,omitempty"`
   105  	RunNumber              *int64                  `json:"run_number,omitempty"`
   106  	SecretsPassed          []string                `json:"secrets_passed,omitempty"`
   107  	SourceVersion          *string                 `json:"source_version,omitempty"`
   108  	StartedAt              *Timestamp              `json:"started_at,omitempty"`
   109  	TargetLogin            *string                 `json:"target_login,omitempty"`
   110  	TargetVersion          *string                 `json:"target_version,omitempty"`
   111  	Team                   *string                 `json:"team,omitempty"`
   112  	Timestamp              *Timestamp              `json:"@timestamp,omitempty"` // The time the audit log event occurred, given as a [Unix timestamp](http://en.wikipedia.org/wiki/Unix_time).
   113  	TokenID                *int64                  `json:"token_id,omitempty"`
   114  	TokenScopes            *string                 `json:"token_scopes,omitempty"`
   115  	Topic                  *string                 `json:"topic,omitempty"`
   116  	TransportProtocolName  *string                 `json:"transport_protocol_name,omitempty"` // A human readable name for the protocol (for example, HTTP or SSH) used to transfer Git data.
   117  	TransportProtocol      *int                    `json:"transport_protocol,omitempty"`      // The type of protocol (for example, HTTP=1 or SSH=2) used to transfer Git data.
   118  	TriggerID              *int64                  `json:"trigger_id,omitempty"`
   119  	User                   *string                 `json:"user,omitempty"` // The user that was affected by the action performed (if available).
   120  	UserAgent              *string                 `json:"user_agent,omitempty"`
   121  	Visibility             *string                 `json:"visibility,omitempty"` // The repository visibility, for example `public` or `private`.
   122  	WorkflowID             *int64                  `json:"workflow_id,omitempty"`
   123  	WorkflowRunID          *int64                  `json:"workflow_run_id,omitempty"`
   124  
   125  	Data *AuditEntryData `json:"data,omitempty"`
   126  }
   127  
   128  // AuditEntryData represents additional information stuffed into a `data` field.
   129  type AuditEntryData struct {
   130  	OldName  *string `json:"old_name,omitempty"`  // The previous name of the repository, for a name change
   131  	OldLogin *string `json:"old_login,omitempty"` // The previous name of the organization, for a name change
   132  }
   133  
   134  // GetAuditLog gets the audit-log entries for an organization.
   135  //
   136  // GitHub API docs: https://docs.github.com/en/rest/orgs/orgs#get-the-audit-log-for-an-organization
   137  func (s *OrganizationsService) GetAuditLog(ctx context.Context, org string, opts *GetAuditLogOptions) ([]*AuditEntry, *Response, error) {
   138  	u := fmt.Sprintf("orgs/%v/audit-log", org)
   139  	u, err := addOptions(u, opts)
   140  	if err != nil {
   141  		return nil, nil, err
   142  	}
   143  
   144  	req, err := s.client.NewRequest("GET", u, nil)
   145  	if err != nil {
   146  		return nil, nil, err
   147  	}
   148  
   149  	var auditEntries []*AuditEntry
   150  	resp, err := s.client.Do(ctx, req, &auditEntries)
   151  	if err != nil {
   152  		return nil, resp, err
   153  	}
   154  
   155  	return auditEntries, resp, nil
   156  }
   157  

View as plain text