예제 #1
0
    def client(self) -> Client:
        """Instantiates python-asana Client"""
        if not self.connection.password:
            raise ValueError(
                "Asana connection password must contain a personal access token: "
                "https://developers.asana.com/docs/personal-access-token")

        return Client.access_token(self.connection.password)
예제 #2
0
    def _get_client() -> Client:
        client = Client.access_token(config.ASANA_CREDENTIALS.token)

        # This suppresses a warning from the Asana API that they're moving to string based IDs
        # it's not an issue for us.
        client.headers.update({"Asana-Enable": "string_ids,new_sections"})

        return client
예제 #3
0
파일: client.py 프로젝트: Asana/archie
 def __init__(self, access_token: str) -> None:
     self._client = AsanaClient.access_token(access_token)
     self._client.headers.update({
         "Asana-Enable":
         "new_sections,string_ids",
         "User-Agent":
         f"asana-archie/{__version__}",
     })
     self._client.session.mount(
         "https://", HTTPAdapter(pool_maxsize=_CONNECTION_POOL_SIZE))
예제 #4
0
 def __init__(
         self,
         token: str,
         project_id: Optional[str] = None,
         section_id: Optional[str] = None,
         tag_id: Optional[str] = None,
 ):
     self._client = Client.access_token(token)
     if project_id is not None:
         filter_func = lambda: self._client.tasks.find_by_project(project_id)
     elif section_id is not None:
         filter_func = lambda: self._client.tasks.find_by_section(section_id)
     elif tag_id is not None:
         filter_func = lambda: self._client.tasks.find_by_tag(tag_id)
     else:
         raise ValueError("You should set one of filter_props")
     self.filter_func = filter_func
def init(access_token: str):
    """
    Use this helper to get specific values from Asana API and choose the tasks you need.

    Before launch you should make or get access_token — https://asana.com/guide/help/api/api
    """
    client = Client.access_token(access_token)

    click.echo('Starting validation of access_token...')
    with click_spinner.spinner():
        try:
            user = client.users.me()
        except NoAuthorizationError:
            click.secho(
                'Token is invalid. Please check your token and read the ' +
                'official documentation: https://asana.com/guide/help/api/api',
                fg='red')
            return
    click.echo('Hello, {0}'.format(user['name']))

    click.echo('Fetching workspaces...')
    with click_spinner.spinner():
        workspaces = list(client.workspaces.find_all())

    click.echo('Please choose workspace')
    for i, w in enumerate(workspaces, 1):
        click.echo('{index}: {name} ({gid})'.format(
            index=i,
            name=w['name'],
            gid=w['gid'],
        ))
    workspace_index = click.prompt('Your choice', type=int) - 1
    workspace = workspaces[workspace_index]

    click.echo('Selected workspace {name} ({gid})'.format(
        name=workspace['name'], gid=workspace['gid']))

    filter_type = click.prompt(
        'You can use only one type of fetching tasks:\n' +
        '1. Show in status bar last task filtered by tag\n' +
        '2. Show in status bar last task filtered by project\n' +
        '3. Show in status bar last task filtered by column of board (so-called section)\n'
        'Your choice',
        type=int)

    if filter_type == 1:
        click.echo('Fetching tags...')
        with click_spinner.spinner():
            tags = list(client.tags.find_all(workspace=workspace['gid']))
        click.echo('Please choose tag')
        for i, t in enumerate(tags, 1):
            click.echo('{index}: {name} ({gid})'.format(
                index=i,
                name=t['name'],
                gid=t['gid'],
            ))
        tag_index = click.prompt('Your choice', type=int) - 1
        tag = tags[tag_index]

        click.secho('Use run command with "--tag-id {0}"'.format(tag['gid']),
                    fg='green')
        return

    click.echo('Fetching projects...')
    with click_spinner.spinner():
        projects = list(client.projects.find_all(workspace=workspace['gid']))
    click.echo('Please choose project')
    for i, p in enumerate(projects, 1):
        click.echo('{index}: {name} ({gid})'.format(
            index=i,
            name=p['name'],
            gid=p['gid'],
        ))
    project_index = click.prompt('Your choice', type=int) - 1
    project = projects[project_index]

    if filter_type == 2:
        click.secho('Use run command with "--project-id {0}"'.format(
            project['gid']),
                    fg='green')
        return

    if filter_type == 3:
        click.echo('Fetching sections...')
        with click_spinner.spinner():
            sections = list(
                client.sections.find_by_project(project=project['gid']))
        click.echo('Please choose column of board (section)')
        for i, s in enumerate(sections, 1):
            click.echo('{index}: {name} ({gid})'.format(
                index=i,
                name=s['name'],
                gid=s['gid'],
            ))
        section_index = click.prompt('Your choice', type=int) - 1
        section = sections[section_index]
        click.secho('Use run command with "--section-id {0}"'.format(
            section['gid']),
                    fg='green')
        return
예제 #6
0
# Workflow settings
BACKLOG_TAG_ID = <FILL ME IN>
BAG_OF_TASKS_TAG_ID = <FILL ME IN>
MAIN_PRJ_ID = <FILL ME IN>
MAIN_PRJ = {'id': MAIN_PRJ_ID, 'name': 'Main'}

ASANA_TIMEOUT = 60

# If `entrypoint` is not defined in app.yaml, App Engine will look for an app
# called `app` in `main.py`.
app = Flask(__name__)
app.config['JWT_SECRET_KEY'] = JWT_SECRET_KEY
jwt = JWTManager(app)

asana_client = Client.access_token(ASANA_API_KEY)


@app.route('/api/login', methods=['POST'])
def login():
    if not request.is_json:
        return jsonify({"msg": "Missing JSON in request"}), 400

    params = request.get_json()
    username = params.get('username', None)
    password = params.get('password', None)

    if not username:
        return jsonify({"msg": "Missing username parameter"}), 400
    if not password:
        return jsonify({"msg": "Missing password parameter"}), 400
예제 #7
0
def asana_client():
    a_client = Client.access_token(settings.ASANA_PAT)
    return a_client