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

Implemented wildcard selector (based on #238) #488

Merged
merged 18 commits into from
Sep 15, 2023

Conversation

keattang
Copy link
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

hashicorp-cla commented Sep 8, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
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
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
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
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
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