empa-scientific-it / cscs-keygen

Python script to automate fetching SSH keys to access the CSCS infrastructure
GNU General Public License v3.0
0 stars 0 forks source link

Use dataclasses for response #2

Open baffelli opened 1 year ago

baffelli commented 1 year ago

Instead of directly accessing json, you could define a few helper dataclasses or pydantic models:

https://github.com/empa-scientific-it/cscs-keygen/blob/20b8c487deab801ab9d550ba91a00d7f9f06b99d/utils.py#L59

edoardob90 commented 1 year ago

You're suggesting something like the following?

from pydantic import BaseModel

class KeyResponse(BaseModel):
    public: str
    private: str

response_model = KeyResponse.model_validate(response.content.decode())
pub_key = response_model.public
priv_key = response_model.private
baffelli commented 1 year ago

Yes, correct. I think it's a bit safer and slightly more ergonomic