Slyplayer8990 / cloud-i

BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

optimizations / reducing amount of code written #10

Closed bedros-p closed 1 year ago

bedros-p commented 1 year ago

https://github.com/Slyplayer8990/cloudy/blob/3289fbd1e618223e23011e3c78061933e2dafb5d/app.py#L22-L33 Suggestion

requiredjson = set(["instance_name", "image", "username", "storage", "memory", "vcpu", "access_key"])
setrequest = set(request.json)

if requiredjson.issubset(setrequest):
    #code here
    pass

alternatively use get() to ensure those fields always have a value do not unpack the whole dict into its own variables - use the dict as a dict unsure if there's a way to set mandatory body fields in flask, look into that as well if you'd like