Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing interpolation if a service config string has a -- in it #610

Merged
merged 4 commits into from Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/commands/secrets/download.ts
Expand Up @@ -20,6 +20,7 @@ export default class SecretsDownload extends BaseCommand {
};

static args = [{
non_sensitive: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are non_sensitive secrets?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm I see this is used everywhere now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this just the secrets filename? That doesn't seem secret to me

name: 'secrets_file',
description: 'Secrets filename to download secrets',
required: true,
Expand Down
12 changes: 8 additions & 4 deletions src/commands/secrets/upload.ts
Expand Up @@ -19,13 +19,17 @@ export default class SecretsUpload extends BaseCommand {
...BaseCommand.flags,
...AccountUtils.flags,
...EnvironmentUtils.flags,
override: Flags.boolean({
description: 'Allow override of existing secrets',
default: false,
}),
override: {
non_sensitive: true,
...Flags.boolean({
description: 'Allow override of existing secrets',
default: false,
}),
},
};

static args = [{
non_sensitive: true,
name: 'secrets_file',
description: 'Secrets file to be uploaded',
required: true,
Expand Down
2 changes: 1 addition & 1 deletion src/dependency-manager/spec/utils/slugs.ts
Expand Up @@ -15,7 +15,7 @@ export class Slugs {

public static ArchitectSlugDescription = `must contain only lower alphanumeric and single hyphens or underscores in the middle; max length ${Slugs.SLUG_CHAR_LIMIT}`;
static CharacterCountLookahead = `(?=.{1,${Slugs.SLUG_CHAR_LIMIT}}(\\${Slugs.NAMESPACE_DELIMITER}|${Slugs.TAG_DELIMITER}|$))`;
public static ArchitectSlugRegexBase = `(?!-)(?!.*--)[a-z0-9-]{1,${Slugs.SLUG_CHAR_LIMIT}}(?<!-)`;
public static ArchitectSlugRegexBase = `(?!-)(?!.{0,${Slugs.SLUG_CHAR_LIMIT}}--)[a-z0-9-]{1,${Slugs.SLUG_CHAR_LIMIT}}(?<!-)`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

public static ArchitectSlugValidator = new RegExp(`^${Slugs.ArchitectSlugRegexBase}$`);

public static LabelMax = 63;
Expand Down
47 changes: 47 additions & 0 deletions test/dependency-manager/interpolation.test.ts
Expand Up @@ -1639,4 +1639,51 @@ describe('interpolation spec v1', () => {
API_ADDR: 'http://127.0.0.1:12345'
})
});

it('All edges are still found if a double dash exists later in the service config', async () => {
const config = `
name: examples/test

secrets:
api_port: 8080

interfaces:
api: \${{ services.api.interfaces.main.url }}

services:
app:
environment:
API_PORT: \${{ services.api.interfaces.main.port }}
API_ADDR: \${{ services.api.interfaces.main.url }}
liveness_probe:
command: curl --fail localhost:3000/users || exit 1
interval: 30s
failure_threshold: 3
api:
interfaces:
main: \${{ secrets.api_port }}
environment:
MY_PORT: \${{ services.api.interfaces.main.port }}
MY_ADDR: \${{ services.api.interfaces.main.url }}
`

mock_fs({
'/stack/architect.yml': config,
});

const manager = new LocalDependencyManager(axios.create(), {
'examples/test': '/stack/architect.yml',
});
const graph = await manager.getGraph(
await manager.loadComponentSpecs('examples/test')
);

const test_component_ref = resourceRefToNodeRef('examples/test');
const app_ref = resourceRefToNodeRef('examples/test.services.app');
const api_ref = resourceRefToNodeRef('examples/test.services.api');
expect(graph.edges.map((e) => e.toString())).has.members([
`${test_component_ref} [api] -> ${api_ref} [main]`,
`${app_ref} [service->main] -> ${api_ref} [main]`,
]);
});
});
4 changes: 0 additions & 4 deletions test/dependency-manager/utils/slug-splitters.test.ts
Expand Up @@ -11,15 +11,13 @@ describe('slug validators with account', () => {
const component_slug = `${component_account_name}/${component_name}`;
const component_version_slug = `${component_account_name}/${component_name}:${tag}`;
const resource_slug = `${component_account_name}/${component_name}.services.${resource_name}`;
const resource_version_slug = `${component_account_name}/${component_name}.services.${resource_name}:${tag}`;

const invalid_slug = 'double--dashes';
const invalid_tag = '.1.0.0';

const invalid_component_slug = `${invalid_slug}/${component_name}`;
const invalid_component_version_slug = `${component_account_name}/${component_name}:${invalid_tag}`;
const invalid_resource_slug = `${component_account_name}/${component_name}.services.${invalid_slug}`;
const invalid_resource_version_slug = `${component_account_name}/${component_name}.services.${resource_name}:${invalid_tag}`;

it(`ComponentSlugUtils.parse accurately splits ${component_slug}`, async () => {
const result = ComponentSlugUtils.parse(component_slug);
Expand Down Expand Up @@ -63,15 +61,13 @@ describe('slug validators without account', () => {
const component_slug = `${component_name}`;
const component_version_slug = `${component_name}:${tag}`;
const resource_slug = `${component_name}.services.${resource_name}`;
const resource_version_slug = `${component_name}.services.${resource_name}:${tag}`;

const invalid_slug = 'double--dashes';
const invalid_tag = '.1.0.0';

const invalid_component_slug = `${invalid_slug}/${component_name}`;
const invalid_component_version_slug = `${component_name}:${invalid_tag}`;
const invalid_resource_slug = `${component_name}.services.${invalid_slug}`;
const invalid_resource_version_slug = `${component_name}.services.${resource_name}:${invalid_tag}`;

it(`ComponentSlugUtils.parse accurately splits ${component_slug}`, async () => {
const result = ComponentSlugUtils.parse(component_slug);
Expand Down