public
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
from globusonline.graph import data_store
import globusonline.graph
from globusonline.graph.request import TestRequest
from globusonline.graph.users import resources as users
from globusonline.graph import groups
from ConfigParser import RawConfigParser
from sys import argv
 
# Setup:
config = RawConfigParser()
GO_CONFIG = argv[1] if len(argv) > 1 else '/home/mattias/virtualenv/globusonline-graph/development.ini'
config.read(GO_CONFIG)
app_options = dict(config.items('app:graph'))
store = data_store.from_settings(app_options)
crypto = globusonline.graph.auth.security.Crypto(app_options['shared_secret'])
request = TestRequest(store, crypto)
 
# Do stuff:
import uuid
from globusonline.graph.credentials.resources import UserCredentials
from globusonline.graph.users.resources import User
import globusonline.graph.credentials.utils as cred_utils
 
for rel in store.get_reference_node("myproxy").instance:
cred = rel.target_node.attributes
if not rel.target_node.has_myproxy.incoming.single:
continue
user_node = rel.target_node.has_myproxy.incoming.single.source_node
user = User(None, user_node, request)
print cred
try:
if cred.has_key('server') and cred.has_key('username') and cred.has_key('id_index') and \
"/O=Grid/OU=GlobusTest/OU=simpleCA-mgt6-mgmt.ether.alcf.anl.gov/CN=Globus Simple CA" in (cred['x509_issuer']):
credential_id = cred['username'] + '_' + 'oauth.alcf.anl.gov'
cred.pop('id_index')
cred['server'] = 'oauth.alcf.anl.gov'
unique_key = str(uuid.uuid4())
#user_creds = UserCredentials(user, request.data_store)
user_creds = user.credentials
if cred_utils.credential_exists_by_id(store, 'oauth', credential_id):
print("OAuth credential already exists")
else:
print("Inserting new credential")
user_creds.add_credential('oauth', unique_key, credential_id, cred)
except Exception as e:
print("Caught: ")
print(e)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.