Skip to content

Commit

Permalink
Merge pull request #284 from fonoster/feat/refactor-createdAt-as-a-date
Browse files Browse the repository at this point in the history
refactor created at as a date
  • Loading branch information
psanders authored Aug 16, 2024
2 parents e0ffcb0 + 134af9a commit 3be4c8f
Show file tree
Hide file tree
Showing 119 changed files with 705 additions and 764 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ jobs:
- name: SIP Connect v1.1 Compliance Tests
if: github.event.inputs.with_tests == 'true'
run: |
docker-compose -f compose.yaml -f compose.dev.yaml up \
--build --abort-on-container-exit --exit-code-from compliance \
compliance edgeport01 edgeport02 dispatcher registry requester apiserver connect location
docker compose -f compose.yaml -f compose.dev.yaml up \
--build --abort-on-container-exit --exit-code-from compliance compliance
publish-to-docker-hub:
name: Publish to Docker Hub
Expand Down
7 changes: 4 additions & 3 deletions compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ services:

#
# SIP End to End Test (SEET) compliance test for SIPConnect v1.1 support
# docker-compose -f compose.yaml -f compose.dev.yaml up \
# --abort-on-container-exit --exit-code-from compliance
# docker compose -f compose.yaml -f compose.dev.yaml up \
# --build --abort-on-container-exit --exit-code-from compliance compliance
#
compliance:
container_name: compliance
image: fonoster/seet:1.1.1
image: fonoster/seet:1.2.0
depends_on:
- edgeport01
- edgeport02
Expand All @@ -170,6 +170,7 @@ services:
- requester
- apiserver
- connect
- location
environment:
SCENARIOS: /seet.json
ports:
Expand Down
5 changes: 3 additions & 2 deletions etc/scenarios/rr/uac_invite_callee_bye.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">

<scenario name="RR.Tst.Plan.1.1.2.UAC">
<scenario name="RR.Tst.Plan.1.5.1.UAC">

<Global variables="requestURI,from,to" />

Expand Down Expand Up @@ -87,7 +87,8 @@
</action>
</recv>

