refactor: policy card
MODIFY
src/app/components/marketplace-signup-stepper/marketplace-signup-stepper.component.ts
src/app/components/marketplace-signup-stepper/marketplace-signup-stepper.component.ts
@@ -23,7 +23,7 @@ export class MarketplaceSignupStepperComponent implements OnInit {
selectedClients = new Set<IClientSummary>();
agreedTermsAndPrivacy: boolean | undefined;
termsEnabled: boolean;
- infos: ISignUpInfo;
+ newContractDetails: ISignUpInfo;
contract: IContract | undefined;
constructor(
@@ -37,7 +37,7 @@ export class MarketplaceSignupStepperComponent implements OnInit {
private backend: BackendService
) {
this.termsEnabled = this.configService.getTerms().enabled;
- this.infos = this.signUpService.getSignUpInfo();
+ this.newContractDetails = this.signUpService.getSignUpInfo();
}
ngOnInit(): void {
@@ -47,7 +47,7 @@ export class MarketplaceSignupStepperComponent implements OnInit {
private setUpHero() {
this.heroService.setUpHero({
- title: this.infos.apiVersion.api.name,
+ title: this.newContractDetails.apiVersion.api.name,
// subtitle:
// this.infos.plan.name + ' ' + this.translator.instant('COMMON.SIGNUP'),
subtitle: 'Test ' + this.translator.instant('COMMON.SIGNUP'),
@@ -78,7 +78,7 @@ export class MarketplaceSignupStepperComponent implements OnInit {
}
private checkNavigationAllowed(): void {
- if (!this.infos) {
+ if (!this.newContractDetails) {
this.snackbar.showErrorSnackBar(
this.translator.instant('WIZARD.REDIRECT')
);
@@ -90,10 +90,10 @@ export class MarketplaceSignupStepperComponent implements OnInit {
const client: IClientSummary = this.selectedClients.values().next().value;
const contract: INewContract = {
- apiOrgId: this.infos.organizationId,
- apiId: this.infos.apiVersion.api.id,
- apiVersion: this.infos.apiVersion.version,
- planId: this.infos.plan.id,
+ apiOrgId: this.newContractDetails.organizationId,
+ apiId: this.newContractDetails.apiVersion.api.id,
+ apiVersion: this.newContractDetails.apiVersion.version,
+ planId: this.newContractDetails.plan.id,
};
this.backend

MODIFY
src/app/components/my-apps-policies/my-apps-policies.component.html
src/app/components/my-apps-policies/my-apps-policies.component.html
-<p>my-apps-policies works!</p>
+<!--In this version we will not have more than 2 policies-->
+<div class="policies">
+ <app-policy-card></app-policy-card>
+ <app-policy-card></app-policy-card>
+</div>

MODIFY
src/app/components/policy-card/policy-card.component.ts
src/app/components/policy-card/policy-card.component.ts
@@ -14,9 +14,6 @@ export interface PolicyHeaders {
})
export class PolicyCardComponent implements OnInit {
@Input() policy?: IPolicy;
- headers: PolicyHeaders;
- icon: string;
- policyIdentifier: string;
// Default Headers
private rateLimitPolicyHeaders: PolicyHeaders = {
@@ -24,29 +21,111 @@ export class PolicyCardComponent implements OnInit {
headerRemaining: 'X-RateLimit-Remaining',
headerReset: 'X-RateLimit-Reset',
};
+
private transferQuotaPolicyHeaders: PolicyHeaders = {
headerLimit: 'X-TransferQuota-Limit',
headerRemaining: 'X-TransferQuota-Remaining',
headerReset: 'X-TransferQuota-Reset',
};
- constructor() {
- if (this.policy?.definition.id === 'RateLimitingPolicy') {
- this.headers = this.rateLimitPolicyHeaders;
+ headers: PolicyHeaders = this.rateLimitPolicyHeaders;
+ icon: string | undefined;
+ policyIdentifier: string | undefined;
+
+ policyConfig = {
+ limit: '',
+ timeUnit: '',
+ };
+
+ test = {
+ id: 1632404307877124,
+ type: 'Api',
+ organizationId: 'Petstore',
+ entityId: 'Petstore',
+ entityVersion: '1.0',
+ name: 'Transfer Quota Policy',
+ description:
+ 'Consumers are limited to transferring 536870912000 bytes per Client per Minute.',
+ //prettier-ignore
+ configuration:
+ "{\"limit\":314572800,\"direction\":\"upload\",\"granularity\":\"Client\",\"period\":\"Minute\"}",
+ createdBy: 'support.is',
+ createdOn: 1632404307840,
+ modifiedBy: 'support.is',
+ modifiedOn: 1632404307840,
+ definition: {
+ id: 'TransferQuotaPolicy',
+ policyImpl: 'class:io.apiman.gateway.engine.policies.TransferQuotaPolicy',
+ name: 'Transfer Quota Policy',
+ description:
+ 'Provides a way to limit the total number of bytes that can be transferred from (or to) an API.',
+ icon: 'download',
+ templates: [
+ {
+ language: null,
+ template:
+ 'Consumers are limited to transferring ${limit} bytes per ${granularity} per ${period}.',
+ },
+ ],
+ formType: 'Default',
+ deleted: false,
+ },
+ orderIndex: 3,
+ };
+
+ ngOnInit(): void {
+ const config = JSON.parse(this.test.configuration);
+ // const config = JSON.parse(this.policy?.configuration);
+ const timeUnit = config.period;
+ let limit = '';
+
+ const policyId = this.test?.definition.id;
+ // const policyId = this.policy?.definition.id;
+ switch (policyId) {
+ case 'RateLimitingPolicy': {
+ this.checkHeaders(config, this.rateLimitPolicyHeaders);
this.icon = 'tune';
this.policyIdentifier = 'RATE_LIMIT';
- } else {
- this.headers = this.transferQuotaPolicyHeaders;
+ limit = config.limit;
+ break;
+ }
+ case 'TransferQuotaPolicy': {
+ this.checkHeaders(config, this.transferQuotaPolicyHeaders);
this.icon = 'import_export';
this.policyIdentifier = 'QUOTA';
+ limit = this.formatBytes(config.limit);
+ break;
}
}
-
- policyConfig = {
- limit: '300',
- unit: 'MB',
- timeUnit: 'day',
+ this.policyConfig = {
+ limit: limit,
+ timeUnit: timeUnit,
};
+ }
+
+ private checkHeaders(config: any, defaultHeaders: PolicyHeaders) {
+ if (config.hasOwnProperty('headerLimit')) {
+ defaultHeaders.headerLimit = config.headerLimit;
+ }
+ if (config.hasOwnProperty('headerRemaining')) {
+ defaultHeaders.headerLimit = config.headerRemaining;
+ }
+ if (config.hasOwnProperty('headerReset')) {
+ defaultHeaders.headerLimit = config.headerReset;
+ }
+ this.headers = defaultHeaders;
+ }
+
+ private formatBytes(bytes: number, decimals = 0): string {
+ // Thankfully taken from https://stackoverflow.com/a/18650828
+ if (bytes === 0) return '0 Bytes';
+
+ const k = 1024;
+ const dm = decimals < 0 ? 0 : decimals;
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
- ngOnInit(): void {}
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
+
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
+ }
}

MODIFY
src/assets/i18n/de.json
src/assets/i18n/de.json
},
"QUOTA": {
"TITLE": "Quota Policy",
- "DESCRIPTION": "You can transfer a maximum of {{limit}} {{unit}} of data {{timeUnit}}",
+ "DESCRIPTION": "You can transfer a maximum of {{limit}} of data per {{timeUnit}}",
"MORE_INFO": "The following headers in the response contain useful information relating to quota limit,",
"LIMIT": "Quota limit allowance (per time period)",
"REMAINING": "Quota limit allowance remaining",

MODIFY
src/assets/i18n/en.json
src/assets/i18n/en.json
},
"QUOTA": {
"TITLE": "Quota Policy",
- "DESCRIPTION": "You can transfer a maximum of {{limit}} {{unit}} of data {{timeUnit}}",
+ "DESCRIPTION": "You can transfer a maximum of {{limit}} of data per {{timeUnit}}",
"MORE_INFO": "The following headers in the response contain useful information relating to quota limit,",
"LIMIT": "Quota limit allowance (per time period)",
"REMAINING": "Quota limit allowance remaining",

refactor: policy card