Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,560 members, 7,809,044 topics. Date: Thursday, 25 April 2024 at 09:42 PM

Help On Deployment On Heroku - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help On Deployment On Heroku (1095 Views)

What Other Alternative To Heroku / Why Is Heroku Not Setting My Cookie / Help With Node.js App Deployment To Heroku (Solved!!!) (2) (3) (4)

(1) (Reply) (Go Down)

Help On Deployment On Heroku by gbolly1151(m): 3:08pm On Nov 26, 2019
When deploying django to heroku why should

(Case1)
SECRET_KEY = os.environ.get("SECRET_KEY", "YBWHGRHH"wink

INSTEAD OF

(Case2)
SECRET_KEY=os.environ['SECRET_KEY']

In my own view the secret key is been exposed in case 1 but more secured in case2
Re: Help On Deployment On Heroku by Ajibel(m): 9:27pm On Nov 26, 2019
In case 1 it means the default value you set would be used as secret key if you didn't set a SECRET KEY in heroku's env.

In case 2 because there's no default, an error will be thrown if you fail to set the key in the env

2 Likes

Re: Help On Deployment On Heroku by gbolly1151(m): 8:46am On Nov 27, 2019
Ajibel:
In case 1 it means the default value you set would be used as secret key if you didn't set a SECRET KEY in heroku's env.

In case 2 because there's no default, an error will be thrown if you fail to set the key in the env

Which one is the best?
Re: Help On Deployment On Heroku by Ajibel(m): 9:25am On Nov 27, 2019
gbolly1151:


Which one is the best?

It depends on your choice. I don't know the best, but I have used several patterns. Here is an idea of what I do with Flask:

if os.environ.get('SECRET_KEY'):
........SECRET_KEY = os.environ.get('SECRET_KEY')
else:
........SECRET_KEY = 'SECRET_KEY_ENV_VAR_NOT_SET'
........print('SECRET KEY ENV VAR NOT SET! SHOULD NOT SEE IN PRODUCTION')

But again I think to have a .env file where you set your private keys and read from it is what I have seen many open source projects do. Since you're using heroku, go through their django setup walkthrough. I believe whatever pattern they make use of there is what you should go with.

1 Like

Re: Help On Deployment On Heroku by gbolly1151(m): 12:10pm On Nov 29, 2019
Ajibel:


It depends on your choice. I don't know the best, but I have used several patterns. Here is an idea of what I do with Flask:

if os.environ.get('SECRET_KEY'):
........SECRET_KEY = os.environ.get('SECRET_KEY')
else:
........SECRET_KEY = 'SECRET_KEY_ENV_VAR_NOT_SET'
........print('SECRET KEY ENV VAR NOT SET! SHOULD NOT SEE IN PRODUCTION')

But again I think to have a .env file where you set your private keys and read from it is what I have seen many open source projects do. Since you're using heroku, go through their django setup walkthrough. I believe whatever pattern they make use of there is what you should go with.

Thanks it is really helpful

I understand that dyno is a virtual file system on which django app are served and can go off anytime, when this happen, do i need to set the config var again to start my app when dyno is on again?
Re: Help On Deployment On Heroku by Ajibel(m): 1:33pm On Nov 29, 2019
gbolly1151:


Thanks it is really helpful

I understand that dyno is a virtual file system on which django app are served and can go off anytime, when this happen, do i need to set the config var again to start my app when dyno is on again?

I haven't had any experience using heroku in this case but what I know is that since the config var you set from the start are persistent, then you wont need to set a new config var again whenever your app is restarted.

1 Like

Re: Help On Deployment On Heroku by gbolly1151(m): 4:31pm On Nov 29, 2019
Ajibel:


I haven't had any experience using heroku in this case but what I know is that since the config var you set from the start are persistent, then you wont need to set a new config var again whenever your app is restarted.

Yea thanks...got it now....after reading their doc, i knew that the config var are kept just like the source code. Whenever dyno loads, config var are set in the environment. So no need of setting the config var again
Re: Help On Deployment On Heroku by HassieMalcomson(f): 2:23pm On Oct 10, 2023
The Heroku key can only be accessed if you have exposed it to the client side. However, if your case is different, then you should approach the setting option and proceed with the config. Here, you should enable this: heroku config: set SECRET_KEY="...". Yes, the Heroku environment is considered highly secure if you keep the key secret.

On the other hand, it is also important that you follow the right method to deploy your application on Heroku. If you are using GitHub, then you can simply go with this source https://blog.back4app.com/deploy-to-heroku/ and it will answer all of your queries about deployment. Also, don't forget to utilize protected places to store keys like Heroku Config Vars and Heroku add-ons.

You should also rotate the keys to avoid unauthorized access. Hopefully, it will also help you.

(1) (Reply)

Learn How To Make Photoshop-like Graphics Designs On Your Andriod Phone! / Pygame Controls With Pydroid / Android Developers Pls Help

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.