Skip to content

Commit

Permalink
send only non empty routing protocols (#230)
Browse files Browse the repository at this point in the history
* send only non empty routing protocols

* get only sites in config state
  • Loading branch information
soson authored Oct 21, 2021
1 parent b1c3fce commit d66e7c0
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 26 deletions.
15 changes: 9 additions & 6 deletions packages/frinx-dashboard/src/api/unistore/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function apiRoutingProtocolToClientRoutingProtocol(routingProtocol: Routi
bgp: bgpProtocol
? {
addressFamily: 'ipv4',
autonomousSystem: bgpProtocol['autonomous-system'],
autonomousSystem: String(bgpProtocol['autonomous-system']),
bgpProfile: bgpProtocol['bgp-profiles']['bgp-profile'][0].profile,
}
: undefined,
Expand All @@ -151,9 +151,12 @@ export function apiSiteNetworkAccessToClientSiteNetworkAccess(
const apiQosProfiles = access.service.qos['qos-profile']['qos-profile'];
const [clientQosProfile] = apiQosProfiles.length ? apiQosProfiles.map((p) => p.profile) : [''];
const vpnAttachment = access['vpn-attachment'] ? access['vpn-attachment']['vpn-id'] : null;
const routingProtocols = access['routing-protocols']['routing-protocol'].map((p) => {
return apiRoutingProtocolToClientRoutingProtocol(p);
});
const routingProtocols =
access['routing-protocols'] && access['routing-protocols']['routing-protocol']
? access['routing-protocols']['routing-protocol'].map((p) => {
return apiRoutingProtocolToClientRoutingProtocol(p);
})
: [];
return {
siteNetworkAccessId: access['site-network-access-id'],
siteNetworkAccessType: access['site-network-access-type'] as SiteNetworkAccessType,
Expand Down Expand Up @@ -260,7 +263,7 @@ function isValidProtocolPredicate(routingProtocol: RoutingProtocol): boolean {
if (!routingProtocol.bgp) {
return false;
}
return !(!routingProtocol.bgp.bgpProfile || !routingProtocol.bgp.autonomousSystem);
return routingProtocol.bgp.bgpProfile !== null && routingProtocol.bgp.autonomousSystem.length > 0;
}

return false;
Expand All @@ -282,7 +285,7 @@ function clientRoutingProtocolsToApiRoutingProtocols(routingProtocols: RoutingPr
'bgp-profile': [{ profile: p.bgp.bgpProfile || '' }] as [{ profile: string }],
},
'address-family': ['ipv4'] as ['ipv4'],
'autonomous-system': p.bgp.autonomousSystem,
'autonomous-system': Number(p.bgp.autonomousSystem),
};
}
if (p.static) {
Expand Down
6 changes: 3 additions & 3 deletions packages/frinx-dashboard/src/api/unistore/network-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export function decodeRoutingProtocolItemOutput(value: unknown): RoutingProtocol
}

const RoutingProtocolsValidator = t.type({
'routing-protocol': t.array(RoutingProtocolItemValidator),
'routing-protocol': optional(t.array(RoutingProtocolItemValidator)),
});

export type RoutingProtocolsOutput = t.TypeOf<typeof RoutingProtocolsValidator>;
Expand Down Expand Up @@ -291,7 +291,7 @@ const SiteNetworkAccessValidator = t.type({
}),
}),
}),
'routing-protocols': RoutingProtocolsValidator,
'routing-protocols': optional(RoutingProtocolsValidator),
}),
),
});
Expand Down Expand Up @@ -738,7 +738,7 @@ export type StaticRoutingType = {
};
export type BgpRoutingType = {
addressFamily: 'ipv4';
autonomousSystem: number;
autonomousSystem: string;
bgpProfile: string | null;
};
export type RoutingProtocol = {
Expand Down
2 changes: 1 addition & 1 deletion packages/frinx-dashboard/src/api/unistore/unistore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function createVpnService(vpnService: VpnService): Promise<void> {
}

export async function getVpnSites(): Promise<VpnSitesOutput> {
const json = await sendGetRequest(`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites`);
const json = await sendGetRequest(`${UNICONFIG_SERVICE_URL}/gamma-l3vpn-svc:l3vpn-svc/sites?content=config`);
const data = decodeVpnSitesOutput(json);
return data;
}
Expand Down
13 changes: 8 additions & 5 deletions packages/frinx-gamma/src/components/forms/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function apiRoutingProtocolToClientRoutingProtocol(routingProtocol: Routi
bgp: bgpProtocol
? {
addressFamily: 'ipv4',
autonomousSystem: bgpProtocol['autonomous-system'],
autonomousSystem: String(bgpProtocol['autonomous-system']),
bgpProfile: bgpProtocol['bgp-profiles']['bgp-profile'][0].profile,
}
: undefined,
Expand Down Expand Up @@ -174,9 +174,12 @@ export function apiSiteNetworkAccessToClientSiteNetworkAccess(
const apiQosProfiles = access.service.qos['qos-profile']['qos-profile'];
const [clientQosProfile] = apiQosProfiles.length ? apiQosProfiles.map((p) => p.profile) : [''];
const vpnAttachment = access['vpn-attachment'] ? access['vpn-attachment']['vpn-id'] : null;
const routingProtocols = access['routing-protocols']['routing-protocol'].map((p) => {
return apiRoutingProtocolToClientRoutingProtocol(p);
});
const routingProtocols =
access['routing-protocols'] && access['routing-protocols']['routing-protocol']
? access['routing-protocols']['routing-protocol'].map((p) => {
return apiRoutingProtocolToClientRoutingProtocol(p);
})
: [];
return {
siteNetworkAccessId: access['site-network-access-id'],
siteNetworkAccessType: access['site-network-access-type'] as SiteNetworkAccessType,
Expand Down Expand Up @@ -306,7 +309,7 @@ function clientRoutingProtocolsToApiRoutingProtocols(routingProtocols: RoutingPr
'bgp-profile': [{ profile: p.bgp.bgpProfile || '' }] as [{ profile: string }],
},
'address-family': ['ipv4'] as ['ipv4'],
'autonomous-system': p.bgp.autonomousSystem,
'autonomous-system': Number(p.bgp.autonomousSystem),
};
}
if (p.static) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,10 @@ const RoutingProtocolForm: VoidFunctionComponent<Props> = ({
<Input
variant="filled"
name="bgp-autonomous-system"
value={bgpProtocol ? unwrap(bgpProtocol.bgp).autonomousSystem : ''}
value={bgpProtocol.bgp ? bgpProtocol.bgp.autonomousSystem : ''}
onChange={(event) => {
const value = Number(event.target.value);

if (Number.isNaN(value)) {
const { value } = event.target;
if (Number.isNaN(Number(value))) {
return;
}

Expand All @@ -124,7 +123,7 @@ const RoutingProtocolForm: VoidFunctionComponent<Props> = ({
type: 'bgp',
bgp: {
...oldBgpRoutingProtocol,
autonomousSystem: Number(value),
autonomousSystem: value,
},
};
const newProtocols = [newBgpRoutingProtocol, staticProtocol];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function getDefaultBgpRoutingProtocol(): RoutingProtocol {
type: 'bgp',
bgp: {
addressFamily: 'ipv4',
autonomousSystem: 0,
autonomousSystem: '',
bgpProfile: null,
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/frinx-gamma/src/components/forms/site-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type StaticRoutingType = {
};
export type BgpRoutingType = {
addressFamily: 'ipv4';
autonomousSystem: number;
autonomousSystem: string;
bgpProfile: string | null;
};
export type RoutingProtocol = {
Expand Down
4 changes: 2 additions & 2 deletions packages/frinx-gamma/src/network-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export function decodeRoutingProtocolItemOutput(value: unknown): RoutingProtocol
}

const RoutingProtocolsValidator = t.type({
'routing-protocol': t.array(RoutingProtocolItemValidator),
'routing-protocol': optional(t.array(RoutingProtocolItemValidator)),
});

export type RoutingProtocolsOutput = t.TypeOf<typeof RoutingProtocolsValidator>;
Expand Down Expand Up @@ -293,7 +293,7 @@ const SiteNetworkAccessValidator = t.type({
}),
}),
}),
'routing-protocols': RoutingProtocolsValidator,
'routing-protocols': optional(RoutingProtocolsValidator),
}),
),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const getDefaultNetworkAccess = (): SiteNetworkAccess => ({
vrrp: 'ipv4',
bgp: {
addressFamily: 'ipv4',
autonomousSystem: 0,
autonomousSystem: '',
bgpProfile: null,
},
static: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const EditSiteNetAccessPage: VoidFunctionComponent<Props> = ({ onSuccess, onCanc
{selectedSite && selectedNetworkAccess && (
<>
<SiteNetworkAccessForm
mode="add"
mode="edit"
qosProfiles={qosProfiles}
bfdProfiles={bfdProfiles}
bgpProfiles={bgpProfiles}
Expand Down

0 comments on commit d66e7c0

Please sign in to comment.