Skip to content

Commit

Permalink
Merge pull request #60 from Kinto/59-add-buckets-root-level
Browse files Browse the repository at this point in the history
Add buckets root level in YAML (fixes #59)
  • Loading branch information
leplatrem authored Dec 6, 2018
2 parents c269ad0 + d5865d5 commit 2208f05
Show file tree
Hide file tree
Showing 17 changed files with 474 additions and 452 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ Changelog

This document describes changes between each past release.

3.1.0 (unreleased)
4.0.0 (unreleased)
------------------

- Nothing changed yet.
**Breaking changes**

- ``kinto-wizard load`` now expects to find a ``buckets:`` root level in the YAML file.
And ``kinto-wizard dump`` will now add it (fixes #59)


3.0.0 (2018-10-17)
Expand Down
7 changes: 4 additions & 3 deletions kinto_wizard/kinto2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ async def introspect_server(client, bucket=None, collection=None, data=False, re
bucket_info = await introspect_bucket(client, bucket, collection=collection,
data=data, records=records)
if bucket_info:
return {bucket: bucket_info}
return {}
return {"buckets": {bucket: bucket_info}}
return {"buckets": {}}

logger.info("Fetch buckets list.")
buckets = await client.get_buckets()
return await gather_dict({
buckets_tree = await gather_dict({
bucket['id']: introspect_bucket(client, bucket['id'], collection=collection,
data=data, records=records)
for bucket in buckets
})
return {"buckets": buckets_tree}


async def introspect_bucket(client, bid, collection=None, data=False, records=False):
Expand Down
10 changes: 6 additions & 4 deletions kinto_wizard/yaml2kinto.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ async def initialize_server(async_client, config, bucket=None, collection=None,
collection=collection,
records=True
)
current_server_buckets = current_server_status["buckets"]
else:
# We don't need to load it because we will override it nevertheless.
current_server_status = {}
current_server_buckets = {}
# 2. For each bucket
buckets = config.get("buckets", {})
with async_client.batch() as batch:
for bucket_id, bucket in config.items():
for bucket_id, bucket in buckets.items():
# Skip buckets that we don't want to import.
if bid and bucket_id != bid:
logger.debug("Skip bucket {}".format(bucket_id))
continue
bucket_exists = bucket_id in current_server_status
bucket_exists = bucket_id in current_server_buckets
bucket_data = bucket.get('data', {})
bucket_permissions = bucket.get('permissions', {})
bucket_groups = bucket.get('groups', {})
Expand All @@ -47,7 +49,7 @@ async def initialize_server(async_client, config, bucket=None, collection=None,
permissions=bucket_permissions,
safe=(not force))
else:
current_bucket = current_server_status[bucket_id]
current_bucket = current_server_buckets[bucket_id]
bucket_current_groups = {}
bucket_current_collections = {}
current_bucket_data = {}
Expand Down
39 changes: 20 additions & 19 deletions tests/dumps/dump-date.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
date:
collections:
dates:
data:
created_at: '2018-06-22T16:34:43.330907'
id: dates
last_modified: 1496132464691
published_date: '2018-06-22'
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records: {}
data:
id: date
last_modified: 1529681414530
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
buckets:
date:
collections:
dates:
data:
created_at: '2018-06-22T16:34:43.330907'
id: dates
last_modified: 1496132464691
published_date: '2018-06-22'
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records: {}
data:
id: date
last_modified: 1529681414530
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
143 changes: 72 additions & 71 deletions tests/dumps/dump-full.yaml
Original file line number Diff line number Diff line change
@@ -1,71 +1,72 @@
natim:
collections:
toto:
data:
id: toto
last_modified: 1496132464691
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records:
e2686bac-c45e-4144-9738-edfeb3d9da6d:
data:
id: e2686bac-c45e-4144-9738-edfeb3d9da6d
last_modified: 1496132479127
permissions: {}
data:
id: natim
last_modified: 1496132446213
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
natim2:
collections:
toto:
data:
id: toto
last_modified: 1496132461211
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records:
ee338fcd-3a19-4a4f-af05-a8b052a23521:
data:
id: ee338fcd-3a19-4a4f-af05-a8b052a23521
last_modified: 1496132482950
permissions: {}
totot:
data:
id: totot
last_modified: 1496132458576
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records: {}
data:
id: natim2
last_modified: 1496132453519
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
date:
collections:
dates:
data:
id: dates
last_modified: 1496132464691
published_date: 2018-06-22
created_at: 2018-06-22 16:34:43.330907
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records: {}
data:
id: date
last_modified: 1529681414530
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
buckets:
natim:
collections:
toto:
data:
id: toto
last_modified: 1496132464691
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records:
e2686bac-c45e-4144-9738-edfeb3d9da6d:
data:
id: e2686bac-c45e-4144-9738-edfeb3d9da6d
last_modified: 1496132479127
permissions: {}
data:
id: natim
last_modified: 1496132446213
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
natim2:
collections:
toto:
data:
id: toto
last_modified: 1496132461211
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records:
ee338fcd-3a19-4a4f-af05-a8b052a23521:
data:
id: ee338fcd-3a19-4a4f-af05-a8b052a23521
last_modified: 1496132482950
permissions: {}
totot:
data:
id: totot
last_modified: 1496132458576
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records: {}
data:
id: natim2
last_modified: 1496132453519
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
date:
collections:
dates:
data:
id: dates
last_modified: 1496132464691
published_date: 2018-06-22
created_at: 2018-06-22 16:34:43.330907
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records: {}
data:
id: date
last_modified: 1529681414530
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
45 changes: 23 additions & 22 deletions tests/dumps/dump-natim-toto-groups.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
natim:
collections:
toto:
data:
id: toto
last_modified: 1496132464691
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records:
e2686bac-c45e-4144-9738-edfeb3d9da6d:
data:
id: e2686bac-c45e-4144-9738-edfeb3d9da6d
last_modified: 1496132479127
permissions: {}
data:
id: natim
last_modified: 1496132446213
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
buckets:
natim:
collections:
toto:
data:
id: toto
last_modified: 1496132464691
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records:
e2686bac-c45e-4144-9738-edfeb3d9da6d:
data:
id: e2686bac-c45e-4144-9738-edfeb3d9da6d
last_modified: 1496132479127
permissions: {}
data:
id: natim
last_modified: 1496132446213
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
43 changes: 22 additions & 21 deletions tests/dumps/dump-natim-toto.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
natim:
collections:
toto:
data:
id: toto
last_modified: 1496132464691
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records:
e2686bac-c45e-4144-9738-edfeb3d9da6d:
data:
id: e2686bac-c45e-4144-9738-edfeb3d9da6d
last_modified: 1496132479127
permissions: {}
data:
id: natim
last_modified: 1496132446213
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
buckets:
natim:
collections:
toto:
data:
id: toto
last_modified: 1496132464691
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records:
e2686bac-c45e-4144-9738-edfeb3d9da6d:
data:
id: e2686bac-c45e-4144-9738-edfeb3d9da6d
last_modified: 1496132479127
permissions: {}
data:
id: natim
last_modified: 1496132446213
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
45 changes: 23 additions & 22 deletions tests/dumps/dump-natim.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
natim:
collections:
toto:
data:
id: toto
last_modified: 1496132464691
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records:
e2686bac-c45e-4144-9738-edfeb3d9da6d:
data:
id: e2686bac-c45e-4144-9738-edfeb3d9da6d
last_modified: 1496132479127
permissions: {}
data:
id: natim
last_modified: 1496132446213
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
buckets:
natim:
collections:
toto:
data:
id: toto
last_modified: 1496132464691
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
records:
e2686bac-c45e-4144-9738-edfeb3d9da6d:
data:
id: e2686bac-c45e-4144-9738-edfeb3d9da6d
last_modified: 1496132479127
permissions: {}
data:
id: natim
last_modified: 1496132446213
groups: {}
permissions:
write:
- basicauth:8e79ddf13abb4e8034f060b6f2975275975e5866727595301e77ba5494b127c4
Loading

0 comments on commit 2208f05

Please sign in to comment.