minio-py icon indicating copy to clipboard operation
minio-py copied to clipboard

MinioAdmin: allow specifying policies as dict besides file

Open Alveel opened this issue 10 months ago • 10 comments

It would be nice to be able to add/update IAM/service account policies through Python dict objects as well as what's currently available through JSON files.

This PR tries to accomplish this.

Feedback/questions welcome.

Depends on https://github.com/minio/minio-py/pull/1483

Alveel avatar Jan 31 '25 16:01 Alveel

i wonder if it makes sense to refactor out something like

def _load_policy(policy_file, policy):
        if policy and policy_file:
            raise ValueError(
                "only one of policy or policy_file may be specified")
        if not policy or not policy_file:
            raise ValueError("either policy or policy_file must be specified")
        body = ''
        if policy:
            body = json.dumps(policy)
        elif policy_file:
            with open(policy_file, encoding='utf-8') as file:
                body = file.read()
       return body

given in how many places we basically have the same code now.

darix avatar Feb 04 '25 12:02 darix

Sounds fairly sensible actually. I'll wait for feedback from a member and see what they think.

Alveel avatar Feb 04 '25 16:02 Alveel

@balamurugana please review

Alveel avatar Feb 11 '25 16:02 Alveel

I'd love to hear some feedback on the current state.

Alveel avatar Feb 13 '25 21:02 Alveel

I'd love to hear some feedback on the current state.

Please fix the CI tests

harshavardhana avatar Feb 14 '25 10:02 harshavardhana

Fixed. Moved the .open() for Path to its own line so I can put the mypy comment on the same line while keeping it within 80 characters to keep autopep8 happy.

Alveel avatar Feb 14 '25 10:02 Alveel

I think that's it? I still see "1 requested change" but I don't see where or what it is.

Do you want me to squash my commits?

Alveel avatar Feb 18 '25 20:02 Alveel

@balamurugana can you take a look? 🙂

Alveel avatar Feb 20 '25 15:02 Alveel

Apologies, that was a dumb error I introduced and insufficiently tested. Tested properly now and passing all tests.

Alveel avatar Feb 25 '25 10:02 Alveel

Squashed commits, should be all clean now. Can you please take a look?

If needed, I still have the original commits in a separate branch locally.

Alveel avatar Feb 26 '25 15:02 Alveel