From dd8dd343438b4b0671d2d18ad97081c76a6eb1bf Mon Sep 17 00:00:00 2001 From: Felipe Morato Date: Wed, 19 Jan 2022 16:12:07 +0200 Subject: [PATCH 001/137] Refactor code occurrences of "bucket" to "container". --- docs/_static/api.yml | 16 +++---- swift_browser_ui/ui/api.py | 20 ++++----- swift_browser_ui/ui/server.py | 18 ++++---- swift_browser_ui_frontend/src/common/api.js | 30 ++++++------- swift_browser_ui_frontend/src/common/conv.js | 6 +-- swift_browser_ui_frontend/src/common/lang.js | 8 ++-- swift_browser_ui_frontend/src/common/store.js | 4 +- .../src/components/ObjectTable.vue | 2 +- .../src/components/ShareRequestsTable.vue | 2 +- .../src/components/SharedOutTable.vue | 2 +- .../src/components/SharedTable.vue | 2 +- .../src/views/AddContainer.vue | 4 +- .../src/views/Containers.vue | 14 +++---- .../src/views/Upload.vue | 4 +- tests/cypress/integration/browser.spec.js | 10 ++--- tests/performance/locustfile.py | 4 +- tests/ui_unit/test_api.py | 42 +++++++++---------- tests/ui_unit/test_server.py | 6 +-- 18 files changed, 95 insertions(+), 99 deletions(-) diff --git a/docs/_static/api.yml b/docs/_static/api.yml index e9b65613d..f7825c2b1 100644 --- a/docs/_static/api.yml +++ b/docs/_static/api.yml @@ -13,7 +13,7 @@ tags: - name: Sharing Account description: Endpoints for sharing request "Database and API for storing / querying Openstack Swift ACL information" - name: Upload/Download - description: Endpoints for uploading and downloading buckets/objects + description: Endpoints for uploading and downloading containers/objects paths: /health: @@ -655,7 +655,7 @@ paths: $ref: '#/components/schemas/ProjectMeta' 403: description: Unauthorized - /api/buckets: + /api/containers: get: tags: - Frontend @@ -671,13 +671,13 @@ paths: description: Unauthorized 404: description: Not Found - /api/bucket/objects: + /api/container/objects: get: tags: - Frontend summary: Get the listing for objects in a given container. parameters: - - name: bucket + - name: container in: query description: The container that is to be queried. schema: @@ -695,7 +695,7 @@ paths: 404: description: Not Found - /api/bucket/meta: + /api/container/meta: get: tags: - Frontend @@ -731,7 +731,7 @@ paths: example: test-container-1 required: true requestBody: - description: Bucket metadata as a key-value object. Updates must include all the metadata for the bucket. Omitted keys are removed by the swift backend. + description: Container metadata as a key-value object. Updates must include all the metadata for the container. Omitted keys are removed by the swift backend. required: true content: application/json: @@ -749,7 +749,7 @@ paths: description: Unauthorized 404: description: Container was not found - /api/bucket/object/meta: + /api/container/object/meta: get: tags: - Frontend @@ -852,7 +852,7 @@ paths: - Frontend summary: Download the object specified in the download link. parameters: - - name: bucket + - name: container in: query description: The container from which to download schema: diff --git a/swift_browser_ui/ui/api.py b/swift_browser_ui/ui/api.py index 687e2203c..77af345c8 100644 --- a/swift_browser_ui/ui/api.py +++ b/swift_browser_ui/ui/api.py @@ -48,9 +48,9 @@ def _unpack( request.app["Log"].error(item["error"]) -async def swift_list_buckets(request: aiohttp.web.Request) -> aiohttp.web.Response: +async def swift_list_containers(request: aiohttp.web.Request) -> aiohttp.web.Response: """ - Return necessary information listing swift buckets in a project. + Return necessary information listing swift containers in a project. The function strips out e.g. the information on a success, since that's not necessary in this case and returns a JSON response containing all the @@ -60,10 +60,10 @@ async def swift_list_buckets(request: aiohttp.web.Request) -> aiohttp.web.Respon try: session = api_check(request) request.app["Log"].info( - "API call for list buckets from " + "API call for list containers from " f"{request.remote}, sess: {session} :: {time.ctime()}" ) - # The maximum amount of buckets / containers is measured in thousands, + # The maximum amount of containers / containers is measured in thousands, # so it's not necessary to think twice about iterating over the whole # response at once serv = request.app["Sessions"][session]["ST_conn"].list() @@ -166,7 +166,7 @@ async def swift_delete_objects(request: aiohttp.web.Request) -> aiohttp.web.Resp async def swift_list_objects(request: aiohttp.web.Request) -> aiohttp.web.Response: """ - List objects in a given bucket or container. + List objects in a given container or container. The function strips out e.g. the information on a success, since that's not necessary in this case and returns a JSON response containing all the @@ -181,7 +181,7 @@ async def swift_list_objects(request: aiohttp.web.Request) -> aiohttp.web.Respon ) serv = request.app["Sessions"][session]["ST_conn"].list( - container=request.query["bucket"] + container=request.query["container"] ) [_unpack(i, obj, request) for i in serv] if not obj: @@ -278,7 +278,7 @@ async def swift_download_object(request: aiohttp.web.Request) -> aiohttp.web.Res host = sess.get_endpoint(service_type="object-store").split("/v1")[0] path_begin = sess.get_endpoint(service_type="object-store").replace(host, "") request.app["Log"].debug(f"Using {host} as host and {path_begin} as path start.") - container = request.query["bucket"] + container = request.query["container"] object_key = request.query["objkey"] lifetime = 60 * 15 # In the path creation, the stats['items'][0][1] is the tenant id from @@ -293,7 +293,7 @@ async def swift_download_object(request: aiohttp.web.Request) -> aiohttp.web.Res ) response.headers["Location"] = dloadurl response.headers["Content-Type"] = list( - serv.stat(request.query["bucket"], [request.query["objkey"]]) + serv.stat(request.query["container"], [request.query["objkey"]]) )[0]["headers"]["content-type"] return response @@ -473,7 +473,7 @@ async def get_object_metadata( raise aiohttp.web.HTTPNotFound() -async def get_metadata_bucket(request: aiohttp.web.Request) -> aiohttp.web.Response: +async def get_metadata_container(request: aiohttp.web.Request) -> aiohttp.web.Response: """Get metadata for a container.""" session = api_check(request) request.app["Log"].info( @@ -503,7 +503,7 @@ async def get_metadata_bucket(request: aiohttp.web.Request) -> aiohttp.web.Respo return aiohttp.web.json_response([ret["container"], ret["headers"]]) -async def update_metadata_bucket(request: aiohttp.web.Request) -> aiohttp.web.Response: +async def update_metadata_container(request: aiohttp.web.Request) -> aiohttp.web.Response: """Update metadata for a container.""" session = api_check(request) request.app["Log"].info( diff --git a/swift_browser_ui/ui/server.py b/swift_browser_ui/ui/server.py index 79e7a2bfc..4de7a442d 100644 --- a/swift_browser_ui/ui/server.py +++ b/swift_browser_ui/ui/server.py @@ -23,7 +23,7 @@ token_rescope, ) from swift_browser_ui.ui.api import ( - swift_list_buckets, + swift_list_containers, swift_list_objects, swift_download_object, swift_download_shared_object, @@ -32,7 +32,7 @@ get_os_user, get_os_active_project, get_metadata_object, - get_metadata_bucket, + get_metadata_container, get_project_metadata, swift_list_shared_objects, get_access_control_metadata, @@ -42,7 +42,7 @@ swift_create_container, swift_delete_container, swift_replicate_container, - update_metadata_bucket, + update_metadata_container, update_metadata_object, get_upload_session, ) @@ -152,19 +152,19 @@ async def servinit() -> aiohttp.web.Application: # Add api routes app.add_routes( [ - aiohttp.web.get("/api/buckets", swift_list_buckets), + aiohttp.web.get("/api/containers", swift_list_containers), aiohttp.web.put("/api/containers/{container}", swift_create_container), aiohttp.web.delete("/api/containers/{container}", swift_delete_container), - aiohttp.web.get("/api/bucket/objects", swift_list_objects), + aiohttp.web.get("/api/container/objects", swift_list_objects), aiohttp.web.get("/api/object/dload", swift_download_object), aiohttp.web.get("/api/shared/objects", swift_list_shared_objects), aiohttp.web.get("/api/username", get_os_user), aiohttp.web.get("/api/projects", os_list_projects), aiohttp.web.get("/api/project/active", get_os_active_project), - aiohttp.web.get("/api/bucket/meta", get_metadata_bucket), - aiohttp.web.post("/api/bucket/meta", update_metadata_bucket), - aiohttp.web.get("/api/bucket/object/meta", get_metadata_object), - aiohttp.web.post("/api/bucket/object/meta", update_metadata_object), + aiohttp.web.get("/api/container/meta", get_metadata_container), + aiohttp.web.post("/api/container/meta", update_metadata_container), + aiohttp.web.get("/api/container/object/meta", get_metadata_object), + aiohttp.web.post("/api/container/object/meta", update_metadata_object), aiohttp.web.get("/api/project/meta", get_project_metadata), aiohttp.web.get("/api/project/acl", get_access_control_metadata), aiohttp.web.post("/api/access/{container}", add_project_container_acl), diff --git a/swift_browser_ui_frontend/src/common/api.js b/swift_browser_ui_frontend/src/common/api.js index 0c8411beb..9b6e99f38 100644 --- a/swift_browser_ui_frontend/src/common/api.js +++ b/swift_browser_ui_frontend/src/common/api.js @@ -64,23 +64,23 @@ export default async function getActiveProject() { return activeProj; } -export async function getBuckets() { - let getBucketsUrl = new URL("/api/buckets", document.location.origin); +export async function getContainers() { + let getContainersUrl = new URL("/api/containers", document.location.origin); // Fetch containers from the API for the user that's currently logged in - let buckets = fetch( - getBucketsUrl, { method: "GET", credentials: "same-origin" }, + let containers = fetch( + getContainersUrl, { method: "GET", credentials: "same-origin" }, ).then( function (resp) { return resp.json(); }, ); - return buckets; + return containers; } -export async function getBucketMeta( +export async function getContainerMeta( container, signal, ){ let url = new URL( - "/api/bucket/meta?container=".concat(encodeURI(container)), + "/api/container/meta?container=".concat(encodeURI(container)), document.location.origin, ); @@ -90,12 +90,12 @@ export async function getBucketMeta( return ret.json(); } -export async function updateBucketMeta( +export async function updateContainerMeta( container, metadata, ){ let url = new URL( - "/api/bucket/meta?container=".concat(encodeURI(container)), + "/api/container/meta?container=".concat(encodeURI(container)), document.location.origin, ); @@ -113,10 +113,8 @@ export async function updateBucketMeta( export async function getObjects(container, signal) { // Fetch objects contained in a container from the API for the user // that's currently logged in. - let objUrl = new URL("/api/bucket/objects", document.location.origin); - // Search parameter named bucket to avoid changing the API after changing - // over from S3 to Swift - objUrl.searchParams.append("bucket", container); + let objUrl = new URL("/api/container/objects", document.location.origin); + objUrl.searchParams.append("container", container); let objects = fetch( objUrl, { method: "GET", credentials: "same-origin", signal }, ).then( @@ -125,7 +123,7 @@ export async function getObjects(container, signal) { function (ret) { for (let i = 0; i < ret.length; i++) { ret[i]["url"] = ( - "/api/object/dload?bucket=" + container + + "/api/object/dload?container=" + container + "&objkey=" + ret[i]["name"] ); } @@ -156,7 +154,7 @@ export async function updateObjectMeta ( objectMeta, ){ let url = new URL( - "/api/bucket/object/meta?container=".concat(encodeURI(container)), + "/api/container/object/meta?container=".concat(encodeURI(container)), document.location.origin, ); @@ -179,8 +177,6 @@ export async function getSharedObjects ( // Fetch objects contained in a container from the API for the user // that's currently logged in. let objUrl = new URL("/api/shared/objects", document.location.origin); - // Search parameter named bucket to avoid changing the API after changing - // over from S3 to Swift objUrl.searchParams.append("storageurl", url); objUrl.searchParams.append("container", container); let objects = fetch( diff --git a/swift_browser_ui_frontend/src/common/conv.js b/swift_browser_ui_frontend/src/common/conv.js index fde03ca2a..606525390 100644 --- a/swift_browser_ui_frontend/src/common/conv.js +++ b/swift_browser_ui_frontend/src/common/conv.js @@ -1,6 +1,6 @@ import { - getBucketMeta, + getContainerMeta, getAccessControlMeta, getObjectsMeta, } from "./api"; @@ -163,7 +163,7 @@ function extractTags(meta) { } export async function getTagsForContainer(containerName, signal) { - let meta = await getBucketMeta(containerName, signal); + let meta = await getContainerMeta(containerName, signal); return extractTags(meta); } @@ -180,7 +180,7 @@ export async function getTagsForObjects( export function makeGetObjectsMetaURL(container, objects) { return new URL( - "/api/bucket/object/meta?container=" + "/api/container/object/meta?container=" .concat(encodeURI(container)) .concat("&object=") .concat(encodeURI(objects.join(","))), diff --git a/swift_browser_ui_frontend/src/common/lang.js b/swift_browser_ui_frontend/src/common/lang.js index 85c2e7293..decf4615c 100644 --- a/swift_browser_ui_frontend/src/common/lang.js +++ b/swift_browser_ui_frontend/src/common/lang.js @@ -263,8 +263,8 @@ let default_translations = { pubkeyLabel: "Public key", addkey: "Add receiver public key", addFiles: "Add files", - bucket: "Bucket", - bucket_msg: "Upload destination bucket", + container: "Bucket", + container_msg: "Upload destination bucket", dropMsg: "Click to add files that will be uploaded.", enup: "Encrypt and Upload", normup: "Upload", @@ -536,8 +536,8 @@ let default_translations = { pubkey: "Vastaanottajien julkiset avaimet", pubkeyLabel: "Julkinen avain", pubkey_msg: "Liitä vastaanottajan julkinen avain", - bucket: "Säiliö", - bucket_msg: "Kohdesäiliö", + container: "Säiliö", + container_msg: "Kohdesäiliö", dropMsg: "Klikkaa lisätäksesi tiedostoja lähetettäväksi.", enup: "Salaa ja lähetä", normup: "Lähetä", diff --git a/swift_browser_ui_frontend/src/common/store.js b/swift_browser_ui_frontend/src/common/store.js index 437c801f8..7c9ee9a04 100644 --- a/swift_browser_ui_frontend/src/common/store.js +++ b/swift_browser_ui_frontend/src/common/store.js @@ -2,7 +2,7 @@ import Vue from "vue"; import Vuex from "vuex"; -import { getBuckets } from "@/common/api"; +import { getContainers } from "@/common/api"; import { getObjects, getSharedObjects, @@ -149,7 +149,7 @@ const store = new Vuex.Store({ updateContainers: async function ({ commit, dispatch }, signal) { commit("loading", true); let containers = []; - await getBuckets().then((ret) => { + await getContainers().then((ret) => { if (ret.status != 200) { commit("loading", false); } diff --git a/swift_browser_ui_frontend/src/components/ObjectTable.vue b/swift_browser_ui_frontend/src/components/ObjectTable.vue index 6062fc8e5..6ba25cef7 100644 --- a/swift_browser_ui_frontend/src/components/ObjectTable.vue +++ b/swift_browser_ui_frontend/src/components/ObjectTable.vue @@ -9,7 +9,7 @@ >