Skip to content

Commit

Permalink
handle service accounts in rule creation
Browse files Browse the repository at this point in the history
  • Loading branch information
maany committed Dec 8, 2023
1 parent 00c43b3 commit 03f6a0e
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 81 deletions.
38 changes: 38 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@builder.io/partytown": "^0.7.6",
"@next/font": "13.1.6",
"@preact/signals": "^1.2.2",
"@primer/css": "^20.8.2",
"@sinclair/typebox": "^0.28.14",
"@tanstack/react-query": "^4.28.0",
Expand Down
77 changes: 34 additions & 43 deletions src/component-library/Pages/Rule/SummaryPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { RuleSummaryViewModel } from "@/lib/infrastructure/data/view-model/rule"
import { RSEAccountUsageLimitViewModel } from "@/lib/infrastructure/data/view-model/rse"
import { BasicStatusTag } from "@/component-library/Tags/BasicStatusTag"
import { ListDIDsViewModel } from "@/lib/infrastructure/data/view-model/list-did"
import { generateDerivedDIDName, generateNewScope } from "@/lib/core/utils/did-utils"
import { DID } from "@/lib/core/entity/rucio"

var format = require("date-format")

Expand Down Expand Up @@ -109,7 +111,7 @@ export const SummaryPage = (
const badges: TBadge[] = []
if(showQuotaWarningBadge) {
badges.push({
title: 'Needs Approval',
title: 'Quota',
type: 'error',
})
}
Expand All @@ -121,51 +123,40 @@ export const SummaryPage = (
}

const getDIDTableContent = () => {
return props.data.DIDViewModels.map((did: ListDIDsViewModel, index) => {
const showOpenBadge = did.open
const badges: TBadge[] = []
if(showOpenBadge) {
badges.push({
title: 'Open',
type: 'warning',
})
}
return {
title: `${did.scope}:${did.name}`,
badges: badges
}
if(!sampleFiles) {
return props.data.DIDViewModels.map((did: ListDIDsViewModel, index) => {
const showOpenBadge = did.open
const badges: TBadge[] = []
if(showOpenBadge) {
badges.push({
title: 'Open',
type: 'warning',
})
}
return {
title: `${did.scope}:${did.name}`,
badges: badges
}
})
}
const accountType = props.data.accountInfo.accountType
const newScope = generateNewScope("account_missing", accountType)
const tableData: {title: string, badges: TBadge[]}[] = []
props.data.DIDViewModels.forEach((did: ListDIDsViewModel, index) => {
const derivedDID: DID =generateDerivedDIDName(newScope, did)
tableData.push({
title: `${derivedDID.scope}:${derivedDID.name}`,
badges: [
{
title: 'Derived',
type: 'info',
}
]
})
})
return tableData
}

const getSummaryMessages = (copies: number, selected_dids: ListDIDsViewModel[], rse_data: RSEAccountUsageLimitViewModel[], approval: boolean, nbfiles: number, open: boolean, lifetime: number) => {
let did_summary_text = "";
let rse_summary_text = "";
let lifetime_summary_text = "";

if (nbfiles != null) {
did_summary_text = `This will ${approval ? '<b>ask for approval</b>' : ''} to create a rule for the following sample dataset(s) with ${nbfiles} file(s):`;
} else if (copies == 1 && selected_dids.length == 1 && rse_data.length == 1) {
did_summary_text = `This request will ${approval ? '<b>ask for approval</b>' : ''} to create a rule for the following DID:`;
rse_summary_text = "The rule will replicate to the following RSE:";
} else {
did_summary_text = `This request will ${approval ? '<b>ask for approval</b>' : ''} create rules for the following DIDs:`;
rse_summary_text = "The rules will replicate to one of the following RSEs:";
}

if (open) {
did_summary_text += '</br>The DIDs in bold are still open. Everything that will be added to them after you created the rule will also be transferred to the selected RSE.';
}

if (lifetime == 1) {
lifetime_summary_text = "The lifetime will be 1 day. If this is ok you can submit the rule request. If not you can go back and change it.";
} else if (lifetime == 0) {
lifetime_summary_text = "The lifetime will be infinite. If this is ok you can submit the rule request. If not you can go back and change it.";
} else {
lifetime_summary_text = `The lifetime will be ${lifetime} days. If this is ok you can submit the rule request. If not you can go back and change it.`;
}

return { did_summary_text, rse_summary_text, lifetime_summary_text };
}
const getMessages = () => {
const messages = []
if(sampleFiles && sampleFiles > 0) {
Expand Down
72 changes: 35 additions & 37 deletions src/lib/core/use-case/create-rule-summary-usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,40 @@ export default class CreateRuleSummayUseCase extends BaseUseCase<AuthenticatedRe
validateRequestModel(requestModel: AuthenticatedRequestModel<CreateRuleSummaryRequest>): BaseErrorResponseModel | undefined {
return undefined;
}
execute(requestModel: AuthenticatedRequestModel<CreateRuleSummaryRequest>): Promise<void> {
throw new Error("Method not implemented.");
}
// async execute(requestModel: AuthenticatedRequestModel<CreateRuleSummaryRequest>): Promise<void> {
// const account = requestModel.account;
// const rucioAuthToken = requestModel.rucioAuthToken;
// // DID Summary Table
// const didSummaryTable: TDIDSummaryRow[] = [];
// if(requestModel.withSamples) {
// const accountInfoDTO: AccountInfoDTO = await this.accountGateway.getAccountInfo(account, rucioAuthToken);
// const accountType: AccountType = accountInfoDTO.accountType;
// const newScope: string = generateNewScope(account, accountType);
// requestModel.selectedDIDs.forEach((did: DID) => {
// const derivedDID: DID = generateDerivedDIDName(newScope, did);
// const didSummaryRow = createDIDSummaryRow(derivedDID as DIDLong, requestModel.copies)
// didSummaryTable.push(didSummaryRow);
// });
// } else {
// requestModel.selectedDIDs.forEach(async (did: DID) => {
// const didDTO: DIDExtendedDTO = await this.didGateway.getDID(
// requestModel.rucioAuthToken,
// did.scope,
// did.name,
// DIDType.FILE
// )
// if(didDTO.status === 'success') {
// const didSummaryRow: TDIDSummaryRow = createDIDSummaryRow(
// didDTO,
// requestModel.copies,
// );
// didSummaryTable.push(didSummaryRow);
// } else {
// // TODO: could not get DID info, handle error?
// }
// })
// }

async execute(requestModel: AuthenticatedRequestModel<CreateRuleSummaryRequest>): Promise<void> {
const account = requestModel.account;
const rucioAuthToken = requestModel.rucioAuthToken;
// DID Summary Table
const didSummaryTable: TDIDSummaryRow[] = [];
if(requestModel.withSamples) {
const accountInfoDTO: AccountInfoDTO = await this.accountGateway.getAccountInfo(account, rucioAuthToken);
const accountType: AccountType = accountInfoDTO.accountType;
const newScope: string = generateNewScope(account, accountType);
requestModel.selectedDIDs.forEach((did: DID) => {
const derivedDID: DID = generateDerivedDIDName(newScope, did);
const didSummaryRow = createDIDSummaryRow(derivedDID as DIDLong, requestModel.copies)
didSummaryTable.push(didSummaryRow);
});
} else {
requestModel.selectedDIDs.forEach(async (did: DID) => {
const didDTO: DIDExtendedDTO = await this.didGateway.getDID(
requestModel.rucioAuthToken,
did.scope,
did.name,
DIDType.FILE
)
if(didDTO.status === 'success') {
const didSummaryRow: TDIDSummaryRow = createDIDSummaryRow(
didDTO,
requestModel.copies,
);
didSummaryTable.push(didSummaryRow);
} else {
// TODO: could not get DID info, handle error?
}
})
}

// // RSE Summary Table
// let needsApproval = false;
Expand Down Expand Up @@ -109,5 +107,5 @@ export default class CreateRuleSummayUseCase extends BaseUseCase<AuthenticatedRe

// }

// }
}
}
3 changes: 2 additions & 1 deletion src/lib/core/utils/did-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const generateNewScope = (account: string, accountType: AccountType): str
}else if(accountType === AccountType.GROUP) {
return `group.${account}`;
} else {
throw new Error(`Invalid account type for rule creation: ${accountType}`);
// TODO: Handle Service Account like root
return `user.${account}`;
}
}

Expand Down

0 comments on commit 03f6a0e

Please sign in to comment.