Esempio n. 1
0
def get_repos_and_forks(public):
    if public:
        params = { "type": "public" }
    else:
        params = { "type": "private" }

    # first get all the repositories for your organization
    repos = functions.do_github_api_request('https://api.github.com/orgs/' + config.Organisation + '/repos', params)

    message = ""
    for repo in repos:
        name = repo['name']
        repo_priv = repo['private']
        repo_url = repo['html_url']
        # public repository detected
        if repo_priv == False:
            message = message + "The repository " + name + " (" + repo_url + ") is defined as a public repository.\n"
        else:
            message = message + "The repository " + name + " (" + repo_url + ") is defined as a private repository.\n"
            forks = functions.do_github_api_request('https://api.github.com/repos/' + config.Organisation + '/' + name + '/forks')
            for fork in forks:
                owner_url = fork['html_url']
                message = message + "\t\tFork: " + owner_url + "\n"

    return message
if os.path.isfile(cur_path + path_seperator + 'local_config.py'):
    import local_config as config
else:
    import config

if config.GitHubAuthKey == "":
    print "Please add your Github api key (Settings -> Applications -> Personal Access Tokens) to config.py\n"
    exit()
if config.Organisation == "":
    print "Please add your Github organisation (https://github.com/settings/organizations) to config.py\n"
    exit()

parser = argparse.ArgumentParser(description='Delete github user from an organisation.')
parser.add_argument('username', metavar='<user name>', nargs=1,
                    help='Github user name that should be removed from the organization ' + config.Organisation)

args = parser.parse_args()

user = args.username[0]

response = functions.do_github_api_request('https://api.github.com/orgs/' + config.Organisation + '/members/' + user,
                                           method='delete')

try:
    message = response.get('message', None)
    print(message)
except:
    response_code, result = response
    if (response_code == 204):
        print("User: "******" has been removed from the organization: " + config.Organisation)
import os
import functions
cur_path = os.path.dirname(os.path.realpath(__file__))
if (os.name == 'nt'):
    path_seperator = "\\"
else:
    path_seperator = "/"

if os.path.isfile(cur_path + path_seperator + 'local_config.py'):
    import local_config as config
else:
    import config


if config.GitHubAuthKey == "":
    print "Please add your Github api key (Settings -> Applications -> Personal Access Tokens) to config.py\n"
    exit()
if config.Organisation == "":
    print "Please add your Github organisation (https://github.com/settings/organizations) to config.py\n"
    exit()

teams = functions.do_github_api_request('https://api.github.com/orgs/' + config.Organisation + '/teams')
for team in teams:
    print("id: "+ str(team['id']) + " - " + team['name'] + " - " + team['url'])
Esempio n. 4
0
parser.add_argument('--skip-sending-email', nargs='?', default=False, help='Don\'t send an email, show it instead', const=True)
parser.add_argument('--dont-update-counter', nargs='?', default=False, help='Don\'t update the amount of alerts', const=True)

args = parser.parse_args()

dont_update_counter = args.dont_update_counter
skip_sending_email = args.skip_sending_email

if not os.path.isfile(config.SQLFile):
    conn, curs = functions.connect_db()
    functions.create_db_structure(conn, curs)
else:
    conn, curs = functions.connect_db()

# get all the users that don't have 2 factor authentication enabled
json_list = functions.do_github_api_request('https://api.github.com/orgs/' + config.Organisation + '/members',
                                            params={"filter": "2fa_disabled"})
users = []

for user in json_list:
    user_dict = functions.do_github_api_request(user['url'])
    user_dict['first_alert'], user_dict['alert_count'] = functions.insert_user_row_in_db(conn, curs, user_dict,
                                                                                         dont_update_counter)
    users.append(user_dict)

conn.close()
email = functions.construct_email(users)
if skip_sending_email:
    print email
else:
    # lets send an overview email
    functions.send_mail(config.FromAddress, config.Receivers, "Github Two Factor authentication audit", email,
    print "Please add your Github organisation (https://github.com/settings/organizations) to config.py\n"
    exit()

parser = argparse.ArgumentParser(description='Add github user to a team within an organisation.')
parser.add_argument('usernames', metavar='<user name>', nargs='*',
                    help='1 or more Github user names that should be added')

args = parser.parse_args()

users = args.usernames
count = len(users)
if (count == 0):
    parser.print_help()
else:
    if not config.DefaultTeamId:
        print "Please setup a default team in config.py!"
        exit()
    for user in users:
        response = functions.do_github_api_request('https://api.github.com/teams/' + str(config.DefaultTeamId)
                                        + '/memberships/' + user, method='put')
        message = response.get('message', None)
        if message:
            print(message)
            print("Do you have the admin:org scope enabled?")
            exit()
        else:
            state = response.get('state', None)
            if state == "pending":
                print(user + " added, awaiting confirmation from the user!")
            elif state == "active":
                print(user + " is already a member!")
Esempio n. 6
0
search_terms = args.terms
extension = args.extension
excel_file_name = args.excel[0]

if extension != "all":
    search_filter = search_filter + " extension:" + extension

for term in search_terms[0]:
    search_filter = search_filter + " " + term

# first get all the repositories for your organization
params = {'q': search_filter}
print("Going to search for: " + search_filter)
results = functions.do_github_api_request(
    'https://api.github.com/search/code', params, 'get',
    [{
        'Accept': 'application/vnd.github.v3.text-match+json'
    }])
items = results['items']

workbook = xlsxwriter.Workbook(excel_file_name)
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})

