예제 #1
0
 def run(self):
     create_oauth_token(
         name="TrelloZilla",
         key=self.conf.trello.api_key,
         secret=self.conf.trello.api_secret,
         expiration=self.conf.expiration,
     )
예제 #2
0
def generate():
    config = get_config_data()
    cfg = pick(config, 'connectors.trello')
    api_key = pick(cfg, 'api_key')
    api_secret = pick(cfg, 'api_secret')

    util.create_oauth_token(key=api_key, secret=api_secret)
예제 #3
0
def main():
    try:
        command = sys.argv[1]
    except IndexError:
        return

    if command == "oauth":
        create_oauth_token()
def setup_trello_oauth():
    config = get_trello_config()
    if not config.get('trello', 'token'):
        os.environ['TRELLO_API_KEY'] = config.get('trello', 'api_key')
        os.environ['TRELLO_API_SECRET'] = config.get('trello', 'api_secret')
        os.environ['TRELLO_EXPIRATION'] = "never"
        trello_util.create_oauth_token()

        print "^^^^ PUT THAT IN YOUR conf/trello.ini"
예제 #5
0
파일: Trello.py 프로젝트: danghuutoan/lib9
    def __init__(self, instance, data={}, parent=None, interactive=False):
        JSConfigClient.__init__(self,
                                instance=instance,
                                data=data,
                                parent=parent,
                                template=TEMPLATE,
                                interactive=interactive)

        from trello import TrelloClient

        if not self.config.data["token_secret_"]:
            print("**WILL TRY TO DO OAUTH SESSION")
            from trello.util import create_oauth_token
            access_token = create_oauth_token(
                key=self.config.data["api_key_"],
                secret=self.config.data["secret_"])
            self.config.data_set("token_", access_token["oauth_token"])
            self.config.data_set("token_secret_",
                                 access_token["oauth_token_secret"])

        self.client = TrelloClient(
            api_key=self.config.data["api_key_"],
            api_secret=self.config.data["secret_"],
            token=self.config.data["token_"],
            token_secret=self.config.data["token_secret_"])
예제 #6
0
def get_trello_client():
    '''Returns configured Trello client.
    
    Source .trello-creds if it exists. Otherwise prompt for required env vars.
    '''
    if os.path.exists(CREDS_FILE):
        with open(CREDS_FILE) as stream:
            creds = json.loads(stream.read())
    else:
        if not all([
                os.environ.get('TRELLO_API_KEY'),
                os.environ.get('TRELLO_API_SECRET')
        ]):
            raise RuntimeError(
                'Missing either TRELLO_API_KEY or TRELLO_API_SECRET for'
                ' initialization.\nThey can both be found at'
                ' https://trello.com/app-key')
        creds = {
            'api_key': os.environ.get('TRELLO_API_KEY'),
            'api_secret': os.environ.get('TRELLO_API_SECRET')
        }

    if not creds.get('token'):
        access_token = create_oauth_token(key=creds['api_key'],
                                          secret=creds['api_secret'],
                                          name='Trello Board Script')
        creds['token'] = access_token['oauth_token']
        creds['token_secret'] = access_token['oauth_token_secret']
        # Save credentials for next run
        with open(CREDS_FILE, 'w') as stream:
            stream.write(json.dumps(creds))
    return TrelloClient(**creds)
예제 #7
0
파일: trello.py 프로젝트: xmonader/js-ng
    def trello_client(self):

        if not self.token_secret:
            # print("**WILL TRY TO DO OAUTH SESSION")
            access_token = create_oauth_token(key=self.api_key,
                                              secret=self.secret)
            self.access_token_ = access_token["oauth_token"]
            self.access_token_secret = access_token["oauth_token_secret"]

        self.client = TrelloAPIClient(api_key=self.api_key_,
                                      api_secret=self.secret,
                                      token=self.token,
                                      token_secret=self.token_secret)
    def init_trello(self, key, secret):
        _ret = util.create_oauth_token(
            "1day",
            "read",
            key,
            secret,
            "trell-complete-report"
        )

        self.set_trello_key(key)
        self.set_trello_key_secret(secret)
        self.set_trello_oauth_key(_ret.get('oauth_token'))
        self.set_trello_oauth_secret(_ret.get('oauth_token_secret'))
        self.save()
