Ejemplo n.º 1
0
def getCredentialsClient( local = False ):
  if local or WebAPICS.useLocalDB():
    if not 'local' in __credObjs:
      __credObjs[ 'local' ] = CredentialsDB()
    return __credObjs[ 'local' ]
  if not 'remote' in __credObjs:
    __credObjs[ 'remote' ] = CredentialsClient()
  return __credObjs[ 'remote' ]
Ejemplo n.º 2
0
def oauthAuthorizeToken():
  gOAManager.parse()

  if gOAData.token:
    webURL = WebAPICS.getAuthorizeURL()
    if not webURL:
      gLogger.fatal( "Missing WebURL location!" )
      bottle.abort( 500 )
    setup = gConfig.getValue( "/DIRAC/Setup", "" )
    if not setup:
      gLogger.fatal( "No setup defined. THIS CANNOT HAPPEN!!" )
      bottle.abort( 500 )
    webURL = "%s?oauth_token=%s&setup=%s" % ( webURL, urllib.quote_plus( gOAData.token ), setup )
    if gOAData.callback:
      webURL = "%s&oauth_callback=%s" % ( webURL, urllib.quote_plus( gOAData.callback ) )
    gLogger.notice( "redirecting to %s" % webURL )
    bottle.redirect( webURL )

  bottle.abort( 400, "Missing request token" )
Ejemplo n.º 3
0
from DIRAC.Core.Utilities import DictCache
import WebAPIDIRAC.ConfigurationSystem.Client.Helpers.WebAPI as WebAPICS

#GET    SELET
#POST   INSERT
#PUT    UPDATE
#DELETE DELETE

def deleteFile( filePath ):
  try:
    os.unlink( filePath )
  except:
    pass

gFileCache = DictCache( deleteFile )
gWorkDir = WebAPICS.getWorkDir()

def initialize():
  if not os.path.isdir( gWorkDir ):
    try:
      os.makedirs( gWorkDir )
    except:
      raise RuntimeError( "Can't create %s" % gWorkDir )
  for ent in os.listdir( gWorkDir ):
    ent = os.path.join( gWorkDir, ent )
    if os.path.isdir( ent ):
      shutil.rmtree( ent )
    else:
      os.unlink( ent )

Ejemplo n.º 4
0
import bottle, sys


from DIRAC.Core.Base import Script
from DIRAC import gLogger


@bottle.route("/")
def index():
    html = "<html><body>Howdy cowboy!</body></html>"
    return html


if __name__ == "__main__":
    import WebAPIDIRAC.ConfigurationSystem.Client.Helpers.WebAPI as WebAPICS
    from WebAPIDIRAC.WebAPISystem.private.BottleOAManager import OAuthPlugin
    from WebAPIDIRAC.WebAPISystem.private.RouteLoader import loadRoutes

    Script.localCfg.addDefaultEntry("/DIRAC/Security/UseServerCertificate", "true")
    Script.localCfg.addDefaultEntry("LogLevel", "INFO")
    Script.enableCS()
    Script.parseCommandLine()
    result = WebAPICS.isOK()
    if not result["OK"]:
        gLogger.fatal(result["Message"])
        sys.exit(1)

    loadRoutes()
    bottle.install(OAuthPlugin())
    bottle.run(host="", port=9354, reloader=False)  # , server = "flup" )