Skip to content

Conversation

@TheToddLuci0
Copy link
Contributor

@TheToddLuci0 TheToddLuci0 commented Jan 8, 2025

While hunting another issue, the spaghetti that is options resolution was getting rather annoying. So I replaced it with something much less tasty, but also much cleaner.

Basically, it uses the ArgumentParser.set_defaults method to update the defaults with the config files at runtime. This manes that we get the same behavior of "CLI wins", while also reducing the need to manually update a self.foobar = args.foobar or config_dict.get("foobar") every time a change is made to the args.

The downside is that it calls parser.parse_known_args() twice, but the actual runtime difference is, as far as I can measure, zero. Might matter if anyone is running credmaster on a 3DS.

@TheToddLuci0
Copy link
Contributor Author

A quick PoC to show the precedence order still works. (note that a debug print was added just before instantiating the CredMaster object)

(venv) ┌──(venv)─(kali㉿kali)-[~/git/CredMaster]
└─$ tail credmaster.py -n 3                                                          
        # Debug print for demo
        print(f"Current profile: {args.profile_name}")
        CredMaster(args, pluginargs)
                                                                                                                                                                                    
(venv) ┌──(venv)─(kali㉿kali)-[~/git/CredMaster]
└─$ python3 credmaster.py --plugin template 2>/dev/null | grep "Current profile" 
Current profile: None
                                                                                                                                                                                    
(venv) ┌──(venv)─(kali㉿kali)-[~/git/CredMaster]
└─$ python3 credmaster.py --plugin template --config aws.config 2>/dev/null | grep "Current profile"
Current profile: credmaster
                                                                                                                                                                                    
(venv) ┌──(venv)─(kali㉿kali)-[~/git/CredMaster]
└─$ python3 credmaster.py --plugin template --config aws.config --profile testey_mc_testerson 2>/dev/null | grep "Current profile"
Current profile: testey_mc_testerson

The 2>/dev/null is due to #90

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.

1 participant