Skip to content

Add endpoint to list clients#268

Merged
c-w merged 6 commits intomasterfrom
list-clients
Dec 26, 2019
Merged

Add endpoint to list clients#268
c-w merged 6 commits intomasterfrom
list-clients

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
@c-w c-w deleted the list-clients branch December 26, 2019 04:10
c-w pushed a commit that referenced this pull request Apr 28, 2020
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.

1 participant