Skip to content

Commit

Permalink
Merge pull request #70 from projectsyn/fix/regex-region
Browse files Browse the repository at this point in the history
Fix default cloud region regex to not extract regions with slashes
  • Loading branch information
glrf authored Aug 2, 2022
2 parents 18dc49f + cc6ee75 commit f1b0d65
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/commodore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const defaultExtraConfig = {
distributionRegex:
/^distribution\/(?<distribution>[^\/]+)(?:\/cloud\/(?<cloud>.+)\.ya?ml|(?:\/.+)?\.ya?ml)$/,
cloudRegionRegex:
/^cloud\/(?<cloud>[^\/]+)(?:\/(?<region>.+)\.ya?ml|\.ya?ml)$/,
/^cloud\/(?<cloud>[^\/]+)(?:\/(?:(?<region>[^\/]+)|.+)\.ya?ml|\.ya?ml)$/,
ignoreValues: ['params'],
// map facts to files
factsMap: {} as any,
Expand Down
3 changes: 2 additions & 1 deletion src/commodore/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ The manager currently understands the following keys in the extra configuration
The manager will also use a named capture group `region` as the cloud provider region, if it exists.
The regex pattern should be written such that it matches the relative file path of a cloud class in the global defaults repository.

Default: `/^cloud\/(?<cloud>[^\/]+)(?:\/(?<region>.+)\.ya?ml|\.ya?ml)$/`.
Default: `/^cloud\/(?<cloud>[^\/]+)(?:\/(?:(?<region>[^\/]+)|.+)\.ya?ml|\.ya?ml)$/`

The default regex pattern extracts the cloud (and optionally cloud region) name from file names in the following forms (and additionally the same forms with `.yaml` file extensions):

- `cloud/<cloud>.yml`
- `cloud/<cloud>/<region>.yml`
- `cloud/<cloud>/foo/bar.yml`

- `ignoreValues`: An array of strings to ignore if they appear as distribution, cloud or region values.
The manager will not use distribution, cloud, or region values which match an entry in this array when calling `commodore inventory show`.
Expand Down
12 changes: 11 additions & 1 deletion src/commodore/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,18 @@ describe('src/commodore/util', () => {
${'distribution/dist.yml'} | ${{ distribution: 'dist', cloud: null, region: null }}
${'cloud/cloud.yml'} | ${{ distribution: null, cloud: 'cloud', region: null }}
${'cloud/cloud/region.yml'} | ${{ distribution: null, cloud: 'cloud', region: 'region' }}
${'cloud/cloud2/region2.yaml'} | ${{ distribution: null, cloud: 'cloud2', region: 'region2' }}
${'cloud/cloud/params.yml'} | ${{ distribution: null, cloud: 'cloud', region: null }}
${'cloud/cloud2/params.yaml'} | ${{ distribution: null, cloud: 'cloud2', region: null }}
${'cloud/cloud/params/param.yml'} | ${{ distribution: null, cloud: 'cloud', region: null }}
${'cloud/cloud/foo/bar.yml'} | ${{ distribution: null, cloud: 'cloud', region: null }}
${'cloud/cloud2/foo/bar/buzz.yaml'} | ${{ distribution: null, cloud: 'cloud2', region: null }}
${'cloud/cloud2/foo/.yaml'} | ${{ distribution: null, cloud: 'cloud2', region: null }}
${'cloud/cloud//.yml'} | ${{ distribution: null, cloud: 'cloud', region: null }}
${'cloud/cloud/.yml'} | ${{ distribution: null, cloud: null, region: null }}
${'cloud/cloudnt/.yaml'} | ${{ distribution: null, cloud: null, region: null }}
${'cloud/cloud/notyml.json'} | ${{ distribution: null, cloud: null, region: null }}
${'cloud/cloud/notyml.sh'} | ${{ distribution: null, cloud: null, region: null }}
${'distribution/dist/cloud/cloud.yml'} | ${{ distribution: 'dist', cloud: 'cloud', region: null }}
`('returns $fact for $file', ({ file, fact }) => {
const f = util.parseFileName(
Expand All @@ -42,7 +53,6 @@ describe('src/commodore/util', () => {
defaultExtraConfig.ignoreValues
);

expect(hasFact(f)).toBe(true);
expect(f.distribution).toBe(fact.distribution);
expect(f.cloud).toBe(fact.cloud);
expect(f.region).toBe(fact.region);
Expand Down

0 comments on commit f1b0d65

Please sign in to comment.