worksheet.write('A1', 'Fragment', bold)
worksheet.write('B1', 'Description', bold)
worksheet.write('C1', 'Link', bold)

row = 1
col = 0
import os
import functions
cur_path = os.path.dirname(os.path.realpath(__file__))
if (os.name == 'nt'):
    path_seperator = "\\"
else:
    path_seperator = "/"

if os.path.isfile(cur_path + path_seperator + 'local_config.py'):
    import local_config as config
else:
    import config

if config.GitHubAuthKey == "":
    print "Please add your Github api key (Settings -> Applications -> Personal Access Tokens) to config.py\n"
    exit()
if config.Organisation == "":
    print "Please add your Github organisation (https://github.com/settings/organizations) to config.py\n"
    exit()

teams = functions.do_github_api_request('https://api.github.com/orgs/' +
                                        config.Organisation + '/teams')
for team in teams:
    print("id: " + str(team['id']) + " - " + team['name'] + " - " +
          team['url'])
args = parser.parse_args()
search_terms = args.terms
extension = args.extension
excel_file_name = args.excel[0]

if extension != "all":
    search_filter = search_filter + " extension:" + extension

for term in search_terms[0]:
    search_filter = search_filter + " " + term

# first get all the repositories for your organization
params = { 'q': search_filter }
print ("Going to search for: " + search_filter)
results = functions.do_github_api_request('https://api.github.com/search/code', params, 'get',
                                          [{'Accept': 'application/vnd.github.v3.text-match+json'}])
items = results['items']

workbook = xlsxwriter.Workbook(excel_file_name)
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': True})



worksheet.write('A1', 'Fragment', bold)
worksheet.write('B1', 'Description', bold)
worksheet.write('C1', 'Link', bold)

row = 1
col = 0
Esempio n. 9
0
parser.add_argument('usernames',
                    metavar='<user name>',
                    nargs='*',
                    help='1 or more Github user names that should be added')

args = parser.parse_args()

users = args.usernames
count = len(users)
if (count == 0):
    parser.print_help()
else:
    if not config.DefaultTeamId:
        print "Please setup a default team in config.py!"
        exit()
    for user in users:
        response = functions.do_github_api_request(
            'https://api.github.com/teams/' + str(config.DefaultTeamId) +
            '/memberships/' + user,
            method='put')
        message = response.get('message', None)
        if message:
            print(message)
            print("Do you have the admin:org scope enabled?")
            exit()
        else:
            state = response.get('state', None)
            if state == "pending":
                print(user + " added, awaiting confirmation from the user!")
            elif state == "active":
                print(user + " is already a member!")
    import local_config as config
else:
    import config

if config.GitHubAuthKey == "":
    print "Please add your Github api key (Settings -> Applications -> Personal Access Tokens) to config.py\n"
    exit()
if config.Organisation == "":
    print "Please add your Github organisation (https://github.com/settings/organizations) to config.py\n"
    exit()

parser = argparse.ArgumentParser(description='Show details Github user.')
parser.add_argument('username',
                    metavar='<user name>',
                    nargs=1,
                    help='Github user names that should queried')

args = parser.parse_args()

user = args.username[0]

response = functions.do_github_api_request('https://api.github.com/users/' +
                                           user)

message = response.get('message', None)
if message:
    print(message)
else:
    for key in response.keys():
        print str(key) + ": " + str(response[key])
    print "Please add your Github api key (Settings -> Applications -> Personal Access Tokens) to config.py\n"
    exit()
if config.Organisation == "":
    print "Please add your Github organisation (https://github.com/settings/organizations) to config.py\n"
    exit()

parser = argparse.ArgumentParser(
    description='Delete github user from an organisation.')
parser.add_argument(
    'username',
    metavar='<user name>',
    nargs=1,
    help='Github user name that should be removed from the organization ' +
    config.Organisation)

args = parser.parse_args()

user = args.username[0]

response = functions.do_github_api_request(
    'https://api.github.com/orgs/' + config.Organisation + '/members/' + user,
    method='delete')

try:
    message = response.get('message', None)
    print(message)
except:
    response_code, result = response
    if (response_code == 204):
        print("User: "******" has been removed from the organization: " +
              config.Organisation)