mirror of
https://github.com/bitwarden/cli
synced 2025-12-16 16:23:30 +00:00
get org collection
This commit is contained in:
@@ -29,6 +29,8 @@ import { CipherView } from 'jslib/models/view/cipherView';
|
|||||||
import { CollectionView } from 'jslib/models/view/collectionView';
|
import { CollectionView } from 'jslib/models/view/collectionView';
|
||||||
import { FolderView } from 'jslib/models/view/folderView';
|
import { FolderView } from 'jslib/models/view/folderView';
|
||||||
|
|
||||||
|
import { CipherString } from 'jslib/models/domain/cipherString';
|
||||||
|
|
||||||
import { Response } from 'jslib/cli/models/response';
|
import { Response } from 'jslib/cli/models/response';
|
||||||
import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
|
import { MessageResponse } from 'jslib/cli/models/response/messageResponse';
|
||||||
import { StringResponse } from 'jslib/cli/models/response/stringResponse';
|
import { StringResponse } from 'jslib/cli/models/response/stringResponse';
|
||||||
@@ -36,11 +38,14 @@ import { StringResponse } from 'jslib/cli/models/response/stringResponse';
|
|||||||
import { CipherResponse } from '../models/response/cipherResponse';
|
import { CipherResponse } from '../models/response/cipherResponse';
|
||||||
import { CollectionResponse } from '../models/response/collectionResponse';
|
import { CollectionResponse } from '../models/response/collectionResponse';
|
||||||
import { FolderResponse } from '../models/response/folderResponse';
|
import { FolderResponse } from '../models/response/folderResponse';
|
||||||
|
import { OrganizationCollectionResponse } from '../models/response/organizationCollectionResponse';
|
||||||
import { OrganizationResponse } from '../models/response/organizationResponse';
|
import { OrganizationResponse } from '../models/response/organizationResponse';
|
||||||
import { TemplateResponse } from '../models/response/templateResponse';
|
import { TemplateResponse } from '../models/response/templateResponse';
|
||||||
|
|
||||||
import { OrganizationCollectionRequest } from '../models/request/organizationCollectionRequest';
|
import { OrganizationCollectionRequest } from '../models/request/organizationCollectionRequest';
|
||||||
|
|
||||||
|
import { SelectionReadOnly } from '../models/selectionReadOnly';
|
||||||
|
|
||||||
import { CliUtils } from '../utils';
|
import { CliUtils } from '../utils';
|
||||||
|
|
||||||
import { Utils } from 'jslib/misc/utils';
|
import { Utils } from 'jslib/misc/utils';
|
||||||
@@ -76,6 +81,8 @@ export class GetCommand {
|
|||||||
return await this.getFolder(id);
|
return await this.getFolder(id);
|
||||||
case 'collection':
|
case 'collection':
|
||||||
return await this.getCollection(id);
|
return await this.getCollection(id);
|
||||||
|
case 'org-collection':
|
||||||
|
return await this.getOrganizationCollection(id, cmd);
|
||||||
case 'organization':
|
case 'organization':
|
||||||
return await this.getOrganization(id);
|
return await this.getOrganization(id);
|
||||||
case 'template':
|
case 'template':
|
||||||
@@ -326,6 +333,35 @@ export class GetCommand {
|
|||||||
return Response.success(res);
|
return Response.success(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getOrganizationCollection(id: string, cmd: program.Command) {
|
||||||
|
if (cmd.organizationid == null || cmd.organizationid === '') {
|
||||||
|
return Response.badRequest('--organizationid <organizationid> required.');
|
||||||
|
}
|
||||||
|
if (!this.isGuid(id)) {
|
||||||
|
return Response.error('`' + id + '` is not a GUID.');
|
||||||
|
}
|
||||||
|
if (!this.isGuid(cmd.organizationid)) {
|
||||||
|
return Response.error('`' + cmd.organizationid + '` is not a GUID.');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const orgKey = await this.cryptoService.getOrgKey(cmd.organizationid);
|
||||||
|
if (orgKey == null) {
|
||||||
|
throw new Error('No encryption key for this organization.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await this.apiService.getCollectionDetails(cmd.organizationid, id);
|
||||||
|
const decCollection = new CollectionView(response);
|
||||||
|
decCollection.name = await this.cryptoService.decryptToUtf8(
|
||||||
|
new CipherString(response.name), orgKey);
|
||||||
|
const groups = response.groups == null ? null :
|
||||||
|
response.groups.map((g) => new SelectionReadOnly(g.id, g.readOnly));
|
||||||
|
const res = new OrganizationCollectionResponse(decCollection, groups);
|
||||||
|
return Response.success(res);
|
||||||
|
} catch (e) {
|
||||||
|
return Response.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async getOrganization(id: string) {
|
private async getOrganization(id: string) {
|
||||||
let org: Organization = null;
|
let org: Organization = null;
|
||||||
if (this.isGuid(id)) {
|
if (this.isGuid(id)) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export class OrganizationCollectionResponse extends CollectionResponse {
|
|||||||
|
|
||||||
constructor(o: CollectionView, groups: SelectionReadOnly[]) {
|
constructor(o: CollectionView, groups: SelectionReadOnly[]) {
|
||||||
super(o);
|
super(o);
|
||||||
|
this.object = 'org-collection';
|
||||||
this.groups = groups;
|
this.groups = groups;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,6 +264,7 @@ export class Program extends BaseProgram {
|
|||||||
.description('Get an object from the vault.')
|
.description('Get an object from the vault.')
|
||||||
.option('--itemid <itemid>', 'Attachment\'s item id.')
|
.option('--itemid <itemid>', 'Attachment\'s item id.')
|
||||||
.option('--output <output>', 'Output directory or filename for attachment.')
|
.option('--output <output>', 'Output directory or filename for attachment.')
|
||||||
|
.option('--organizationid <organizationid>', 'Organization id for an organization object.')
|
||||||
.on('--help', () => {
|
.on('--help', () => {
|
||||||
writeLn('\n Objects:');
|
writeLn('\n Objects:');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
|
|||||||
Reference in New Issue
Block a user