Skip to content

Implemented wildcard selector (based on #238)#488

Merged
maxcoulombe merged 18 commits intohashicorp:mainfrom
PropellerAero:wildcard-selector
Sep 15, 2023
Merged

Implemented wildcard selector (based on #238)#488
maxcoulombe merged 18 commits intohashicorp:mainfrom
PropellerAero:wildcard-selector

Conversation

@keattang
Copy link
Copy Markdown
Contributor

@keattang keattang commented Sep 8, 2023

This PR builds upon the work done in #238 and implements all of the requested code review changes.

@hashicorp-cla
Copy link
Copy Markdown

hashicorp-cla commented Sep 8, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@maxcoulombe maxcoulombe left a comment

Choose a reason for hiding this comment

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

Hey @keattang , thanks for picking up the work on this, this is super appreciated.

The changes look good. My only suggestion is regarding test coverage so I'll merge the PR as is and adjust the test in a separate PR when we prepare the release to spare you the back-and-forth.

Cheers and thanks again!


expect(core.exportVariable).toBeCalledWith('GROUP_SECRET', 'SUPERSECRET');
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One small suggestion would be to setup a secret with multiple keys to validate that the wildcard operator does indeed picks up all the sub-keys.

For example on l.22:

        await got(`${vaultUrl}/v1/secret/data/test`, {
            method: 'POST',
            headers: {
                'X-Vault-Token': vaultToken,
            },
            json: {
                data: {
                    secret: 'SUPERSECRET',
                    secret_2: 'SUPERSECRET_2',
                },
            },
        });


expect(core.exportVariable).toBeCalledWith('OTHERSECRETDASH', 'OTHERCUSTOMSECRET');
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Then you can modify the test to cover not only that the wildcard is valid & the prefix gets applied, but that multiple sub-keys get picked up as well as desired:

    it('get wildcard secrets', async () => {
        mockInput(`secret/data/test * ;`);

        await exportSecrets();

        expect(core.exportVariable).toBeCalledTimes(2);

        expect(core.exportVariable).toBeCalledWith('SECRET', 'SUPERSECRET');
        expect(core.exportVariable).toBeCalledWith('SECRET_2', 'SUPERSECRET_2');
    });

    it('get wildcard secrets with name prefix', async () => {
        mockInput(`secret/data/test * | GROUP_ ;`);

        await exportSecrets();

        expect(core.exportVariable).toBeCalledTimes(2);

        expect(core.exportVariable).toBeCalledWith('GROUP_SECRET', 'SUPERSECRET');
        expect(core.exportVariable).toBeCalledWith('GROUP_SECRET_2', 'SUPERSECRET_2');
    });


expect(core.exportVariable).toBeCalledWith('GROUP_SECRET', 'CUSTOMSECRET_IN_NAMESPACE');
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here, would be great to have a multi-value secret as part of the tests.

@maxcoulombe maxcoulombe merged commit d9197ec into hashicorp:main Sep 15, 2023
@keattang
Copy link
Copy Markdown
Contributor Author

Yep sounds great! Thanks for getting this merged in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants