forked from rucio/webui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: add list-did feature with multicall post processing pipeline ruc…
- Loading branch information
Showing
13 changed files
with
224 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { injectable } from "inversify"; | ||
import type { ListDIDsInputPort, ListDIDsOutputPort } from "@/lib/core/port/primary/list-dids-ports"; | ||
import type DIDGatewayOutputPort from "@/lib/core/port/secondary/did-gateway-output-port"; | ||
import { DIDDTO, ListDIDDTO, ListDIDsStreamData } from "../../dto/did-dto"; | ||
import { ListDIDsError, ListDIDsRequest, ListDIDsResponse } from "../../usecase-models/list-dids-usecase-models"; | ||
import { parseDIDString } from "@/lib/common/did-utils"; | ||
import { BaseMultiCallStreamableUseCase, BaseStreamingUseCase } from "@/lib/sdk/usecase"; | ||
import { AuthenticatedRequestModel } from "@/lib/sdk/usecase-models"; | ||
import { ListDIDsViewModel } from "@/lib/infrastructure/data/view-model/list-did"; | ||
import GetDIDsPipelineElement from "./pipeline-element-get-did"; | ||
|
||
@injectable() | ||
class ListDIDsUseCase extends BaseMultiCallStreamableUseCase<ListDIDsRequest, ListDIDsResponse, ListDIDsError, ListDIDDTO, ListDIDsStreamData, DIDDTO, ListDIDsViewModel> implements ListDIDsInputPort { | ||
|
||
constructor( | ||
protected presenter: ListDIDsOutputPort, | ||
private didGateway: DIDGatewayOutputPort, | ||
) { | ||
const getDIDPipelineElement = new GetDIDsPipelineElement(didGateway); | ||
super(presenter, [getDIDPipelineElement]) | ||
this.didGateway = didGateway; | ||
} | ||
|
||
validateRequestModel(requestModel: AuthenticatedRequestModel<ListDIDsRequest>): ListDIDsError | undefined { | ||
let scope: string; | ||
let name: string; | ||
try{ | ||
let didComponents = parseDIDString(requestModel.query); | ||
scope = didComponents.scope; | ||
name = didComponents.name; | ||
} catch (error: any) { | ||
return { | ||
status: 'error', | ||
error: 'Invalid DID Query', | ||
message: (error as Error).message, | ||
} as ListDIDsError | ||
} | ||
} | ||
|
||
async makeGatewayRequest(requestModel: AuthenticatedRequestModel<ListDIDsRequest>): Promise<ListDIDDTO> { | ||
const { scope, name } = parseDIDString(requestModel.query); | ||
const listDIDDTO: ListDIDDTO = await this.didGateway.listDIDs(requestModel.rucioAuthToken, scope, name, requestModel.type); | ||
return listDIDDTO; | ||
} | ||
|
||
handleGatewayError(error: ListDIDDTO): ListDIDsError { | ||
let errorType = 'Unknown Error' | ||
if(error.error === 'Invalid Auth Token') { | ||
errorType = 'Invalid Request' | ||
} | ||
else if(error.error !== 'Unknown Error') { | ||
errorType = 'Invalid DID Query' | ||
} | ||
|
||
return { | ||
error: errorType, | ||
message: `${error.error}: ${error.message}`, | ||
} as ListDIDsError | ||
} | ||
|
||
streamDataToStreamDTO(streamedChunk: ListDIDsStreamData, requestModel: ListDIDsRequest): DIDDTO { | ||
const { scope, name } = parseDIDString(streamedChunk); | ||
return { | ||
name: name, | ||
scope: scope, | ||
did_type: requestModel.type, | ||
} as DIDDTO | ||
} | ||
|
||
processStreamedData(dto: DIDDTO): { data: ListDIDsResponse | ListDIDsError; status: "success" | "error"; } { | ||
const responseModel: ListDIDsResponse = { | ||
status: 'success', | ||
name: dto.name, | ||
scope: dto.scope, | ||
did_type: dto.did_type, | ||
length: 0, | ||
bytes: 0, | ||
} | ||
return { | ||
data: responseModel, | ||
status: 'success', | ||
} | ||
} | ||
|
||
handleStreamError(error: ListDIDsError): void { | ||
this.emit('error', error) | ||
} | ||
|
||
validateFinalResponseModel(responseModel: ListDIDsResponse): { isValid: boolean; errorModel?: ListDIDsError | undefined; } { | ||
return { | ||
isValid: true, | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
|
||
export default ListDIDsUseCase; |
91 changes: 91 additions & 0 deletions
91
src/lib/core/use-case/list-dids/pipeline-element-get-did.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { parseDIDString } from "@/lib/common/did-utils"; | ||
import { BaseStreamingPostProcessingPipelineElement } from "@/lib/sdk/postprocessing-pipeline-elements"; | ||
import { AuthenticatedRequestModel } from "@/lib/sdk/usecase-models"; | ||
import { inject } from "inversify"; | ||
import { DIDDTO } from "../../dto/did-dto"; | ||
import DIDGatewayOutputPort from "../../port/secondary/did-gateway-output-port"; | ||
import { ListDIDsError, ListDIDsRequest, ListDIDsResponse } from "../../usecase-models/list-dids-usecase-models"; | ||
|
||
export default class GetDIDsPipelineElement extends BaseStreamingPostProcessingPipelineElement<ListDIDsRequest, ListDIDsResponse, ListDIDsError, DIDDTO>{ | ||
constructor(private didGateway: DIDGatewayOutputPort) { | ||
super(); | ||
} | ||
async makeGatewayRequest(requestModel: AuthenticatedRequestModel<ListDIDsRequest>, responseModel: ListDIDsResponse): Promise<DIDDTO> { | ||
let scope: string = ''; | ||
let name: string = ''; | ||
try { | ||
const parsedDID = parseDIDString(requestModel.query); | ||
scope = parsedDID.scope; | ||
name = parsedDID.name; | ||
const dto: DIDDTO = await this.didGateway.getDID(requestModel.rucioAuthToken, scope, name); | ||
return dto; | ||
} catch (error: any) { | ||
const errorDTO: DIDDTO = { | ||
status: 'error', | ||
error: 'Invalid Parameters', | ||
message: (error as Error).message, | ||
name: requestModel.query, | ||
scope: requestModel.query, | ||
did_type: requestModel.type, | ||
account: '', | ||
open: false, | ||
monotonic: false, | ||
expired_at: '', | ||
bytes: 0, | ||
length: 0 | ||
} | ||
return errorDTO; | ||
} | ||
} | ||
|
||
handleGatewayError(dto: DIDDTO): ListDIDsError { | ||
let error: 'Unknown Error' | 'Invalid DID Query' | 'Invalid Request' = 'Unknown Error'; | ||
switch(dto.error) { | ||
case 'Invalid Auth Token': | ||
error = 'Invalid Request'; | ||
break; | ||
case 'Data Identifier Not Found': | ||
error = 'Invalid DID Query'; | ||
break; | ||
case 'Invalid Parameters': | ||
error = 'Invalid Request'; | ||
break; | ||
case 'Scope Not Found': | ||
error = 'Invalid DID Query'; | ||
break; | ||
case 'Unknown Error': | ||
error = 'Unknown Error'; | ||
break; | ||
default: | ||
error = 'Unknown Error'; | ||
break; | ||
} | ||
|
||
const errorModel: ListDIDsError = { | ||
status: 'error', | ||
name: dto.name, | ||
error: error, | ||
message: dto.error + ': ' + dto.message + ' for DID ' + dto.scope + ':' + dto.name, | ||
} | ||
return errorModel; | ||
} | ||
|
||
validateDTO(dto: DIDDTO): { status: "success" | "error" | "critical"; data: ListDIDsError | DIDDTO; } { | ||
if(dto.expired_at === '') { | ||
dto.expired_at = 'Never'; | ||
} | ||
|
||
return { | ||
status: 'success', | ||
data: dto | ||
} | ||
} | ||
|
||
|
||
transformResponseModel(responseModel: ListDIDsResponse, dto: DIDDTO): ListDIDsResponse { | ||
responseModel.bytes = dto.bytes; | ||
responseModel.length = dto.length; | ||
return responseModel; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.