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

Implement rdctl create-profile [ --input FILE | --body JSON | --from-settings ] #5021

Merged
merged 38 commits into from
Aug 2, 2023

Conversation

ericpromislow
Copy link
Contributor

@ericpromislow ericpromislow commented Jun 21, 2023

Fixes #5020

This lets users create registry and plist files from either current settings or arbitrary JSON documents.

Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

Adding --body and --input options to list-settings doesn't make any sense; it should always fetch the current settings from the API.

If we want to have this general conversion functionality (and I do think that this is useful to have), then it needs to be a separate command.

Let's hash out the design of those commands first before working on the implementation.

@ericpromislow
Copy link
Contributor Author

I agree that it doesn't make sense for list-settings to do this. But it didn't take much code - about 25 lines not counting doc-strings and tests, and I figured best to get it done while it was fresh in my mind.

I don't see how rdctl list-settings --output reg.... is useful unless you edit the output before importing it into the registry.

@ericpromislow ericpromislow marked this pull request as draft June 22, 2023 16:44
@jandubois
Copy link
Member

I don't see how rdctl list-settings --output reg.... is useful unless you edit the output before importing it into the registry.

I agree, but removing stuff in an editor is still easier than writing a JSON input file manually. So I would still use the preferences dialog to set all the desired settings, export them into reg or plist format, and then just remove things I don't intend to lock down.

For the defaults profile it doesn't even matter; you can leave everything in. The defaults are only applied during first-run anyways.

@ericpromislow ericpromislow force-pushed the 4562-add-reg-output-option branch 3 times, most recently from 59ce8b1 to 8b652c4 Compare June 29, 2023 22:26
@ericpromislow ericpromislow force-pushed the 5020-fake-rdctl-convert-command branch from 3d9fd01 to 8a3cb6b Compare July 3, 2023 22:25
Base automatically changed from 4562-add-reg-output-option to main July 5, 2023 17:12
@ericpromislow ericpromislow force-pushed the 5020-fake-rdctl-convert-command branch from b8b7925 to 628622b Compare July 7, 2023 00:35
@ericpromislow ericpromislow force-pushed the 5020-fake-rdctl-convert-command branch 3 times, most recently from d346c31 to 6086479 Compare July 27, 2023 22:09
@ericpromislow ericpromislow force-pushed the 5020-fake-rdctl-convert-command branch from 6086479 to cfae438 Compare July 27, 2023 22:30
@ericpromislow ericpromislow changed the title Add --input and --body flags to rdctl list-settings Implement rdctl create-profile [ --input FILE | --body JSON | --from-settings ] Jul 27, 2023
@ericpromislow ericpromislow marked this pull request as ready for review July 27, 2023 22:36
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

This is only a partial review of the tests.

I would really like to understand the issue with assert_output and here-documents because I think a lot of the tests would read better with here-docs.

bats/tests/preferences/generate-reg-output.bats Outdated Show resolved Hide resolved
bats/tests/preferences/generate-reg-output.bats Outdated Show resolved Hide resolved
bats/tests/preferences/generate-reg-output.bats Outdated Show resolved Hide resolved
bats/tests/preferences/generate-reg-output.bats Outdated Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
src/go/rdctl/cmd/createProfile.go Outdated Show resolved Hide resolved
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

Another round of feedback

bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
Comment on lines 198 to 411
# Just match a few of the lines near the start and the end of the output.
# The unit tests do more comprehensive output checking.
Copy link
Member

Choose a reason for hiding this comment

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

The comment seems out-dated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'm going with full here-doc testing now.

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

check-spelling found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@ericpromislow ericpromislow force-pushed the 5020-fake-rdctl-convert-command branch 2 times, most recently from 8328d0d to ab6770f Compare July 28, 2023 20:04
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

Another round of feedback, based solely on reading through the tests.

src/go/rdctl/cmd/createProfile.go Outdated Show resolved Hide resolved

if outputSettingsFlags.Format == plistFormat {
if outputSettingsFlags.RegistryHive != "" || outputSettingsFlags.RegistryProfileType != "" {
return fmt.Errorf("registry hive and type can't be specified with plist")
Copy link
Member

Choose a reason for hiding this comment

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

For consistency with quoting of all "values" in other errors:

Suggested change
return fmt.Errorf("registry hive and type can't be specified with plist")
return fmt.Errorf(`registry hive and type can't be specified with output "plist"`)

src/go/rdctl/cmd/createProfile.go Outdated Show resolved Hide resolved
case "":
outputSettingsFlags.RegistryProfileType = defaultsType
default:
return fmt.Errorf("invalid registry type of '%s' specified, must be %s or %s", outputSettingsFlags.RegistryProfileType, defaultsType, lockedType)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("invalid registry type of '%s' specified, must be %s or %s", outputSettingsFlags.RegistryProfileType, defaultsType, lockedType)
return fmt.Errorf(`invalid registry type of "%s" specified, must be "%s" or "%s"`, outputSettingsFlags.RegistryProfileType, defaultsType, lockedType)

bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Outdated Show resolved Hide resolved
bats/tests/profile/create-profile-output.bats Show resolved Hide resolved
Signed-off-by: Eric Promislow <epromislow@suse.com>
Use double-quoting to quote all terms that need quoting in user-directed messages.

Put command-line checking BATs tests before tests that run and check output.

Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
On Windows run the output through 'reg import' to verify it's acceptable.

Signed-off-by: Eric Promislow <epromislow@suse.com>
- The missing-file error message is different in WSL, so drop the specific part
- The `<(function)` form doesn't work on Windows, so use it only on macos-specific tests.

Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Ensure that on the bash side we write to `/mnt/DRIVE/tmp`,
and on Windows it's `DRIVE:\tmp``

We also have to change the directory name `Policies` to something
else because modifying it requires admin privileges, even in HKCU.

Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
- Put the bogus namespace in a variable
- Use the term 'full settings' for consistency
- Have `assert_check_registry_output` use `$output`

Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Signed-off-by: Eric Promislow <epromislow@suse.com>
Comment on lines +450 to +454
@test "and shutdown" {
if is_macos; then
rdctl shutdown
fi
}
Copy link
Member

Choose a reason for hiding this comment

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

This should not be necessary; we really should look into why this happens for you. Is this specific to using RD_LOCATION=dev? Because I always use RD_LOCATION=system, and it doesn't need a shutdown during teardown.

Will approve as is though and create a seoarate issue.

@jandubois jandubois merged commit c728928 into main Aug 2, 2023
13 checks passed
@jandubois jandubois deleted the 5020-fake-rdctl-convert-command branch August 2, 2023 01:23
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.

Support generating reg files from arbitrary JSON snippets
2 participants