Skip to content

Commit

Permalink
prepare endpoints for content type parameter (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
soson authored Dec 1, 2021
1 parent 6259925 commit 91a7249
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 23 deletions.
61 changes: 46 additions & 15 deletions packages/frinx-dashboard/src/api/unistore/unistore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,23 @@ type Pagination = {
limit: number;
};

type ContentType = 'config' | 'nonconfig';

function getContentParameter(contentType?: ContentType): string {
return contentType ? `content=${contentType}` : 'content=config';
}

export async function getVpnServices(
pagination: Pagination | null,
serviceFilter: ServiceFilter | null,
contentType?: ContentType,
): Promise<VpnServicesOutput> {
try {
const paginationParams = pagination ? `&offset=${pagination.offset}&limit=${pagination.limit}` : '';
const filterParams = serviceFilter ? getServiceFilterParams(serviceFilter) : '';
const content = getContentParameter(contentType);
const json = await sendGetRequest(
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/vpn-services/vpn-service?${paginationParams}${filterParams}`,
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/vpn-services/vpn-service?${content}${paginationParams}${filterParams}`,
);
const data = decodeVpnServicesOutput(json);
return data;
Expand Down Expand Up @@ -103,12 +111,14 @@ export async function createVpnService(vpnService: VpnService): Promise<void> {
export async function getVpnSites(
pagination: Pagination | null,
siteFilter: SiteFilter | null,
contentType?: ContentType,
): Promise<VpnSitesOutput> {
try {
const paginationParams = pagination ? `&offset=${pagination.offset}&limit=${pagination.limit}` : '';
const filterParams = siteFilter ? getSiteFilterParams(siteFilter) : '';
const content = getContentParameter(contentType);
const json = await sendGetRequest(
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site?content=config${paginationParams}${filterParams}`,
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site?${content}${paginationParams}${filterParams}`,
);
const data = decodeVpnSitesOutput(json);
return data;
Expand Down Expand Up @@ -146,12 +156,14 @@ export async function getValidProviderIdentifiers(): Promise<ValidProviderIdenti
export async function getVpnBearers(
pagination: Pagination | null,
vpnBearerFilter: VpnBearerFilter | null,
contentType?: ContentType,
): Promise<VpnBearerOutput> {
try {
const paginationParams = pagination ? `&offset=${pagination.offset}&limit=${pagination.limit}` : '';
const filterParams = vpnBearerFilter ? getVpnBearerFilterParams(vpnBearerFilter) : '';
const content = getContentParameter(contentType);
const json = await sendGetRequest(
`/data/network-topology:network-topology/topology=unistore/node=bearer/frinx-uniconfig-topology:configuration/gamma-bearer-svc:bearer-svc/vpn-bearers/vpn-bearer?content=config${paginationParams}${filterParams}`,
`/data/network-topology:network-topology/topology=unistore/node=bearer/frinx-uniconfig-topology:configuration/gamma-bearer-svc:bearer-svc/vpn-bearers/vpn-bearer?${content}${paginationParams}${filterParams}`,
);
const data = decodeVpnBearerOutput(json);

Expand Down Expand Up @@ -281,11 +293,15 @@ export async function getBearerValidProviderIdentifiers(): Promise<ValidProvider
}
}

export async function getVpnServiceCount(serviceFilter: ServiceFilter | null): Promise<number> {
export async function getVpnServiceCount(
serviceFilter: ServiceFilter | null,
contentType?: ContentType,
): Promise<number> {
try {
const filterParams = serviceFilter ? getServiceFilterParams(serviceFilter) : '';
const content = getContentParameter(contentType);
const data = await sendGetRequest(
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/vpn-services/vpn-service?content=config&fetch=count${filterParams}`,
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/vpn-services/vpn-service?${content}&fetch=count${filterParams}`,
);
if (!isNumber(data)) {
throw new Error('not a number');
Expand All @@ -298,11 +314,12 @@ export async function getVpnServiceCount(serviceFilter: ServiceFilter | null): P
}
}

export async function getVpnSiteCount(siteFilter: SiteFilter | null): Promise<number> {
export async function getVpnSiteCount(siteFilter: SiteFilter | null, contentType?: ContentType): Promise<number> {
try {
const filterParams = siteFilter ? getSiteFilterParams(siteFilter) : '';
const content = getContentParameter(contentType);
const data = await sendGetRequest(
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site?content=config&fetch=count${filterParams}`,
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site?${content}&fetch=count${filterParams}`,
);
if (!isNumber(data)) {
throw new Error('not a number');
Expand All @@ -315,11 +332,15 @@ export async function getVpnSiteCount(siteFilter: SiteFilter | null): Promise<nu
}
}

export async function getVpnBearerCount(vpnBearerFilter: VpnBearerFilter | null): Promise<number> {
export async function getVpnBearerCount(
vpnBearerFilter: VpnBearerFilter | null,
contentType?: ContentType,
): Promise<number> {
try {
const filterParams = vpnBearerFilter ? getVpnBearerFilterParams(vpnBearerFilter) : '';
const content = getContentParameter(contentType);
const data = await sendGetRequest(
`/data/network-topology:network-topology/topology=unistore/node=bearer/frinx-uniconfig-topology:configuration/gamma-bearer-svc:bearer-svc/vpn-bearers/vpn-bearer?content=config&fetch=count${filterParams}`,
`/data/network-topology:network-topology/topology=unistore/node=bearer/frinx-uniconfig-topology:configuration/gamma-bearer-svc:bearer-svc/vpn-bearers/vpn-bearer?${content}&fetch=count${filterParams}`,
);
if (!isNumber(data)) {
throw new Error('not a number');
Expand All @@ -332,11 +353,16 @@ export async function getVpnBearerCount(vpnBearerFilter: VpnBearerFilter | null)
}
}

export async function getLocations(siteId: string, pagination: Pagination | null): Promise<LocationsOutput> {
export async function getLocations(
siteId: string,
pagination: Pagination | null,
contentType?: ContentType,
): Promise<LocationsOutput> {
try {
const paginationParams = pagination ? `&offset=${pagination.offset}&limit=${pagination.limit}` : '';
const content = getContentParameter(contentType);
const json = await sendGetRequest(
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site=${siteId}/locations/location?content=config${paginationParams}`,
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site=${siteId}/locations/location?${content}${paginationParams}`,
);
const data = decodeLocationsOutput(json);
return data;
Expand All @@ -348,10 +374,11 @@ export async function getLocations(siteId: string, pagination: Pagination | null
}
}

export async function getLocationsCount(siteId: string): Promise<number> {
export async function getLocationsCount(siteId: string, contentType?: ContentType): Promise<number> {
try {
const content = getContentParameter(contentType);
const data = await sendGetRequest(
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site=${siteId}/locations/location?content=config&fetch=count`,
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site=${siteId}/locations/location?${content}&fetch=count`,
);
if (!isNumber(data)) {
throw new Error('not a number');
Expand All @@ -368,12 +395,14 @@ export async function getSiteNetworkAccesses(
siteId: string,
pagination: Pagination | null,
siteNetworkAccessFilter: SiteNetworkAccessFilter | null,
contentType?: ContentType,
): Promise<SiteNetworkAccessOutput> {
try {
const paginationParams = pagination ? `&offset=${pagination.offset}&limit=${pagination.limit}` : '';
const filterParams = siteNetworkAccessFilter ? getSiteNetworkAccessFilterParams(siteNetworkAccessFilter) : '';
const content = getContentParameter(contentType);
const json = await sendGetRequest(
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site=${siteId}/site-network-accesses/site-network-access?content=config${paginationParams}${filterParams}`,
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site=${siteId}/site-network-accesses/site-network-access?${content}${paginationParams}${filterParams}`,
);
const data = decodeSiteNetworkAccessOutput(json);
return data;
Expand All @@ -388,11 +417,13 @@ export async function getSiteNetworkAccesses(
export async function getSiteNetworkAccessesCount(
siteId: string,
siteNetworkAccessFilter: SiteNetworkAccessFilter | null,
contentType?: ContentType,
): Promise<number> {
try {
const filterParams = siteNetworkAccessFilter ? getSiteNetworkAccessFilterParams(siteNetworkAccessFilter) : '';
const content = getContentParameter(contentType);
const data = await sendGetRequest(
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site=${siteId}/site-network-accesses/site-network-access?content=config&fetch=count${filterParams}`,
`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites/site=${siteId}/site-network-accesses/site-network-access?${content}&fetch=count${filterParams}`,
);
if (!isNumber(data)) {
throw new Error('not a number');
Expand Down
32 changes: 24 additions & 8 deletions packages/frinx-gamma/src/unistore-callback-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,32 @@ type Pagination = {
limit: number;
};

type ContentType = 'config' | 'nonconfig';

export type UnistoreCallbacks = {
getVpnServices: (pagination: Pagination | null, filters: ServiceFilters | null) => Promise<VpnServicesOutput>;
getVpnServices: (
pagination: Pagination | null,
filters: ServiceFilters | null,
contentType?: ContentType,
) => Promise<VpnServicesOutput>;
editVpnServices: (body: VpnService) => Promise<unknown>;
deleteVpnService: (id: string) => Promise<unknown>;
createVpnService: (body: VpnService) => Promise<void>;
getVpnSites: (pagination: Pagination | null, filters: SiteFilters | null) => Promise<VpnSitesOutput>;
getVpnSites: (
pagination: Pagination | null,
filters: SiteFilters | null,
contentType?: ContentType,
) => Promise<VpnSitesOutput>;
createVpnSite: (body: VpnSite) => Promise<void>;
editVpnSite: (body: VpnSite) => Promise<void>;
deleteVpnSite: (id: string) => Promise<void>;
getValidProviderIdentifiers: () => Promise<ValidProviderIdentifiersOutput>;
getBearerValidProviderIdentifiers: () => Promise<ValidProviderIdentifiersOutput>;
getVpnBearers: (pagination: Pagination | null, filters: VpnBearerFilters | null) => Promise<VpnBearerOutput>;
getVpnBearers: (
pagination: Pagination | null,
filters: VpnBearerFilters | null,
contentType?: ContentType,
) => Promise<VpnBearerOutput>;
createVpnBearer: (bearer: VpnBearer) => Promise<void>;
editVpnBearer: (bearer: VpnBearer) => Promise<void>;
deleteVpnBearer: (id: string) => Promise<void>;
Expand All @@ -52,19 +66,21 @@ export type UnistoreCallbacks = {
createVpnCarrier: (carrier: VpnCarrier) => Promise<void>;
editVpnCarrier: (carrier: VpnCarrier) => Promise<void>;
deleteVpnCarrier: (carrierName: string) => Promise<void>;
getVpnServiceCount: (filters: ServiceFilters | null) => Promise<number>;
getVpnSiteCount: (filters: SiteFilters | null) => Promise<number>;
getVpnBearerCount: (filters: VpnBearerFilters | null) => Promise<number>;
getLocations: (siteId: string, pagination: Pagination | null) => Promise<LocationsOutput>;
getLocationsCount: (siteId: string) => Promise<number>;
getVpnServiceCount: (filters: ServiceFilters | null, contentType?: ContentType) => Promise<number>;
getVpnSiteCount: (filters: SiteFilters | null, contentType?: ContentType) => Promise<number>;
getVpnBearerCount: (filters: VpnBearerFilters | null, contentType?: ContentType) => Promise<number>;
getLocations: (siteId: string, pagination: Pagination | null, contentType?: ContentType) => Promise<LocationsOutput>;
getLocationsCount: (siteId: string, contentType?: ContentType) => Promise<number>;
getSiteNetworkAccesses: (
siteId: string,
pagination: Pagination | null,
siteNetworkAccessFilter: SiteNetworkAccessFilters | null,
contentType?: ContentType,
) => Promise<SiteNetworkAccessOutput>;
getSiteNetworkAccessesCount: (
siteId: string,
siteNetworkAccessFilter: SiteNetworkAccessFilters | null,
contentType?: ContentType,
) => Promise<number>;
getTransactionCookie: () => Promise<string>;
};
Expand Down

0 comments on commit 91a7249

Please sign in to comment.