簡體   English   中英

Github V4 GraphQL API - 審計日志查詢

[英]Github V4 GraphQL API - audit log query

我正在嘗試與 github api v4 交互,我想根據 api 中可用的模式查詢審計日志事件。 我可以在這里找到關於 github api 的紀錄片,我可以在這里看到可用的模式但沒有關於如何查詢不同模式的工作示例。

如果這里有人使用過這個 API,特別是審計日志模式,我需要一個工作示例來開始與審計日志模式交互......

例如,我想查詢所有組織向團隊事件添加成員,假設在模式 TeamAddMemberAuditEntry 中,或從組織 OrgRemoveMemberAuditEntry 中刪除成員

到目前為止,我已經嘗試使用 node.js 查詢它:

require('isomorphic-fetch');

fetch('https://api.github.com/graphql', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json',
             'Authorization': 'bearer <token>',
             'Accept': 'application/vnd.github.audit-log- preview+json'},
  body: JSON.stringify({ query: '{ TeamAddMemberAuditEntry }' }),
})
  .then(res => res.json())
  .then(res => console.log(res.data));

如果有人在這里尋找解決方案,在查看公共模式之后,這就是查詢查找獲取審計日志對象的方式,當然這沒有標題和查詢前綴。

auditLog是一種聯合類型,您可以通過添加另一個“... on”塊來獲取多個審核事件。 例如,我在這里得到所有orginvitemembers事件

{
  organization(login:"<your-org>") {
    auditLog(first:2) {
      edges {
        node {
          __typename
          ... on OrgInviteMemberAuditEntry {
            action
            actorIp
            actorLogin
            createdAt
            userLogin
            actorLocation{
              country
              city
            }
          }
        }       
      }
    }
  }
}

我也在追求同樣的事情。 我認為你的query語句就像這個問題。

我在 GitHub 博客中看到了這個文檔。

https://github.blog/2019-06-21-the-github-enterprise-audit-log-api-for-graphql-beginners/

我能夠調整示例查詢並提出以下...

{
  organization(login: "xyz-corp") {
    auditLog(last: 10
    , query: "action:org.remove_member") {
      edges {
        node {
          ... on AuditEntry {
            action
            actorLogin
            userLogin
            createdAt
            user{
              name
              email
            }                
          }
        }
      }
    }
  }
}

我能夠用以下內容替換查​​詢,就像我通過 UI 獲取添加和更新一樣。

  • 行動:org.add_member
  • 行動:org.update_member

其他審計日志查詢項在此處描述

https://docs.github.com/en/organizations/keeping-your-organization-secure/reviewing-the-audit-log-for-your-organization

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM