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

IDview #146

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

IDview #146

wants to merge 1 commit into from

Conversation

madhuriupadhye
Copy link
Contributor

No description provided.

@madhuriupadhye madhuriupadhye marked this pull request as draft January 13, 2025 10:52
@madhuriupadhye
Copy link
Contributor Author

@danlavu can you roughly overview this?
Please let me know for any changes

@danlavu
Copy link

danlavu commented Jan 14, 2025

I don't think this is how we should do it because this won't work for users. The command is different for users, groups and hosts, so we can rename the class to reflect the corresponding object. Maybe we should make a subclass or a method in the existing class, like

ipa.user("test user").add_idview(name="override_user")
ipa.host(["client"]).add_idview(["override_host"](

or a subclass

ipa.user("test user").add().override(name="override_user").add()

The thing I would like to see is that the parameters match the corresponding values in the parent class, so it's easier to write. The args for home directory in ideviews is 'homedir" but we are using "home" as an example.

Does this sound good?

@madhuriupadhye
Copy link
Contributor Author

I don't think this is how we should do it because this won't work for users. The command is different for users, groups and hosts, so we can rename the class to reflect the corresponding object. Maybe we should make a subclass or a method in the existing class, like

ipa.user("test user").add_idview(name="override_user")
ipa.host(["client"]).add_idview(["override_host"](

or a subclass

ipa.user("test user").add().override(name="override_user").add()

The thing I would like to see is that the parameters match the corresponding values in the parent class, so it's easier to write. The args for home directory in ideviews is 'homedir" but we are using "home" as an example.

Does this sound good?

I don't think this is how we should do it because this won't work for users. The command is different for users, groups and hosts, so we can rename the class to reflect the corresponding object. Maybe we should make a subclass or a method in the existing class, like

ipa.user("test user").add_idview(name="override_user")
ipa.host(["client"]).add_idview(["override_host"](

or a subclass

ipa.user("test user").add().override(name="override_user").add()

The thing I would like to see is that the parameters match the corresponding values in the parent class, so it's easier to write. The args for home directory in ideviews is 'homedir" but we are using "home" as an example.

Does this sound good?

I am planning to create IDView complete different class, and overrirde will be subclass of user but let me create the document so it will be more clear.

@madhuriupadhye madhuriupadhye force-pushed the ipa_view branch 2 times, most recently from 7d2593a to ee485c4 Compare January 16, 2025 14:08
@madhuriupadhye madhuriupadhye force-pushed the ipa_view branch 13 times, most recently from 1d69536 to d413078 Compare January 28, 2025 15:41
@madhuriupadhye madhuriupadhye force-pushed the ipa_view branch 8 times, most recently from 81d2a69 to 1f396b0 Compare February 3, 2025 15:47
Copy link

@danlavu danlavu left a comment

Choose a reason for hiding this comment

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

A few more directional changes, but this is looking a lot better, thank you.

"""


self.role.host.conn.run(
Copy link

Choose a reason for hiding this comment

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

You should use the CLIBuilder to make it consistent with the rest of the code and you do not have to add conditionals.

https://pytest-mh.readthedocs.io/en/latest/articles/tips-and-tricks/building-command-line.html

)
return self

def modify_id_override(
Copy link

Choose a reason for hiding this comment

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

Would rename it to modify and change the execution to host.conn.run or host.conn.exec so you don't have to sync the name of the function.

Copy link

Choose a reason for hiding this comment

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

So, after some testing the same function name is overloading the IPAUser.add() function. I know this was my suggestion, and I'm mistaken. We can rename the function to __add() to avoid the overloading.

@madhuriupadhye madhuriupadhye force-pushed the ipa_view branch 2 times, most recently from 4717cb0 to f7842bd Compare February 4, 2025 10:24
@madhuriupadhye madhuriupadhye force-pushed the ipa_view branch 13 times, most recently from 032981f to 70cc380 Compare February 4, 2025 15:53
"sshpubkey": (self.cli.option.VALUE, sshpubkey),
"certificate": (self.cli.option.VALUE, certificate),
}

Copy link

Choose a reason for hiding this comment

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

Try this.

            if attrs is None:
                args = []
            
            attrs = self.cli.args(
                {
                    "desc": (self.cli.option.VALUE, description),
                    "login": (self.cli.option.VALUE, login),
                   "uid": (self.cli.option.VALUE, uid),
                    "gidnumber": (self.cli.option.VALUE, gid),
                    "gecos": (self.cli.option.VALUE, gecos),
                    "home_directory": (self.cli.option.VALUE, home_directory),
                    "shell": (self.cli.option.VALUE, shell),
                    "sshpubkey": (self.cli.option.VALUE, sshpubkey),
                    "certificate": (self.cli.option.VALUE, certificate),
                }
            )
         
            self.role.host.conn.exec(["ipa", "idoverrideuser-add", idview_name, self.name, *attrs])
            return self

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it did not work.

Command:
    ipa idoverrideuser-add newview1 user-4 desc login uid gidnumber gecos home_directory shell sshpubkey certificate
  CWD:
  Env:
  Output:
  Error output:
    ipa: ERROR: command 'idoverrideuser_add' takes at most 2 arguments

Copy link

Choose a reason for hiding this comment

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

    def __add(
        self,
        idview_name: str,
        *,
        description: str | None = None,
        login: str | None = None,
        uid: int | None = None,
        gid: int | None = None,
        gecos: str | None = None,
        home_directory: str | None = None,
        shell: str | None = None,
        sshpubkey: str | None = None,
        certificate: str | list[str] | None = None,
    ) -> IDOverride:

        attrs = {
            "desc": (self.cli.option.VALUE, description),
            "login": (self.cli.option.VALUE, login),
            "uid": (self.cli.option.VALUE, uid),
            "gidnumber": (self.cli.option.VALUE, gid),
            "gecos": (self.cli.option.VALUE, gecos),
            "homedirectory": (self.cli.option.VALUE, home_directory),
            "shell": (self.cli.option.VALUE, shell),
            "sshpubkey": (self.cli.option.VALUE, sshpubkey),
            "certificate": (self.cli.option.VALUE, certificate),
        }

        self.role.host.conn.exec(["ipa", "idoverrideuser-add", idview_name, self.name] + list(self.cli.args(attrs)))

        return self

Working now, the clibuilder adds -- to the command, the way you had it, it was doing ----uid. The _modify function, takes the dict and turns it into a list, so we had to do that too.

self.name = user.name

def add(self,
idview_name:str,
Copy link

Choose a reason for hiding this comment

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

I'd use just name instead of idview_name, since it's a different class.


def apply(self, *, hosts: list[str] | None = None, hostgroups: str | None = None) -> IPAIdView:
"""
Applies ID View to specified hosts or current members of specified
Copy link

Choose a reason for hiding this comment

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

Which id view takes priority, is it the last one applied? I'd put that information in the :description:

Applies id view to host or hostgroup. 

:description: ID View is a key. Any overlapping views will replace the value. 
:param hosts: Host or hosts to apply the ID view to, defaults to None.

Signed-off-by: Madhuri Upadhye <[email protected]>
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.

2 participants