-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from CiscoDevNet/DT_add-exceptions-to-get-vers…
…ion-checker Updates to the multi-version fonction and 'Contract' ruleset
- Loading branch information
Showing
5 changed files
with
240 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Changelog | ||
|
||
## October 24th, 2024 | ||
|
||
The 'multi-version' rule received several updates: | ||
- it does not consider any more 'v*' patterns in path such as 'ipv6' as version number. | ||
- the rule also support expections for paths such as '/api/dhcp/v4' where v4 should not be considered as a version number per the API design. | ||
|
||
The 'Contract' ruleset has been updated to include an exception for path "networks/{networkId}/switch/dhcp/v4" of the Meraki API. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
export default function getVersion(str, exceptionList) { | ||
|
||
// Exclude paths fragments that are considered exceptions | ||
if (exceptionList) { | ||
for (const exception of exceptionList) { | ||
if (str.includes(exception)) { | ||
str = str.replace(exception, 'EXCEPTION'); | ||
} | ||
} | ||
} | ||
|
||
// The version regex is pretty complex to address all use cases at Cisco | ||
// Please check this Asana issue for full context and explorations: https://app.asana.com/0/1206872740398257/1206657704786474 | ||
//const versionRegex = /\b\/?v\d+(\.\d+)*\/?(\b|$)/; // does not fully work, captures v6 as a version number for path: "/device/cedgecflowd/app-fwd-cflowd-v6-flows" | ||
const versionRegex = /(?<![-\w])\/?v\d+(\.\d+)*\/?(\b|$)/; // does NOT capture v6 as a version number for path: "/device/cedgecflowd/app-fwd-cflowd-v6-flows" | ||
|
||
let version = ''; | ||
const parts = str.match(versionRegex); | ||
if (parts) { | ||
version = parts[0]; | ||
|
||
// The latest regexp captures /v1 in some cases, let's remove leading or trailing '/' if any | ||
version = version.charAt(0) === '/' ? version.slice(1) : version; | ||
version = version.charAt(version.length - 1) === '/' ? version.slice(0, -1) : version; | ||
} | ||
|
||
return version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/** | ||
* Copyright 2022 Cisco Systems, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import getVersion from './getVersion.js'; | ||
import { describe, expect, jest, test } from '@jest/globals'; | ||
|
||
describe('getVersion', () => { | ||
const serverUrls = [ | ||
{ | ||
url: 'http://api.example1.com/v1.2/', | ||
version: 'v1.2' | ||
}, | ||
{ | ||
url: 'http://api.example1.com/v1', | ||
version: 'v1' | ||
} | ||
] | ||
|
||
const paths = [ | ||
{ | ||
path: 'v2/my/bad/path', | ||
version: 'v2' | ||
}, | ||
{ | ||
path: '/v2.1.0/my/path', | ||
version: 'v2.1.0' | ||
}, | ||
{ | ||
path: '/api/v1/cloudonramp/saas', | ||
version: 'v1' | ||
}, | ||
{ | ||
path: '/api/v1/config-group', | ||
version: 'v1' | ||
}, | ||
{ | ||
path: '/api/v1/config-group/{configGroupId}', | ||
version: 'v1' | ||
}, | ||
{ | ||
path: '/api/v2/data/device/statistics/interfacestatistics/fields', | ||
version: 'v2' | ||
}, | ||
{ | ||
path: '/api/device/dhcpv6/intesface', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/v2.1.0/device/dhcpv6/intesface', | ||
version: 'v2.1.0' | ||
}, | ||
{ | ||
path: '/api/device/interface/ipv6Stats', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/ip/v4fib', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/ip/v6fib', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/ipsec/ikev1', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/ipsec/ikev2', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/ipv6/nd6', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/ndv6', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/omp/routes/advertised/ompIpv6', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/omp/routes/received/ompIpv6', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/ospf/v3interface', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/ospf/v3neighbor', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/policy/ipv6/accesslistassociations', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/policy/ipv6/accesslistcounters', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/policy/ipv6/accesslistnames', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/policy/ipv6/accesslistpolicers', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/roleBasedIpv6Counters', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/device/roleBasedIpv6Permissions', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/template/policy/definition/aclv6', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/template/policy/definition/aclv6/bulk', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/template/policy/definition/aclv6/multiple/{id}', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/template/policy/definition/aclv6/{id}', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/template/policy/definition/deviceaccesspolicyv6', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/template/policy/definition/deviceaccesspolicyv6/bulk', | ||
version: '' | ||
}, | ||
{ | ||
path: '/api/template/policy/definition/deviceaccesspolicyv6/multiple/{id}', | ||
version: '' | ||
} | ||
] | ||
|
||
|
||
test('should return the version from the server urls', () => { | ||
serverUrls.forEach(serverUrl => { | ||
const version = getVersion(serverUrl.url); | ||
expect(version).toEqual(serverUrl.version); | ||
}); | ||
}); | ||
|
||
test('should return the version from the paths', () => { | ||
paths.forEach(path => { | ||
const version = getVersion(path.path); | ||
expect(version).toEqual(path.version); | ||
}); | ||
}); | ||
}); | ||
|