Пример #1
0
def post_register_name(
        session, snap_name,
        registrant_comment=None, is_private=False, store=None):

    json = {
        'snap_name': snap_name,
    }

    if registrant_comment:
        json['registrant_comment'] = registrant_comment

    if is_private:
        json['is_private'] = is_private

    if store:
        json['store'] = store

    response = cache.get(
        REGISTER_NAME_URL,
        headers=get_authorization_header(session),
        json=json,
        method='POST')

    if authentication.is_macaroon_expired(response.headers):
        raise MacaroonRefreshRequired()

    return process_response(response)
Пример #2
0
def snap_screenshots(snap_id, session, data=None, files=None):
    method = None
    files_array = None
    headers = get_authorization_header(session)
    headers['Accept'] = 'application/json'

    if data:
        method = 'PUT'

        files_array = []
        if files:
            for f in files:
                files_array.append(
                    (f.filename, (f.filename, f.stream, f.mimetype))
                )
        else:
            # API requires a multipart request, but we have no files to push
            # https://github.com/requests/requests/issues/1081
            files_array = {'info': ('', data['info'])}
            data = None

    screenshot_response = cache.get(
        SCREENSHOTS_QUERY_URL.format(snap_id=snap_id),
        headers=headers,
        data=data,
        method=method,
        files=files_array
    )

    if authentication.is_macaroon_expired(screenshot_response.headers):
        raise MacaroonRefreshRequired()

    return process_response(screenshot_response)
Пример #3
0
def get_snap_info(snap_name, session):
    response = cache.get(
        SNAP_INFO_URL.format(snap_name=snap_name),
        headers=get_authorization_header(session)
    )

    if authentication.is_macaroon_expired(response.headers):
        raise MacaroonRefreshRequired()

    return process_response(response)
Пример #4
0
def get_agreement(session):
    headers = get_authorization_header(session)

    agreement_response = cache.get(
        AGREEMENT_URL,
        headers
    )

    if authentication.is_macaroon_expired(agreement_response.headers):
        raise MacaroonRefreshRequired()

    return agreement_response.json()
Пример #5
0
def get_account(session):
    headers = get_authorization_header(session)

    response = cache.get(
        url=ACCOUNT_URL,
        method='GET',
        headers=headers
    )

    if authentication.is_macaroon_expired(response.headers):
        raise MacaroonRefreshRequired()

    return process_response(response)
Пример #6
0
def snap_metadata(snap_id, session, json=None):
    method = "PUT" if json is not None else None

    metadata_response = cache.get(
        METADATA_QUERY_URL.format(snap_id=snap_id),
        headers=get_authorization_header(session),
        json=json,
        method=method
    )

    if authentication.is_macaroon_expired(metadata_response.headers):
        raise MacaroonRefreshRequired()

    return process_response(metadata_response)
Пример #7
0
def get_publisher_metrics(session, json):
    authed_metrics_headers = PUB_METRICS_QUERY_HEADERS.copy()
    auth_header = get_authorization_header(session)['Authorization']
    authed_metrics_headers['Authorization'] = auth_header

    metrics_response = cache.get(
        SNAP_PUB_METRICS_URL,
        headers=authed_metrics_headers,
        json=json
    )

    if authentication.is_macaroon_expired(metrics_response.headers):
        raise MacaroonRefreshRequired()

    return process_response(metrics_response)
Пример #8
0
def post_agreement(session, agreed):
    headers = get_authorization_header(session)

    json = {
        'latest_tos_accepted': agreed
    }
    agreement_response = cache.get(
        AGREEMENT_URL,
        headers,
        json
    )

    if authentication.is_macaroon_expired(agreement_response.headers):
        raise MacaroonRefreshRequired()

    return process_response(agreement_response)
Пример #9
0
def post_username(session, username):
    headers = get_authorization_header(session)
    json = {
        'short_namespace': username
    }
    username_response = cache.get(
        url=ACCOUNT_URL,
        headers=headers,
        json=json,
        method='PATCH'
    )

    if authentication.is_macaroon_expired(username_response.headers):
        raise MacaroonRefreshRequired()

    if username_response.status_code == 204:
        return {}
    else:
        return process_response(username_response)