<!-- The stack is not generating routes for the following command -->
<!-- WARNING: This step is failing due to a bug in the connect processor which
overwrites the contact header with the peer EdgePort. -->
<send>
<![CDATA[
ACK [$remoteURI] SIP/2.0
Expand Down
2 changes: 1 addition & 1 deletion etc/scenarios/rr/uas_agent_to_agent_callee_bye.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">

<scenario name="RR.Tst.Plan.1.1.2.UAS">
<scenario name="RR.Tst.Plan.1.5.1.UAS">

<recv request="INVITE" rrs="true" />

Expand Down
8 changes: 4 additions & 4 deletions etc/seet.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
},
{
"name": "=== Registering sip.provider.net for 1200 seconds to prevent collisions ===",
"description": "Hack to prevent trunk from sending additional REGISTER meesages.",
"description": "Hack to prevent trunk from sending additional REGISTER messages.",
"transportMode": "u1",
"userAgents": [
{
Expand Down Expand Up @@ -607,7 +607,7 @@
]
},
{
"name": "RR.Tst.Plan.1.4.1: Sending a SIP Message to a Peer with Load Balacing in Round Robin Mode",
"name": "RR.Tst.Plan.1.4.1: Sending a SIP Message to a Peer with Load Balancing in Round Robin Mode",
"description": "This test verifies that Routr correctly routes a SIP message to a Peer with load balancing in Round Robin Mode",
"transportMode": "u1",
"target": "sip01.edgeport.net:5060",
Expand Down Expand Up @@ -674,8 +674,8 @@
]
},
{
"name": "RR.Tst.Plan.1.4.2: Sending a SIP Message to a Peer with Load Balacing using Least-Sessions Mode",
"description": "Unsupported scenario. Please enable and visualy inspect the signaling!",
"name": "RR.Tst.Plan.1.4.2: Sending a SIP Message to a Peer with Load Balancing using Least-Sessions Mode",
"description": "Unsupported scenario. Please enable and visually inspect the signaling!",
"transportMode": "u1",
"target": "sip01.edgeport.net:5060",
"enabled": false,
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"packages": ["mods/*"],
"version": "2.12.1"
"version": "2.13.4"
}
File renamed without changes.
2 changes: 1 addition & 1 deletion mods/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@routr/common",
"version": "2.12.1",
"version": "2.13.4",
"description": "Common package",
"author": "Pedro Sanders <[email protected]>",
"homepage": "https://github.com/fonoster/routr#readme",
Expand Down
3 changes: 1 addition & 2 deletions mods/common/src/connect/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* limitations under the License.
*/
import * as grpc from "@grpc/grpc-js"
import { JsonObject } from "pb-util/build"
import {
AccessControlList,
Agent,
Expand Down Expand Up @@ -71,7 +70,7 @@ export type APIClient = {
numbers: ServiceAPI<INumber>
}

export type ServiceAPI<R extends { extended?: JsonObject }> = {
export type ServiceAPI<R extends { extended?: Record<string, unknown> }> = {
create: (request: unknown) => Promise<R>
update: (request: unknown) => Promise<R>
get: (ref: string) => Promise<R>
Expand Down
2 changes: 1 addition & 1 deletion mods/common/src/connect/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const hasValidACLRulesOrThrow = (acl: {
allow: string[]
}) => validOrThrow(hasValidACLRules, acl)

export const hasRefenceOrThrow = (ref: string) =>
export const hasReferenceOrThrow = (ref: string) =>
validOrThrow(hasReference, ref)

export const hasNameOrThrow = (name: string) => validOrThrow(hasName, name)
Expand Down
18 changes: 8 additions & 10 deletions mods/common/src/connect/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ import * as grpc from "@grpc/grpc-js"
import { toPascalCase } from "../helper"
import { Kind, KindWithoutUnknown } from "./types"
import protoLoader = require("@grpc/proto-loader")

const protoOptions = {
keepCase: false,
longs: String,
enums: String,
defaults: true,
oneofs: true
}
import { protoLoadOptions } from "../service"

function getProtoPath(kind: Kind): string {
switch (kind) {
Expand All @@ -46,7 +39,7 @@ export function createConnectClient(options: {
credentials: grpc.ChannelCredentials
apiAddr: string
}) {
const def = protoLoader.loadSync(getProtoPath(options.kind), protoOptions)
const def = protoLoader.loadSync(getProtoPath(options.kind), protoLoadOptions)
const descriptor = grpc.loadPackageDefinition(def) as any
const base = descriptor.fonoster.routr.connect

Expand All @@ -69,7 +62,12 @@ export function createConnectClient(options: {
}

export function createConnectService(kind: KindWithoutUnknown) {
const def = protoLoader.loadSync(getProtoPath(kind), protoOptions)
// Here we set defaults to simplify partial updates
const actualProtoOptions = {
...protoLoadOptions,
defaults: false
}
const def = protoLoader.loadSync(getProtoPath(kind), actualProtoOptions)
const descriptor = grpc.loadPackageDefinition(def) as any
const base = descriptor.fonoster.routr.connect

Expand Down
4 changes: 2 additions & 2 deletions mods/common/src/connect/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* limitations under the License.
*/
import { LoadBalancingAlgorithm, Privacy, Transport } from "../types"
import { Kind } from "./types"
import { APIVersion, Kind } from "./types"

export interface ConfigBase {
apiVersion: string
apiVersion: APIVersion
ref: string
metadata: { name: string }
}
Expand Down
4 changes: 3 additions & 1 deletion mods/common/src/connect/mappers/acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export function mapToACL(config: AccessControlListConfig): AccessControlList {
ref: config.ref,
name: config.metadata.name,
allow: config.spec.accessControlList?.allow ?? [],
deny: config.spec.accessControlList?.deny ?? []
deny: config.spec.accessControlList?.deny ?? [],
createdAt: new Date().getTime(),
updatedAt: new Date().getTime()
}
}
6 changes: 4 additions & 2 deletions mods/common/src/connect/mappers/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ export function mapToAgent(config: AgentConfig): Agent {
name: config.metadata.name,
username: config.spec.username,
privacy: config.spec.privacy ?? Privacy.NONE,
enabled: config.spec.enabled as boolean,
enabled: config.spec.enabled,
domainRef: config.spec.domainRef,
credentialsRef: config.spec.credentialsRef,
maxContacts: config.spec.maxContacts,
expires: config.spec.expires
expires: config.spec.expires,
createdAt: new Date().getTime(),
updatedAt: new Date().getTime()
}
}
4 changes: 3 additions & 1 deletion mods/common/src/connect/mappers/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export function mapToCredentials(config: CredentialsConfig): Credentials {
ref: config.ref,
name: config.metadata.name,
username: config.spec.credentials.username,
password: config.spec.credentials.password
password: config.spec.credentials.password,
createdAt: new Date().getTime(),
updatedAt: new Date().getTime()
}
}
4 changes: 3 additions & 1 deletion mods/common/src/connect/mappers/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export function mapToDomain(config: DomainConfig): Domain {
name: config.metadata.name,
domainUri: config.spec.context.domainUri,
accessControlListRef: config.spec.accessControlListRef,
egressPolicies: config.spec.context.egressPolicies
egressPolicies: config.spec.context.egressPolicies,
createdAt: new Date().getTime(),
updatedAt: new Date().getTime()
}
}
4 changes: 3 additions & 1 deletion mods/common/src/connect/mappers/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export function mapToNumber(config: NumberConfig): INumber {
aorLink: location.aorLink,
sessionAffinityHeader: location.sessionAffinityHeader,
extraHeaders: location.extraHeaders,
trunkRef: config.spec.trunkRef
trunkRef: config.spec.trunkRef,
createdAt: new Date().getTime(),
updatedAt: new Date().getTime()
}
}
4 changes: 3 additions & 1 deletion mods/common/src/connect/mappers/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export function mapToPeer(config: PeerConfig): Peer {
),
withSessionAffinity: config.spec.loadBalancing?.withSessionAffinity,
maxContacts: config.spec.maxContacts,
expires: config.spec.expires
expires: config.spec.expires,
createdAt: new Date().getTime(),
updatedAt: new Date().getTime()
}
}
4 changes: 3 additions & 1 deletion mods/common/src/connect/mappers/trunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export function mapToTrunk(config: TrunkConfig): Trunk {
weight: entry.weight,
priority: entry.priority
}
})
}),
createdAt: new Date().getTime(),
updatedAt: new Date().getTime()
}
}
15 changes: 7 additions & 8 deletions mods/common/src/connect/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { JsonObject } from "pb-util/build"
import { LoadBalancingAlgorithm, Privacy, Transport } from "../types"

