daily pastebin goal
30%
SHARE
TWEET

Untitled

a guest May 16th, 2018 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import json
  2. import copy
  3. from pprint import pprint
  4.  
  5. # Get mock file from v2.3
  6. with open('apptestv23.json') as f:
  7.     apps_from_v1 = json.load(f)
  8.  
  9. # Get mock file from v3
  10. with open('apptestv30.json') as f:
  11.     apps_from_v2 = json.load(f)
  12.  
  13. ids_from_v2 = set([app['id'] for app in apps_from_v1])
  14. ids_from_v3 = set([app['id'] for app in apps_from_v2])
  15.  
  16. # Get ids of app not registered in v3
  17. different_ids = ids_from_v2 - ids_from_v3
  18.  
  19.  
  20. def build_grant_types(oldApp):
  21.     grant_types = []
  22.     grant_type = {}
  23.     for element in app['grant_types']:
  24.         # Refresh token is added by authserver
  25.         # XXX Add more logic for authorization_code, client_credentials
  26.         # and jwt-bearer. Apps should use jwt-bearer if they use pi-scopes.
  27.         # Authorization_code and client_credentials should have only scopes.
  28.         if element != 'refresh_token':
  29.             grant_type['name'] = element
  30.             grant_type['scopes'] = app['scopes']
  31.             grant_type['purposes'] = []
  32.             grant_types.append(copy.copy(grant_type))
  33.     return grant_types
  34.  
  35.  
  36. def build_new_app(app):
  37.     newApp = {}
  38.     newApp['id'] = app['id']
  39.     newApp['name'] = app['name']
  40.     newApp['secret'] = app['secret']
  41.     newApp['description'] = app['description']
  42.     newApp['redirect_uris'] = app['redirect_uris']
  43.     newApp['grant_types'] = build_grant_types(app)
  44.     return newApp
  45.  
  46.  
  47. # Find app in r2.3 to recrete in v3
  48. for index, app in enumerate(apps_from_v1):
  49.     for item in list(different_ids):
  50.         if app['id'] == item:
  51.             newApp = {}
  52.             newApp = build_new_app(app)
  53.             different_ids.remove(item)
RAW Paste Data
Top