0

我正在尝试运行这个由 trufflehog 制作的 python 脚本,以使用他们的开源扫描程序一次扫描一个帐户或组织的所有 repo。

有谁知道我如何将我的组织名称和访问令牌放入 url 而不会弄乱其余部分?

 def get_org_repos(orgname, page):
    response = requests.get(url='https://api.github.com/users/' + orgname + '/repos?page={}'.format(page))
    json = response.json()
    if not json:
        return None
    for item in json:

        if item['fork'] == False:
            print('searching ' + item["html_url"])
            results = truffleHog.find_strings(item["html_url"], do_regex=True, custom_regexes=rules, do_entropy=False, max_depth=100000)
            for issue in results["foundIssues"]:
                d = loads(open(issue).read())
                d['github_url'] = "{}/blob/{}/{}".format(item["html_url"], d['commitHash'], d['path'])
                d['github_commit_url'] = "{}/commit/{}".format(item["html_url"], d['commitHash'])
                d['diff'] = d['diff'][0:200]
                d['printDiff'] = d['printDiff'][0:200]
                print(dumps(d, indent=4))
    get_org_repos(orgname, page + 1)
get_org_repos("insertOrgName", 1)

到目前为止,我已经尝试了一些变化,比如

requests.get(url='https://api.github.com/users/myOrg/repos?access_token=xyz?page={}'.format(page))

4

1 回答 1

0

首先我会使用 f-strings 使其更具可读性,其次我会使用内置的请求功能传入 GET 参数。

params = {'page':page, 'access_token'=access_token}
def get_org_repos(orgname, page):
    response = requests.get(f'https://api.github.com/users/{orgname}/repos', params=params)
    json = response.json()
    if not json:
        return None
    for item in json:

        if item['fork'] == False:
            print('searching ' + item["html_url"])
            results = truffleHog.find_strings(item["html_url"], do_regex=True, custom_regexes=rules, do_entropy=False, max_depth=100000)
            for issue in results["foundIssues"]:
                d = loads(open(issue).read())
                d['github_url'] = f'{html_url}/blob/{commitHash}/{path}'
                d['github_commit_url'] = f'{html_url}/commit/{commitHash}'
                d['diff'] = d['diff'][0:200]
                d['printDiff'] = d['printDiff'][0:200]
                print(dumps(d, indent=4))
    get_org_repos(orgname, page + 1)
get_org_repos("insertOrgName", 1)
于 2021-11-17T21:01:45.670 回答