export enum Kind {
Expand All @@ -33,17 +32,17 @@ export enum Kind {
export type KindWithoutUnknown = Exclude<Kind, Kind.UNKNOWN>

export enum APIVersion {
v2beta1 = "v2beta1",
V2BETA1 = "v2beta1",
V2 = "v2"
}

export interface BaseConnectModel {
apiVersion: string
apiVersion: APIVersion
ref: string
name: string
createdAt?: number
updatedAt?: number
extended?: JsonObject
createdAt: number
updatedAt: number
extended?: Record<string, unknown>
}

export interface AccessControlList extends BaseConnectModel {
Expand Down Expand Up @@ -87,8 +86,8 @@ export interface INumber extends BaseConnectModel {
city: string
country: string
countryIsoCode: string
sessionAffinityHeader: string
extraHeaders: { name: string; value: string }[]
sessionAffinityHeader?: string
extraHeaders?: { name: string; value: string }[]
trunkRef?: string
trunk?: Trunk
}
Expand Down
6 changes: 4 additions & 2 deletions mods/common/src/connect/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export const isValidHeader = (header: string) => {
: true
}

export const hasValidHeaders = (headers: { name: string; value: string }[]) => {
export const hasValidHeaders = (
headers: { name: string; value: string }[] = []
) => {
// eslint-disable-next-line no-loops/no-loops
for (const header of headers) {
const E = isValidHeader(header.name) as true | BadRequestError
Expand Down Expand Up @@ -159,7 +161,7 @@ export const hasACLRules = (acl: { deny: string[]; allow: string[] }) => {
return true
}

export const isValidACLRule = (rules: string[]) => {
export const isValidACLRule = (rules: string[] = []) => {
// eslint-disable-next-line no-loops/no-loops
for (const cidr of rules) {
if (
Expand Down
4 changes: 2 additions & 2 deletions mods/common/src/protos/location.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ message AddRouteRequest {

message FindRoutesRequest {
message Backend {
enum Algoritm {
enum Algorithm {
ROUND_ROBIN = 0;
LEAST_SESSIONS = 1;
}
string ref = 1;
bool with_session_affinity = 2;
Algoritm algorithm = 3;
Algorithm algorithm = 3;
}
string call_id = 1;
string aor = 2;
Expand Down
9 changes: 2 additions & 7 deletions mods/common/src/requester/grpc_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@
*/
import * as grpc from "@grpc/grpc-js"
import protoLoader = require("@grpc/proto-loader")
import { protoLoadOptions } from "../service"

const packageDefinition = protoLoader.loadSync(
__dirname + "/../protos/requester.proto",
{
keepCase: false,
longs: String,
enums: String,
defaults: true,
oneofs: true
}
protoLoadOptions
)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion mods/common/src/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const createServerInternalErrorResponse = (
}
}

export const createForbideenResponse = (metadata?: Record<string, string>) => {
export const createForbiddenResponse = (metadata?: Record<string, string>) => {
return {
metadata,
message: {
Expand Down
4 changes: 2 additions & 2 deletions mods/common/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { GRPC_SERVING_STATUS, statusMap } from "@fonoster/common"

const logger = getLogger({ service: "common", filePath: __filename })

const loadOptions = {
export const protoLoadOptions = {
keepCase: false,
longs: String,
enums: String,
Expand Down Expand Up @@ -58,7 +58,7 @@ export const LOCATION_OBJECT_PROTO = getObjectProto({
export function getObjectProto<A>(
objectProto: ObjectProto
): A | ServiceDefinitionNotFoundError {
const definitions = protoLoader.loadSync(objectProto.path, loadOptions)
const definitions = protoLoader.loadSync(objectProto.path, protoLoadOptions)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const objProto = (grpc.loadPackageDefinition(definitions) as any)?.fonoster
?.routr[objectProto.name]
Expand Down
3 changes: 2 additions & 1 deletion mods/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export enum ExtraHeader {
SESSION_COUNT = "X-Session-Count",
DOD_NUMBER = "X-DOD-Number",
DOD_PRIVACY = "X-DOD-Privacy",
CONNECT_TOKEN = "X-Connect-Token"
CONNECT_TOKEN = "X-Connect-Token",
CALL_DIRECTION = "X-Call-Direction"
}

export enum Privacy {
Expand Down
Loading

0 comments on commit 3be4c8f

Please sign in to comment.