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

feat: register with content templates #168

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

rverdile
Copy link
Contributor

@rverdile rverdile commented Nov 13, 2024

Card ID: CCT-769.

This is dependent on this PR, which the requirements are still being discussed, so I'm leaving this in draft for now.

This PR implements a new option to register with a content template, given the content template name. Since content templates are implemented as environments in candlepin, I've tried to implement this such that some code could be re-used in the future for registering with environments.

Feedback is appreciated and welcome :)

Still needs

  • To handle activation keys
  • To handle when GetEnvironments() is not available

@Archana-PandeyM
Copy link

/packit build

@rverdile rverdile marked this pull request as ready for review December 2, 2024 13:49
Copy link
Contributor

@jirihnidek jirihnidek left a comment

Choose a reason for hiding this comment

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

Thanks for your PR. Overall, it works. 👍

I have to apologize. We agreed that we will support only environment with type == content-template. Thus, it will be possible to simplify your PR on some places. You can find more details in my comments.

I have some other requests.

rhsm.go Outdated
if len(environments) > 0 && organization != "" {
var useEnvIDs = false
envList, err := getEnvironmentsList(privConn, username, password, organization)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

If err is not nil, then orgs with error should be returned. We will not allow to use content-templates on the systems, where D-Bus method GetEnvironments() is not available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree this is a nice simplification. And now I'm thinking alternating to using the ID would not be useful in the case of content templates. @ptoscano wrote the ticket so he may want to provide some input here.

rhsm.go Outdated
return environments, nil
}

func mapEnvironmentIDsToNames(names []string, environmentList []Environment, contentTemplates bool) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Few notes:

  • The name of this function is not correct. You try to get environment IDs from environment names. Thus the name should be something like mapEnvironmentNamesToIds() or getContentTemplateIds(). You return list (not map) of environments with type == "content-template". I vote for getContentTemplateIds().
  • This method is missing doc string with description.
  • Variable contentTemplates bool could be removed.
  • You can also name returned variables. Something like:
func getContentTemplateIds()(names []string, environmentList []Environment, contentTemplates bool) (envIDs []string, err error) {
// Body of function

rhsm.go Outdated
Comment on lines 589 to 592
typeString := "environment"
if contentTemplates {
typeString = "content template"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be removed, because we will support only environments with type == "content-template"

rhsm.go Outdated
if contentTemplates {
typeString = "content template"
}
return nil, fmt.Errorf(typeString+" named \"%s\" was not found", name)
Copy link
Contributor

Choose a reason for hiding this comment

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

The error should be modified and the logic of error detection should be also modified.

I claim that we should return error if any of provided environment is not found or the type is not "content-type".

rhsm.go Outdated
return environments, nil
}

func getEnvironmentsList(conn *dbus.Conn, username, password, organization string) ([]Environment, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doc string is missing of this function.

rhsm.go Outdated
return e.Type == "content-template"
}

func unpackEnvironments(s string) ([]Environment, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Doc string is missing.

rhsm.go Show resolved Hide resolved
@jirihnidek
Copy link
Contributor

Following change in rhsm.service candlepin/subscription-manager#3480 would allow to simplify implementation of content template.

  1. It will be possible to use environment names directly for both authentication methods
  2. It will be possible to specify environment_type in argument of Register() and RegisterWithActivationKeys()
  3. Thus, there will be no need to call GetEnvironments() D-Bus method and registration will not be blocked by another REST API call.

@rverdile
Copy link
Contributor Author

Made the changes based on the new subscription manager PR!

@jirihnidek
Copy link
Contributor

@rverdile I just merged candlepin/subscription-manager#3480 to main ... I will review your PR tomorrow.

@jirihnidek
Copy link
Contributor

/packit build

Copy link
Contributor

@jirihnidek jirihnidek left a comment

Choose a reason for hiding this comment

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

Thanks for the update 👍 . It looks good. We are almost there. Can you please rebase your PR? We started to use meson build system and your branch does not reflect it. I also have three small requests.

rhsm.go Outdated
options := make(map[string]string)
if len(environments) != 0 {
options["environment_names"] = strings.Join(environments, ",")
options["environment_type"] = environmentType
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it is not necessary to pass environmentType as an argument to this function and you can use:

options["environment_type"] = EnvTypeContentTemplate

because we will use only "content-template".

rhsm.go Outdated
options := make(map[string]string)
if len(environments) != 0 {
options["environment_names"] = strings.Join(environments, ",")
options["environment_type"] = environmentType
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it is not necessary to pass environmentType as an argument to this function and you can use:

options["environment_type"] = EnvTypeContentTemplate

because we will use only "content-template".

.gitignore Outdated
@@ -7,3 +7,4 @@ BUILDROOT
RPMS
SOURCES
SRPMS
.idea
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not add this line to .gitignore as part of this PR. Such change is not related to this PR.

@rverdile rverdile force-pushed the content-templates branch 3 times, most recently from 4b28a76 to 1884313 Compare January 13, 2025 15:13
    * card ID: CCT-769
    * register to templates with --content-template <name>
@rverdile
Copy link
Contributor Author

updated, thanks!

@jirihnidek
Copy link
Contributor

/packit build

@jirihnidek jirihnidek merged commit 3e54b9a into RedHatInsights:main Jan 14, 2025
18 of 22 checks passed
Copy link
Contributor

@jirihnidek jirihnidek left a comment

Choose a reason for hiding this comment

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

LGTM

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.

5 participants