Skip to content

Instantly share code, notes, and snippets.

@mattias-lidman
Created January 24, 2012 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattias-lidman/1672915 to your computer and use it in GitHub Desktop.
Save mattias-lidman/1672915 to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment