MCPcopy Create free account
hub / github.com/bitwarden/clients / getCipher

Method getCipher

apps/cli/src/commands/get.command.ts:144–195  ·  view source on GitHub ↗
(id: string, filter?: (c: CipherView) => boolean)

Source from the content-addressed store, hash-verified

142 }
143
144 private async getCipher(id: string, filter?: (c: CipherView) => boolean) {
145 const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
146
147 let decCipher = await this.getCipherView(id, activeUserId);
148 if (decCipher == null) {
149 return Response.notFound();
150 }
151
152 if (Array.isArray(decCipher)) {
153 // Apply restricted ciphers filter
154 decCipher = await this.cliRestrictedItemTypesService.filterRestrictedCiphers(decCipher);
155
156 if (decCipher.length === 0) {
157 return Response.error("Access to this item type is restricted by organizational policy.");
158 }
159
160 if (filter != null) {
161 decCipher = decCipher.filter(filter);
162 }
163
164 if (decCipher.length === 0) {
165 return Response.notFound();
166 }
167
168 if (decCipher.length === 1) {
169 decCipher = decCipher[0];
170 } else {
171 return Response.multipleResults(decCipher.map((c) => c.id));
172 }
173 } else {
174 const isCipherRestricted =
175 await this.cliRestrictedItemTypesService.isCipherRestricted(decCipher);
176 if (isCipherRestricted) {
177 return Response.error("Access to this item type is restricted by organizational policy.");
178 }
179
180 // Apply filter if provided to single cipher
181 if (filter != null && !filter(decCipher)) {
182 return Response.notFound();
183 }
184 }
185
186 await this.eventCollectionService.collect(
187 EventType.Cipher_ClientViewed,
188 decCipher.id,
189 true,
190 decCipher.organizationId,
191 );
192
193 const res = new CipherResponse(decCipher);
194 return Response.success(res);
195 }
196
197 private async getUsername(id: string) {
198 const cipherResponse = await this.getCipher(

Callers 7

runMethod · 0.95
getUsernameMethod · 0.95
getPasswordMethod · 0.95
getUriMethod · 0.95
getTotpMethod · 0.95
getNotesMethod · 0.95
getAttachmentMethod · 0.95

Calls 11

getCipherViewMethod · 0.95
filterFunction · 0.85
notFoundMethod · 0.80
multipleResultsMethod · 0.80
mapMethod · 0.80
collectMethod · 0.80
successMethod · 0.80
errorMethod · 0.65
filterMethod · 0.45
isCipherRestrictedMethod · 0.45

Tested by

no test coverage detected