예제 #9
0
    def _init(self, **kwargs):
        from trello import TrelloClient

        if not self.token_secret_:
            print("**WILL TRY TO DO OAUTH SESSION")
            from trello.util import create_oauth_token

            access_token = create_oauth_token(key=self.api_key_, secret=self.secret_)
            self.token_ = access_token["oauth_token"]
            self.token_secret_ = access_token["oauth_token_secret"]

        self.client = TrelloClient(
            api_key=self.api_key_, api_secret=self.secret_, token=self.token_, token_secret=self.token_secret_
        )
예제 #10
0
def auth(args):
    key = args.api_key or os.environ['TRELLO_API_KEY']
    secret = args.api_key_secret or os.environ['TRELLO_API_SECRET']
    mode = 'r+' if os.path.isfile(config.config_file) else 'w'
    with open(config.config_file, mode) as configfile:
        config_parser = RawConfigParser()
        if mode == 'r+':
            # If file exists read before auth to check it
            config_parser.read_file(configfile)
            configfile.seek(0)

        # Perform auth
        oauth_token = create_oauth_token(expiration=args.expiration, key=key, secret=secret, name=args.name)

        # Write the config
        config_parser.set('DEFAULT', 'trello_api_key', key)
        config_parser.set('DEFAULT', 'trello_api_secret', secret)
        config_parser.set('DEFAULT', 'trello_token', oauth_token['oauth_token'])
        config_parser.set('DEFAULT', 'trello_token_secret', oauth_token['oauth_token_secret'])
        config_parser.write(configfile)
예제 #11
0
def authenticate(args):
    """
    Function called by the authenticate subcommand to perform the initial authentication

    :args: Command line arguments. Must contain the following attributes : 'config', 'api_key', 'api_key_secret', 'name'
    """
    if os.path.exists(args.config):
        print("File already exists, aborting")

    oauth_token = create_oauth_token(expiration=args.expiration,
                                     key=args.api_key,
                                     secret=args.api_key_secret,
                                     name=args.name)
    conf = RawConfigParser()
    conf.set("DEFAULT", "trello_api_key", args.api_key)
    conf.set("DEFAULT", "trello_api_secret", args.api_key_secret)
    conf.set("DEFAULT", "trello_token", oauth_token['oauth_token'])
    conf.set("DEFAULT", "trello_token_secret",
             oauth_token['oauth_token_secret'])
    with open(args.config, 'w') as f:
        conf.write(f)
__author__ = 'aapa'
from trello import util

api_key = 'xxxx'
api_secret = 'xxxx'

util.create_oauth_token(key=api_key, secret=api_secret)

#!/usr/bin/env python
# Load in our auth utility from py-trello
# https://github.com/sarumont/py-trello/blob/0.4.3/trello/util.py
from trello.util import create_oauth_token


# Run our script
if __name__ == '__main__':
    create_oauth_token(name='slack-to-trello', scope='read,write', expiration='never')
