【问题标题】:Github V4 GraphQL API - audit log queryGithub V4 GraphQL API - 审计日志查询
【发布时间】:2019-10-12 18:36:14
【问题描述】:

我正在尝试与 github api v4 交互,我想根据 api 中可用的模式查询审计日志事件。我可以找到关于 github api here 的纪录片,并且可以看到可用的架构 here,但没有关于如何查询不同架构的工作示例。

如果这里有人使用过这个 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));

【问题讨论】:

    标签: github graphql audit-logging


    【解决方案1】:

    如果有人在这里寻找解决方案,在查看公共架构后,这是查询查找获取审计日志对象的方式,当然这是没有标题和查询前缀的。

    auditLog 是一个联合类型,你可以通过添加另一个 "...on" 块来获取多个审计事件。例如在这里我得到了所有的 orginvitemembers 事件

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

    【讨论】:

      【解决方案2】:

      我也在追求同样的事情。我认为您的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 获取添加和更新一样。

      • action:org.add_member
      • action:org.update_member

      此处介绍其他审计日志查询项

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

      【讨论】:

        猜你喜欢
        • 2018-08-21
        • 2023-03-08
        • 2012-08-31
        • 1970-01-01
        • 2018-03-10
        • 2021-12-23
        • 2020-01-12
        • 2018-06-23
        • 2018-06-17
        相关资源
        最近更新 更多