Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoint to list clients #268

Merged
merged 6 commits into from Dec 26, 2019
Merged

Add endpoint to list clients #268

merged 6 commits into from Dec 26, 2019

Conversation

c-w
Copy link
Member

@c-w c-w commented Dec 26, 2019

This change required a data migration:

import json
import os
import uuid

from opwen_email_server import config
from opwen_email_server.constants import azure as constants
from opwen_email_server.services import storage

storage_account = os.environ['STORAGE_ACCOUNT']
storage_key = os.environ['STORAGE_KEY']

old_storage = storage.AzureTextStorage(
    account=storage_account,
    key=storage_key,
    host=config.TABLES_HOST,
    secure=config.TABLES_SECURE,
    container=constants.TABLE_AUTH,
    provider=config.STORAGE_PROVIDER,
)

new_storage = storage.AzureObjectStorage(
    account=storage_account,
    key=storage_key,
    host=config.TABLES_HOST,
    secure=config.TABLES_SECURE,
    container=constants.TABLE_AUTH,
    provider=config.STORAGE_PROVIDER,
)

auths = []

for resource_id in old_storage.iter():
    try:
        uuid.UUID(resource_id, version=4)
    except ValueError:
        domain = resource_id
        auth = old_storage.fetch_text(resource_id)
        try:
            auth = json.loads(auth)
        except json.JSONDecodeError:
            client_id = auth
            owner = None
        else:
            client_id = auth['client_id']
            owner = auth['owner']
        auths.append({'owner': owner, 'domain': domain, 'client_id': client_id})

for auth in auths:
    client_id = auth['client_id']
    domain = auth['domain']
    new_storage.store_object(f'client_id/{client_id}', auth)
    new_storage.store_object(f'domain/{domain}', auth)

@c-w c-w merged commit 8de04d9 into master Dec 26, 2019
3 checks passed
@c-w c-w deleted the list-clients branch Dec 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant