From 495f89c6d1fb2e8a82a676ba05e48b46ffe3ba98 Mon Sep 17 00:00:00 2001 From: Manas Date: May 24 2019 17:46:41 +0000 Subject: Revert "Revert "test ini and keyring support"" This reverts commit 56ad1bd77cd656f7f50cc4535aef168c1eb67959. --- diff --git a/auth/__pycache__/__init__.cpython-36.pyc b/auth/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..e54dd9f Binary files /dev/null and b/auth/__pycache__/__init__.cpython-36.pyc differ diff --git a/auth/__pycache__/taiga.cpython-36.pyc b/auth/__pycache__/taiga.cpython-36.pyc new file mode 100644 index 0000000..e800c43 Binary files /dev/null and b/auth/__pycache__/taiga.cpython-36.pyc differ diff --git a/auth/__pycache__/tauth.cpython-36.pyc b/auth/__pycache__/tauth.cpython-36.pyc new file mode 100644 index 0000000..c7f18ab Binary files /dev/null and b/auth/__pycache__/tauth.cpython-36.pyc differ diff --git a/auth/pauth.py b/auth/pauth.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/auth/pauth.py diff --git a/auth/tauth.py b/auth/tauth.py new file mode 100644 index 0000000..99f156d --- /dev/null +++ b/auth/tauth.py @@ -0,0 +1,73 @@ +import requests +import json +import keyring +import random +import os +import binascii +import getpass +import configparser + +config = configparser.ConfigParser() +confi.read('config.ini') + +service_id = config['TAIGA']['SERVICE_ID'] # service id +service_token = config['TAIGA']['SERVICE_TOKEN'] # service d for auth + + +def refresh_token(): + headers = { + 'Content-Type': 'application/json' + } + """ + Used only for testing and Demo + Encrypted Config file/Application token + used in production. + Doing the follwoing in prod is security risk. + """ + username = keyring.get_password(service_id, "username") + print(username) + payload = { + 'type': 'normal', + 'username': username, + 'password': keyring.get_password(service_id, username) + } + # print(payload) # only for debugging + + try: + r = requests.post( + "https://api.taiga.io/api/v1/auth", + data=json.dumps(payload), + headers=headers) + print(r.status_code) + if r.status_code == 200: + """ + with open('auth.txt', 'w') as a_file: + a_file.write(r.json()['auth_token']) + """ + try: + keyring.set_password(service_token, "username", r.json()['auth_token']) + print("succesful authentication") + except (keyring.errors.PasswordSetError, Exception) as e: + print("Failed to set auth token") + elif r.status_code == 400: + print("auth error") + except Exception as e: + print(e) + + +def reset(): + print("You User Id and password will be securly store in the Keyring") + username = input("Enter your user id for taiga: ") + password = getpass.getpass("Enter your password for taiga: ") + try: + # keyring.set_password("taiga", username) + keyring.set_password(service_id, "username", username) + keyring.set_password(service_id, username, str(password)) + username = binascii.hexlify(os.urandom(20)) # randomising username to avoid sneak memory attacks + password = binascii.hexlify(os.urandom(20)) # ranomising pass to avoid sneak memory attacks + # username = random.choices(string.ascii_uppercase + string.digits, k=random.randint(1,10)) + # passwd = random.choices(string.ascii_uppercase + string.digits, k=random.randint(1,10)) + print("Password reset succesfully") + except (keyring.errors.PasswordSetError, Exception) as e: + print("Failed to reset password") + # print(e + "Contact the developers asap") diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..b3e5d51 --- /dev/null +++ b/config.ini @@ -0,0 +1,10 @@ +[TAIGA] +SERVICE_ID = taiga +SERVICE_TOKEN = taiga_auth +PID = 315827 # for test only + + +[PAGURE] +SERVICE_ID = pagure + +[BUGZILLA] \ No newline at end of file diff --git a/convert.py b/convert.py new file mode 100644 index 0000000..517e29a --- /dev/null +++ b/convert.py @@ -0,0 +1,78 @@ +import os +import requests +import json +import keyring +import configparser + +config = configparser.ConfigParser() +confi.read('config.ini') + +service_id = config['TAIGA']['SERVICE_ID'] # service id +service_token = config['TAIGA']['SERVICE_TOKEN'] +pid = config['TAIGA']['PID'] + +""" +with open('auth.txt', 'r') as a_file: + token = + # auth_t = token.encode("ascii", "ignore") + # print(token) # debug only +""" +keyring.get_password(service_id, username) +headers = { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer {0}'.format(keyring.get_password(service_id, username)) +} + + +def convert(args): + for _, value in args._get_kwargs(): # iteratingover name space object + for x in value: + try: + print(headers) # Debug only + url = "https://api.taiga.io/api/v1/issues/by_ref?ref=" + str(x) + "&project=" + str(pid) + # debugurl = "https://api.taiga.io/api/v1/issues/by_ref" + print(url) # debug/dev env only + # print(debugurl) # Debug only + # ino = str(x) + '/' + """ + params = ( + ('ref', ino), + ('project', str(pid)), + ) + """ + r = requests.get( + url, + # debugurl, + headers=headers, + # params=params + ) + # print("get object",r.json()) # Debug/Dev env only + if r.status_code == 200: + data = json.loads(r.content) + # print(data) + details = data['description'] + subject = data['subject'] + payload = { + 'project': pid, + 'description': details, + 'subject': subject + } + print("post object") + r = requests.post( + 'https://api.taiga.io/api/v1/userstories', + data=json.dumps(payload), + headers=headers + ) + if r.status_code == 200: + print("Sucessfully converted issue: {}".format(x)) + elif r.status_code == 401: + print("Authorization issues try reauthenticating") + except Exception as e: + print(e) + +""" +curl -X GET \ +-H "Content-Type: application/json" \ +-H "Authorization: Bearer ${eyJ1c2VyX2F1dGhlbnRpY2F0aW9uX2lkIjozNTY4MDR9:1hI6pm:4d4mA-gUXC2S0FxaladX0Fd_3gA}" \ +-s https://api.taiga.io/api/v1/issues/by_ref?ref=1\&project=315827 +""" \ No newline at end of file