示例#1
0
def main():
    # script constants
    settings_filename = os.path.join(expanduser("~"), ".tstool.settings")
    
    browsers = ['safari', 'chrome', 'firefox', 'clipboard']

    args = getArgs()
    env = args.env if args.env else ''

    if(env == "test"):
        master_client_id = '0414db0b148d483eb781a00ee970efc3'
        client_id = '9e9fb27d0e5b488eb5b70322cb65e0de'
        client_secret = 'd9fde1beae694aa2a2f727b791b6012b'
        domain = 'brightideatest'
        resource_endpoint = 'https://auth.brightideatest.com/api3'
    else:
        master_client_id = '9161C1CB042E40F185771DD52A39048E'
        client_id = '4A2D7960D87346B995D34CA44F636E3A'
        client_secret = '24B87340107A49A385F6678C4E9062A8'
        domain = 'brightidea'
        resource_endpoint = 'https://bi.brightidea.com/api3'


    shelf = shelve.open(settings_filename)
    if(env+'secret' in shelf and 'email' in shelf):
        master_secret=shelf[env+"secret"]
        email=shelf["email"]
    else:
        #get master secret through api
        client = Client(
            token_endpoint="https://auth."+domain+".com/_oauth2/token",
            client_id=client_id,
            client_secret=client_secret)
        client.resource_endpoint = resource_endpoint
        username = raw_input("Please enter your idea space account email: ")
        password = getpass.getpass('Enter your password: '******'password',username=username,password=password)

        master_account = client.request("/apiAccount/"+master_client_id)
        master_secret = master_account["apiAccount"]["secret"]
        email=username

        shelf[env+"secret"]=master_secret
        shelf["email"]=username
        shelf.sync()

    #Determine the browser
    if(args.command in browsers):
        shelf["browser"]=args.command
        shelf.sync()
        print("Browser is changed to "+args.command)
        sys.exit()

    if('browser' in shelf):
        browser = shelf["browser"]
    else:
        browser = "chrome"

    inputURL = urlparse(args.command)
    targetURL = urllib.quote(args.command)

    # API config
    bi = Brightidea(token_endpoint="https://"+inputURL.hostname+"/_oauth2/token",
    	client_id=master_client_id,
    	client_secret=master_secret,
        host_name=inputURL.hostname)

    access_token = bi.client.access_token

    login_url = "https://"+inputURL.hostname+"/api3/session/me?access_token="+access_token+"&target="+targetURL+"&email="+email

    if(args.admin):
        login_url += "&admin=1"

    if(args.email):
        login_url += "&email="+args.email

    if(args.screen_name):
        login_url += "&screen_name="+args.screen_name

    openBrowser(browser, login_url)
示例#2
0
文件: tstool.py 项目: jinziqi/TSTool
def main():
    # script constants
    settings_filename = os.path.join(expanduser("~"), ".tstool.settings")
    master_client_id = '9161C1CB042E40F185771DD52A39048E'
    client_id = '4A2D7960D87346B995D34CA44F636E3A'
    client_secret = '24B87340107A49A385F6678C4E9062A8'

    shelf = shelve.open(settings_filename)
    if('secret' in shelf and 'email' in shelf):
        master_secret=shelf["secret"]
        email=shelf["email"]
    else:
        #get master secret through api
        client = Client(
            token_endpoint="https://auth.brightidea.com/_oauth2/token",
            client_id=client_id,
            client_secret=client_secret)
        client.resource_endpoint = 'https://bi.brightidea.com/api3'
        username = raw_input("Please enter your idea space account email: ")
        password = raw_input("Enter your password: "******"/apiAccount/"+master_client_id)
        master_secret = master_account["apiAccount"]["secret"]
        email=username

        shelf["secret"]=master_secret
        shelf["email"]=username
        shelf.sync()

    #Determine the browser
    if(sys.argv[1] == "chrome"):
        shelf["browser"]="chrome"
        shelf.sync()
        print("Browser is changed to Chrome")
        sys.exit()
    elif(sys.argv[1] == "safari"):
        shelf["browser"]="safari"
        shelf.sync()
        print("Browser is changed to Safari")
        sys.exit()
    elif(sys.argv[1] == "firefox"):
        shelf["browser"]="firefox"
        shelf.sync()
        print("Browser is changed to firefox")
        sys.exit()
    elif(sys.argv[1] == "custom"):
        shelf["browser"]="custom"
        shelf.sync()
        print("Browser is changed to custom")
        sys.exit()

    if('browser' in shelf):
        browser = shelf["browser"]
    else:
        browser = "safari"

    inputURL = urlparse(sys.argv[1])
    targetURL = urllib.quote(sys.argv[1])

    # API config
    bi = Brightidea(token_endpoint="https://"+inputURL.hostname+"/_oauth2/token",
    	client_id=master_client_id,
    	client_secret=master_secret,
        host_name=inputURL.hostname)

    access_token = bi.client.access_token

    login_url = "https://"+inputURL.hostname+"/api3/session/me?access_token="+access_token+"&target="+targetURL+"&email="+email
    
    if(sys.platform == "darwin"):
        if(browser == "safari"):
            call(["open","-a","Safari",login_url])
        elif(browser == "chrome"):
            call(["open","-a","Google Chrome",login_url])
    elif(sys.platform == "linux2"):
        if(browser == "chrome"):
            call(['google-chrome', login_url])
        elif(browser == "firefox"):
            call(['google-chrome', login_url])
        elif(browser == "custom"):
            print(login_url)