예제 #14
0
    def __load_authentication_credentials(
            config_file_name='.auth.cfg',
            section='trello'):
        """ Loads authentication credentials from an ini-style
        configuration file.

        Args:
            config_file_name (str): Basename of the configuration file.
            section (str): Configuration file section name.

        Returns: dict: the selected credentials
        """
        config_file_path = os.path.join(
            os.path.expanduser("~"),
            config_file_name)

        logging.getLogger(__name__).info(
            "Loading trello credentials from %s",
            config_file_path)

        if not os.path.exists(config_file_path):
            raise scriptabit.ConfigError(
                "File '{0}' not found".format(config_file_path))

        config = ConfigParser()
        config.read(config_file_path)

        credentials = {
            'apikey': config.get(section, 'apikey'),
            'apisecret': config.get(section, 'apisecret'),
            'token': '',
            'tokensecret': ''}

        try:
            credentials['token'] = config.get(section, 'token')
            credentials['tokensecret'] = config.get(section, 'tokensecret')
        except NoOptionError:
            # If the OAuth tokens are missing, they will get filled in later
            pass

        if not credentials['apikey']:
            raise scriptabit.ConfigError(
                'Trello API key not found in .auth.cfg')

        if not credentials['apisecret']:
            raise scriptabit.ConfigError(
                'Trello API secret not found in .auth.cfg')

        if not credentials['token'] or not credentials['tokensecret']:
            logging.getLogger(__name__).warning('Getting Trello OAuth token')
            access_token = create_oauth_token(
                expiration='never',
                scope='read,write',
                key=credentials['apikey'],
                secret=credentials['apisecret'],
                name='scriptabit',
                output=True)
            credentials['token'] = access_token['oauth_token']
            credentials['tokensecret'] = access_token['oauth_token_secret']

            # Write back to the file
            config_file_path = os.path.join(
                os.path.expanduser("~"),
                '.auth.cfg')
            with open(config_file_path, 'w') as f:
                logging.getLogger(__name__).warning(
                    'Writing Trello OAuth tokens back to .auth.cfg')
                config.set('trello', 'token', credentials['token'])
                config.set(
                    'trello',
                    'tokensecret',
                    credentials['tokensecret'])
                config.write(f)

        return credentials
예제 #15
0
 def create_oauth(self):
         from trello import util
         util.create_oauth_token()
         sys.exit(0)
예제 #16
0
import os
from trello import TrelloClient
from trello.util import create_oauth_token

api_key = os.environ['TRELLO_API_KEY']
api_secret = os.environ['TRELLO_API_SECRET']

create_oauth_token(key=api_key, secret=api_secret, scope='read,write', expiration='never',name='Madeleine')
#!/usr/bin/env python
# Load in our auth utility from py-trello
# https://github.com/sarumont/py-trello/blob/0.4.3/trello/util.py
from trello.util import create_oauth_token

# Run our script
if __name__ == '__main__':
    create_oauth_token(name='slack-to-trello',
                       scope='read,write',
                       expiration='never')
예제 #18
0
    """ No matching Lists found """


TRELLO_API_KEY = os.environ.get('TRELLO_API_KEY')
if not TRELLO_API_KEY:
    print('Set TRELLO_API_KEY, from https://trello.com/app-key')
    sys.exit(1)

TRELLO_API_SECRET = os.environ.get('TRELLO_API_SECRET')
if not TRELLO_API_SECRET:
    print('Set TRELLO_API_SECRET from the bottom of https://trello.com/app-key')
    sys.exit(1)

TRELLO_API_TOKEN = os.environ.get('TRELLO_API_TOKEN')
if not TRELLO_API_TOKEN:
    create_oauth_token(expiration='1day', scope='read')


GITHUB_USER = os.environ.get('GITHUB_USER')
GITHUB_PASSWORD = os.environ.get('GITHUB_PASSWORD')
if not GITHUB_USER or not GITHUB_PASSWORD:
    print('Missing GitHub credentials, https://github.com/settings/tokens')
    sys.exit(1)


def get_board(trello, board):
    for b in trello.list_boards():
        if b.id == board:
            return b
        elif b.name == board:
            return b
예제 #19
0
"""
This script really just simplifies the process of issuing OAuth tokens for the most common
use case of this bot. It merely reads off the api_{key,secret} already defined in the
cfg files, and uses the existing py-trello script to guide the user through the rest of
the process.
"""

# Snag the API key and secret. But load the config first ;)
config = RawConfigParser()
config.read(['bot.cfg', 'dev_secrets.cfg'])

