繁体   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