简体   繁体   English

Github V4 GraphQL API - 审计日志查询

[英]Github V4 GraphQL API - audit log query

i'm trying to interact with github api v4, i want to query audit log events based on schemas available in the api.我正在尝试与 github api v4 交互,我想根据 api 中可用的模式查询审计日志事件。 I can found a documentary about the github api here and I can see the schemas available here but there are no working examples of how to query the different schemas.我可以在这里找到关于 github api 的纪录片,我可以在这里看到可用的模式但没有关于如何查询不同模式的工作示例。

If there is someone here experience with this API, specially with the audit log schemas, I need a working example to start interacting with the audit log schemas...如果这里有人使用过这个 API,特别是审计日志模式,我需要一个工作示例来开始与审计日志模式交互......

for example i want to query all organization add member to team events, suppose to be in the schema TeamAddMemberAuditEntry, or remove member from org OrgRemoveMemberAuditEntry例如,我想查询所有组织向团队事件添加成员,假设在模式 TeamAddMemberAuditEntry 中,或从组织 OrgRemoveMemberAuditEntry 中删除成员

So far I've tried to query it with node.js:到目前为止,我已经尝试使用 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));

If someone here will look for solution, after viewing the public schema this is how the query looks for getting audit-log objects, this is without the headers and the query prefix of course. 如果有人在这里寻找解决方案,在查看公共模式之后,这就是查询查找获取审计日志对象的方式,当然这没有标题和查询前缀。

The auditLog is a union type, you can get multiple audit events by adding another "...on" block. auditLog是一种联合类型,您可以通过添加另一个“... on”块来获取多个审核事件。 for example here i'm getting all the orginvitemembers events 例如,我在这里得到所有orginvitemembers事件

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

I was after the same thing.我也在追求同样的事情。 I think your query statement is like the issue.我认为你的query语句就像这个问题。

I came across this documentation in the GitHub blog.我在 GitHub 博客中看到了这个文档。

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

I was able to adapt the example query and come up with the following...我能够调整示例查询并提出以下...

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

I was able to substitute the query with the following just as I would via the UI to get adds and updates.我能够用以下内容替换查​​询,就像我通过 UI 获取添加和更新一样。

  • action:org.add_member行动:org.add_member
  • action:org.update_member行动:org.update_member

Other audit log query items are described here其他审计日志查询项在此处描述

https://docs.github.com/en/organizations/keeping-your-organization-secure/reviewing-the-audit-log-for-your-organization 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