trello_api_key = config.get('trello', 'api_key')
trello_api_secret = config.get('trello', 'api_secret')

access_token = create_oauth_token(expiration='never',
    scope='read,write',
    key=trello_api_key,
    secret=trello_api_secret,
    name='My%20Trello%20Bot',
    output=False
)

# Now, we dump the new values to our secret config file.
config_out = RawConfigParser()
config_out.add_section('trello')
config_out.set('trello', 'oauth_token', access_token['oauth_token'])
config_out.set('trello', 'oauth_secret', access_token['oauth_token_secret'])
with open('bot_secrets.cfg', 'w') as secrets:
    secrets.write('; !!!!! Automatically generated by trello_setup.py !!!!!\n')
    config_out.write(secrets)
예제 #20
0
        space = input("Confluence Space ID:").strip()
        parent = input("Parent page ID:").strip()
        parent_page = confluence.get_page_by_id(parent)

    boards = None

    while not boards:
        trello_api_key = keys.get('trello_api_key') or input(
            "Trello API Key (https://trello.com/app-key):").strip()
        trello_api_secret = keys.get('trello_api_secret') or input(
            "Trello API Secret (https://trello.com/app-key):").strip()

        if 'oauth_token' not in keys or 'oauth_token_secret' not in keys:
            try:
                oauth_result = util.create_oauth_token('never', 'read,write',
                                                       trello_api_key,
                                                       trello_api_secret)
                keys['oauth_token'] = oauth_result['oauth_token']
                keys['oauth_token_secret'] = oauth_result['oauth_token_secret']
            except:
                try:
                    del keys['trello_api_key']
                    del keys['trello_api_secret']
                except:
                    pass

        oauth_token = keys.get('oauth_token')
        oauth_token_secret = keys.get('oauth_token_secret')

        trello = TrelloClient(api_key=trello_api_key,
                              api_secret=trello_api_secret,

# Using: https://pypi.org/project/py-trello/
# https://github.com/sarumont/py-trello
# PDF documentation: https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=&cad=rja&uact=8&ved=2ahUKEwji5eCS7OXvAhX-M1kFHeVGADMQFjAAegQIBxAD&url=https%3A%2F%2Freadthedocs.org%2Fprojects%2Fpy-trello-dev%2Fdownloads%2Fpdf%2Flatest%2F&usg=AOvVaw1-vlt-k1FXhBt1uslG60E7
from trello import TrelloClient
from trello.util import create_oauth_token
import authorization
import os

# store our applications API key/secret
os.environ["TRELLO_API_KEY"] = '2e0161c01eca7ad03bda843f811dac8b'
os.environ[
    "TRELLO_API_SECRET"] = 'd4446e39644f0992f6db9859c77441754f0085ad5725d86699780d1ba86dfeea'
# get the users unique tokens
user_token = create_oauth_token()
print(user_token)
#print(user_token.get('oauth_token'))
#print(user_token.get('oauth_token_secret'))

# These need to be replaced with each user's information
# user: [email protected]
# pass: Piw2amhhPy7DFng
client = TrelloClient(
    api_key='2e0161c01eca7ad03bda843f811dac8b',
    api_secret=
    'd4446e39644f0992f6db9859c77441754f0085ad5725d86699780d1ba86dfeea',
    #token = '3e412495cb8cb892871070726e2d289a4dbf781f0a8deb37bd04a39dbebf62de'
    token=user_token.get('oauth_token'),
    token_secret=user_token.get('oauth_token_secret'))
예제 #22
0
import os
from trello import TrelloClient
from trello.util import create_oauth_token

api_key = os.environ['TRELLO_API_KEY']
api_secret = os.environ['TRELLO_API_SECRET']

create_oauth_token(key=api_key,
                   secret=api_secret,
                   scope='read,write',
                   expiration='never',
                   name='Madeleine')