16115: Adds expiration date param to sharing url service method.
[arvados-workbench2.git] / src / services / api-client-authorization-service / api-client-authorization-service.ts
index 7c985dbba80c00bde82c697c5728409e97e682ae..dbda0a42c79951de4431f796e1b73cc7a612a75c 100644 (file)
@@ -14,17 +14,20 @@ export class ApiClientAuthorizationService extends CommonService<ApiClientAuthor
         super(serverApi, "api_client_authorizations", actions);
     }
 
-    createCollectionSharingToken(uuid: string): Promise<ApiClientAuthorization> {
+    createCollectionSharingToken(uuid: string, expDate: Date | undefined): Promise<ApiClientAuthorization> {
         if (extractUuidObjectType(uuid) !== ResourceObjectType.COLLECTION) {
             throw new Error(`UUID ${uuid} is not a collection`);
         }
-        return this.create({
+        const data = {
             scopes: [
                 `GET /arvados/v1/collections/${uuid}`,
                 `GET /arvados/v1/collections/${uuid}/`,
                 `GET /arvados/v1/keep_services/accessible`,
             ]
-        });
+        }
+        return expDate !== undefined
+            ? this.create({...data, expiresAt: expDate.toUTCString()})
+            : this.create(data);
     }
 
     listCollectionSharingTokens(uuid: string): Promise<ListResults<ApiClientAuthorization>> {