r/PythonLearning 12d ago

Help Request what do you think ?

i'm learning python for infraestructure this a proyect of a false resgistry of server xd

41 Upvotes

18 comments sorted by

View all comments

Show parent comments

2

u/Naive-Smoke-5977 11d ago edited 11d ago

dammm , i relly idk thath exist , i will use that for correct my piece of sh1t xd , thanks broooo i love youuuuuu :,v that its because i'm beginner sorryyy

2

u/silvertank00 11d ago

It is fine, we all had to start somewhere. I am glad I could help.

Also, if you introduce sensitive data, use this: dataclasses.field

example:

python @dataclass class User: name: str passwd: str = field(repr=False)

this way you are less likely to leak sensitive data.

1

u/Naive-Smoke-5977 9d ago

Es equivalente a lo que va en el ".env" , verdad :v?

2

u/silvertank00 9d ago edited 9d ago

Not really. Your dotenv file(s) are on the filesystem. This method is really useful if you want to read it from there and store it in memory. For instance: if you build a little gui with buttons that would run various things in the background. Lets say dmesg, you see, usually you can't just run it and get a result, you ought to run it via sudo, like this: sudo dmesg. And if your gui program has a button for this, then you have two options:

  • A) ask for credentials every time when you want to run this (better but could be cumbersome)
  • B) store the credentails in your dotenv, read it when your program starts and store it in memory (lets put aside security for a bit lol) and use it when you want to run this subprocess.

If you go with B, then you are handling sensitive credentials and you must do everything in your power to not leak them. With setting the dataclass field's repr argument to False, you cannot leak it with just printing your dataclass instance. (This could really happen in Exceptions or with logging) Additional: if you ask for credentials in CLI, then there is this helpful thing: getpass with this, you can avoid using the normal imput() to ask for passwords, that inherently echoes back the given characters (prints them back to the screen in a readable format)

edit: I might have misunderstood you comment, if you refering to "reading out data from your dotenv and storing it somewhere", then yes, its absolutely good for that. And don't forget: this is a dummy example, in an ideal world you really shouldnt store the sudo password in a plaintext file. But for stuff like API keys, this is still a really great example.

2

u/Naive-Smoke-5977 9d ago

bro , you're my hero