首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何利用生态系统过滤GitHub GraphQL中的信息

如何利用生态系统过滤GitHub GraphQL中的信息
EN

Stack Overflow用户
提问于 2021-06-13 09:35:22
回答 1查看 532关注 0票数 1

链接第一

我在努力

代码语言:javascript
复制
{
    securityAdvisories(first: 100, ecosystem: nuget) {
    totalCount
    pageInfo {
        endCursor
        startCursor
    }
    nodes {
        description
        summary
        cvss {
        vectorString
        }
        databaseId
        identifiers {
        type
        value
        }
        ghsaId
    }
    }
}

我得到了字段'securityAdvisories‘不接受争论’生态系统‘“我在https://docs.github.com/en/graphql/reference/objects#securityadvisorypackage中看到了字段生态系统

如何通过“生态系统”进行过滤?

这是可能的,因为我可以做https://github.com/advisories?query=ecosystem%3Anuget,如何获得所有113个建议?

更新

我可以过滤属于生态系统咨询的漏洞。

代码语言:javascript
复制
  vulnerabilities(first: 10, ecosystem: NUGET) {
    edges {
      node {
        advisory {
          id
        }
      }
    }

更新2我首先爬行UI

代码语言:javascript
复制
page=1;while [ 1 ];do  curl "https://github.com/advisories?page=$count&query=ecosystem%3Anuget" -o $count.txt;count=$((count+1));done
find -maxdepth 1 -name "*.txt" | xargs grep -oE "GHSA-\w{4}-\w{4}-\w{4}" 

在我有了GHSA列表之后,我运行了一个有点神秘的Python

代码语言:javascript
复制
import requests
import easyargs

template="""
{"query": "query securityAdvisory(ghsaId: \\"GHSA_VALUE\\") {     id     description     ghsaId     permalink     summary     identifiers {       type       value     }     references {       url     }     origin     cwes(first: 10) {       nodes {         name         id         description         cweId       }     }     cvss {       score       vectorString     }     databaseId     publishedAt     notificationsPermalink     updatedAt     severity     withdrawnAt     vulnerabilities(first: 50) {       edges {         node {           severity           updatedAt           vulnerableVersionRange         }       }     }   } } "}
"""

# get token from https://github.com/settings/tokens
# ghsas is a list of GHSAs
@easyargs
def main(token=str, ghsas=str):
    with open(ghsas) as f:
        lines = f.readlines()

    for s in lines:
        s = s.strip()
        data=template.replace("GHSA_VALUE", s, 1)
        r = requests.post(url="https://api.github.com/graphql", data=data, headers={"Authorization":f"bearer {token}"})
        print(r.text)

if __name__ == '__main__':
    main()

我相信有更好的解决办法。在完美的世界中,我将有一个单行卷曲返回一个包含113个Nuget相关的安全支持的JSON。我不知道如何查询GraphQL。

EN

回答 1

Stack Overflow用户

发布于 2021-06-16 16:43:41

对于可以筛选的参数,需要查看查询类型的文档,而不是对象类型,即https://docs.github.com/en/graphql/reference/queries#securityadvisoryconnection

因为它没有针对ecosystem的条目,所以不能按生态系统过滤查询结果。不过,您可以返回生态系统(将其添加到node块中),然后在结果返回给您之后,按生态系统进行筛选。

您可以过滤的内容在图中作为冗余数据存储,这意味着后端可以完全避免访问节点。很明显,这是有代价的,所以它只适用于人们通常想要过滤的东西。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67956806

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档