Skip to content

Commit

Permalink
fix: Swagger UI fixes and other small tech debts [DEV-3121] (#339)
Browse files Browse the repository at this point in the history
* Fix for balance checking

* Small fixes and tech debt

* Makes linter happy

* Add new line

* another attempt to fix linter
  • Loading branch information
Andrew Nikitin committed Aug 14, 2023
1 parent 87c1670 commit d7b3daa
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 167 deletions.
214 changes: 107 additions & 107 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class App {
app.post(
'/credential-status/publish',
RevocationController.commonValidator,
new RevocationController().createStatusList
new RevocationController().publishStatusList
);
app.post(
'/credential-status/check',
Expand Down
22 changes: 10 additions & 12 deletions src/controllers/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,16 @@ export class AccountController {
// 3. Check the token balance for Testnet account
if (customer.address && process.env.FAUCET_ENABLED === 'true') {
const balances = await checkBalance(customer.address, process.env.TESTNET_RPC_URL);
if (balances.length === 0) {
const balance = balances[0];
if (!balance || +balance.amount < process.env.TESTNET_MINIMUM_BALANCE) {
// 3.1 If it's less then required for DID creation - assign new portion from testnet-faucet
const resp = await FaucetHelper.delegateTokens(customer.address);
if (resp.status !== StatusCodes.OK) {
return response.status(StatusCodes.BAD_GATEWAY).json({
error: resp.error,
});
}
}
}
const balance = balances[0];
if (!balance || +balance.amount < process.env.TESTNET_MINIMUM_BALANCE) {
// 3.1 If it's less then required for DID creation - assign new portion from testnet-faucet
const resp = await FaucetHelper.delegateTokens(customer.address);
if (resp.status !== StatusCodes.OK) {
return response.status(StatusCodes.BAD_GATEWAY).json({
error: resp.error,
});
}
}
}
return response.status(StatusCodes.OK).json({});
}
Expand Down
7 changes: 7 additions & 0 deletions src/controllers/revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,13 @@ export class RevocationController {
* - revoke
* - suspend
* - reinstate
* - in: query
* name: publish
* description: Publish the status list to the DID network. The default is `false`, which means the status list is not published to the DID network.
* required: true
* schema:
* type: boolean
* default: false
* - in: query
* name: encrypted
* description: Define whether the status list is encrypted. The default is `false`, which means the DID-Linked Resource can be fetched and parsed publicly. Encrypted status lists can only be fetched if the payment conditions are satisfied. When publishing a new version, this should match the original property.
Expand Down
2 changes: 2 additions & 0 deletions src/middleware/auth/base-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export abstract class AbstractAuthHandler implements IAuthResourceHandler {
public async commonPermissionCheck(request: Request): Promise<IAuthResponse> {
// Reset all variables
this.reset();
// setting up namespace. It should be testnet or mainnet
this.namespace = AbstractAuthHandler.getNamespaceFromRequest(request)
// Firstly - try to find the rule for the request
const rule = this.findRule(request.path, request.method, this.getNamespace());

Expand Down
2 changes: 1 addition & 1 deletion src/middleware/auth/did-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class DidAuthHandler extends AbstractAuthHandler {
}

public async handle(request: Request, response: Response): Promise<IAuthResponse> {
if (!request.path.includes('/did')) {
if (!request.path.includes('/did/')) {
return super.handle(request, response);
}
return this.commonPermissionCheck(request);
Expand Down
2 changes: 1 addition & 1 deletion src/middleware/auth/presentation-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class PresentationAuthHandler extends AbstractAuthHandler {
this.registerRoute('/presentation/verify', 'POST', '', { allowUnauthorized: true, skipNamespace: true });
}
public async handle(request: Request, response: Response): Promise<IAuthResponse> {
if (!request.path.includes('/presentation')) {
if (!request.path.includes('/presentation/')) {
return super.handle(request, response);
}
return this.commonPermissionCheck(request);
Expand Down
6 changes: 3 additions & 3 deletions src/middleware/auth/resource-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { IAuthResponse } from '../../types/authentication.js';
export class ResourceAuthHandler extends AbstractAuthHandler {
constructor() {
super();
this.registerRoute('/resource/create', 'POST', 'create:resource:testnet');
this.registerRoute('/resource/create', 'POST', 'create:resource:mainnet');
this.registerRoute('/resource/create/(.*)', 'POST', 'create:resource:testnet');
this.registerRoute('/resource/create/(.*)', 'POST', 'create:resource:mainnet');
}
public async handle(request: Request, response: Response): Promise<IAuthResponse> {
if (!request.path.includes('/resource')) {
if (!request.path.includes('/resource/')) {
return super.handle(request, response);
}
return this.commonPermissionCheck(request);
Expand Down
47 changes: 12 additions & 35 deletions src/static/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,16 @@
]
}
},
{
"in": "query",
"name": "publish",
"description": "Publish the status list to the DID network. The default is `false`, which means the status list is not published to the DID network.",
"required": true,
"schema": {
"type": "boolean",
"default": false
}
},
{
"in": "query",
"name": "encrypted",
Expand Down Expand Up @@ -1174,39 +1184,6 @@
}
}
}
},
"host": {
"0": "c",
"1": "r",
"2": "e",
"3": "d",
"4": "e",
"5": "n",
"6": "t",
"7": "i",
"8": "a",
"9": "l",
"10": "-",
"11": "s",
"12": "e",
"13": "r",
"14": "v",
"15": "i",
"16": "c",
"17": "e",
"18": ".",
"19": "c",
"20": "h",
"21": "e",
"22": "q",
"23": "d",
"24": ".",
"25": "n",
"26": "e",
"27": "t"
},
"schemes": {
"0": "https"
}
},
"components": {
Expand Down Expand Up @@ -1765,8 +1742,8 @@
],
"example": {
"did": "did:cheqd:testnet:7c2b990c-3d05-4ebf-91af-f4f4d0091d2e",
"name": "cheqd-employee-credentials",
"version": "2023",
"statusListName": "cheqd-employee-credentials",
"statusListVersion": "2023",
"data": "H4sIAAAAAAAAA-3BAQ0AAADCoPdPbQ8HFAAAAAAAAAAAAAAAAAAAAADwaDhDr_xcRAAA",
"encoding": "base64url"
}
Expand Down
7 changes: 2 additions & 5 deletions src/types/swagger-types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/**
* @openapi
*
* host: credential-service.cheqd.net
* schemes:
* - https
* components:
* schemas:
* CredentialRequest:
Expand Down Expand Up @@ -384,8 +381,8 @@
* type: string
* example:
* did: did:cheqd:testnet:7c2b990c-3d05-4ebf-91af-f4f4d0091d2e
* name: cheqd-employee-credentials
* version: '2023'
* statusListName: cheqd-employee-credentials
* statusListVersion: '2023'
* data: H4sIAAAAAAAAA-3BAQ0AAADCoPdPbQ8HFAAAAAAAAAAAAAAAAAAAAADwaDhDr_xcRAAA
* encoding: base64url
* CredentialStatusUpdateRequest:
Expand Down

0 comments on commit d7b3daa

Please sign in to comment.