foreman not getting environment variables - ruby-on-rails

I'm using foreman for the environment variables in a rails app. On my config/enviroments/development.rb I have the following code:
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: "587",
domain: "gmail.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV['GMAIL_USERNAME'],
password: ENV['GMAIL_PASSWORD']
#user_name: "user#gmail.com",
#password: "password"
}
and my .env file is as follows:
GMAIL_USERNAME=user#gmail.com
GMAIL_PASSWORD=password
and my Procfile is:
web: bundle exec rvmsudo rails s -p 80
So if I run "foreman start", I get the following message:
Net::SMTPAuthenticationError in Devise::ConfirmationsController#create
530-5.5.1 Authentication Required
However if I comment the lines that concern the environment variables and uncomment the ones that are commented right now at development.rb, everything works fine.
So I imagine the problem is that foreman is not getting the environment variables correctly.
I'm using git with branches, and ignoring both Procfile and .env
Is there anything wrong with my code?

Looks like the environment variables are not being set. Which method are you using to do that?
Here's an article that explains several methods.
Try setting them manually on the command line thus:
export GMAIL_USERNAME="user#gmail.com"
export GMAIL_PASSWORD="password"
Then type env at the command prompt to verify they are set. Then give it a whirl.

Related

Incorrect credentials response in Rails 6

Rails 6
I created the credentials file, as follows:
EDITOR=vi rails credentials:edit
production:
mysql:
db: acme-production
user: deploy
password: xxxxxxxxxxxx
smartagent:
token: lnroftb7sgr8c7f1ogqvij24xl
test:
mysql:
db: acme-test
user: deploy
password: xxxxxxxxxxxx
smartagent:
token: lnroftb7sgr8c7f1ogqvij24xl
secret_key_base: xxxxxxxxxxxxxx
master.key is in the correct place (in the config folder, locally, and as an environment setting on the server).
I am having trouble with the smartagent token.
When I do:
rails c
and
Rails.application.credentials.dig(Rails.env.to_sym, :mysql, :db)
I get:
=> "acme-test"
However, when I do:
Rails.application.credentials.dig(Rails.env.to_sym, :smartagent, :token)
I get:
=> nil
Any idea why this might be happening?
Solution:
I deleted the credentials file, re-populated it, and restarted the Rails app. That fixed the problem, so this must have been either an indentation issue (spaces vs tabs), or that the server had not restarted properly, after earlier changes were made

How To Get The Value Of An Environment Variable In Elixir On Windows?

Windows 10
Elixir 1.3.1
Per the advice in this article, I've tried to modify my config files to use the "${ENV_VAR}" syntax. But then when I try to compile the code Elixir complains about the values of the configuration settings. So I tried the syntax directly in iex and it doesn't seem to work.
iex(1)> "${PATH}"
"${PATH}"
iex(2)> System.get_env("PATH")
"C:\\Program Files\\erl8.0\\erts-8.0\\bin;C: . . ." (rest omitted for brevity's sake)
I'd really like to use the "${ENV_VAR}" notation because it'd be nice to not have to hand-edit the sys.config file. Am I doing something wrong or is this just a Windows specific issue?
Here's part of my config file (even though, as I say, it seems I can reproduce the behavior in iex):
config :riismi, ecto_repos: [Riismi.Repo]
config :riismi, Riismi.Mailer,
adapter: Bamboo.SMTPAdapter,
server: "smtp.gmail.com",
port: 465,
username: "${RMI_MAIL_SERVERUSER}",
password: "${RMI_MAIL_SERVERPWD}",
tls: :if_available, # can be `:always` or `:never` or `:if_available`
ssl: true, # can be `true`
retries: 3
As I say, I realize this is likely to be a Windows issue--just wanted to insure that I'm not missing something otherwise.

smtp configuration for custom gmail address

For my rails application, i have configured my gmail address as a gateway to send emails, i did this and it was working fine (normal gmail) :
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.com',
user_name: 'example#gmail.com',
password: 'password',
authentication: 'plain',
enable_starttls_auto: true }
But today, i created a custom email in gmail (contact#mydomain.ma).
So i did the same configuration beside confirming that the domain is mine:
1 - Enable Forwarding and POP/IMAP
2 - Enable access of less secure apps
and for the rails configuration, i did the following:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'mydomain.ma',
user_name: 'contact#mydomain.ma',
password: 'password',
authentication: 'plain',
enable_starttls_auto: true }
Infortunately, i get this error :
Net::SMTPAuthenticationError at /fr/emails
534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbtx
I'm sure that the error cames from the rails configuration, any help?
Thanks!
Not sure for port, but AFAIR gmail uses 465 SSL port. Have you tried port 465?
Also check this article http://docs.helpscout.net/article/120-smtp-settings
There's info that sometimes google treats some apps for 'less secure' and requires more setup.
I've put in my credentials correctly, but I keep receiving a 5.7.14
error when I test the connection. Help! This means Gmail is trying to
properly authenticate your credentials through Help Scout. In some
cases, you have to ask Gmail to allow less secure apps in order for
this to do the trick. If it's still acting wonky, head over to this
link, follow the instructions, and then head back into Help Scout and
retry the Test Connection button in your connection settings.
Check this links:
https://support.google.com/accounts/answer/6010255?hl=en
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Hope this helps.

gitlab can not send email via smtp

Can I skip the email confirmation step and enable the user ?
I followed by https://github.com/gitlabhq/gitlabhq/blob/6-4-stable/doc/install/installation.md
followed by each step.
But I can not get email confirmation so that no user can be confirmed.
Then I run the server by rails s -p 1987 -e production on the port 1987
The identical setting, I can receive email by my own rails app on other machines,
it's annoying me very much.
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.7.8
Checking Environment ...
Git configured for git user? ... yes
Checking Environment ... Finished
Checking GitLab Shell ...
GitLab Shell version >= 1.9.3 ? ... OK (1.9.3)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
Satellites access is drwxr-x---? ... yes
update hook up-to-date? ... yes
update hooks in repos are links: ... can't check, you have no projects
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Check directories and files:
/home/git/repositories: OK
/home/git/.ssh/authorized_keys: OK
Test redis-cli executable: redis-cli 2.2.12
Send ping to redis server: PONG
gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
Database contains orphaned UsersGroups? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... yes
projects have namespace: ... can't check, you have no projects
Projects have satellites? ... can't check, you have no projects
Redis version >= 2.0.0? ... yes
Your git bin path is "/usr/local/bin/git"
Git version >= 1.7.10 ? ... yes (1.8.5)
Checking GitLab ... Finished
production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
:address => "74.125.129.109",
# :address => "smtp.gmail.com",
:port => 587,
:domain => "localhost",
:authentication => 'plain',
:user_name => XXX,
:password => XXX,
:enable_starttls_auto => true,
:openssl_verify_mode => 'none'
}
Don't know how to skip email confirmation and enable user, but with gitlab 6.7.5 these are my smtp settings (for icloud email server. Make sure you have logged in first into iCloud's web-email app, at least once):
file: /Users/git/gitlab/config/initializers/smtp_settings.rb
# To enable smtp email delivery for your GitLab instance do next:
# 1. Rename this file to smtp_settings.rb
# 2. Edit settings inside this file
# 3. Restart GitLab instance
#
if Rails.env.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.mail.me.com",
port: 587,
user_name: "youraccount#icloud.com",
password: "yourpasswd",
domain: "me.com",
authentication: "plain",
enable_starttls_auto: true
}
end
Also remember to change the email_from attrbiute in your gitlab.yml file:
file: /Users/git/gitlab/config/gitlab.yml
## Email settings
# Email address used in the "From" field in mails sent by GitLab
email_from: youraccount#icloud.com
After changing the smtp file, restart the gitlab service.
Hope this helps.
Cheers,

Trouble Getting s3 set up in Rails 3 Refinery CMS App

I'm trying to get my refinery cms image storage to Amazon s3 and I'm following this guide:
http://refinerycms.com/guides/how-to-use-amazon-s3-for-storage
But I'm blocked here:
There are a number of ways to set
these with your credentials, including
unix variables or settings them
manually through Ruby using ENV.
How do I define these credentials. Do I put something like :S3_KEY =>
"my_key" in my environments.rb file? I tried this and it didn't work.
I also tried this:
AWS::S3::Base.establish_connection!(
:access_key_id => ENV['S3_KEY'] || 'key_goes_here',
:secret_access_key => ENV['S3_SECRET'] || 's3_secret_key_here',
)
Can't figure out how to do this. Any ideas are greatly appreciated.
The safest way is to specify them as environment variables, so they aren't included in your source code. If you're the only one with access to the source, then specifying them as you describe should work.
You can specify them in your ~/.bashrc
export S3_KEY=mykey
export S3_SECRET=mysecret
Or if you're just testing locally you can prepend them to your rails command.
$ S3_KEY=mykey S3_SECRET=mysecret rails server
If you don't want to/can't use environment variables, another method is to use an initializer to load credentials from a yml file: config/initializers/s3_credentials.rb
# Load AWS::S3 configuration values
#
S3_CREDENTIALS = \
YAML.load_file(File.join(Rails.root, 'config/s3_credentials.yml'))[Rails.env]
# Set the AWS::S3 configuration
#
AWS::S3::Base.establish_connection! S3_CREDENTIALS['connection']
config/s3_credentials.yml
development: &defaults
connection:
:access_key_id: AAAAAA_your-key-here
:secret_access_key: 4rpsi235js_your-secret-here
:use_ssl: true
bucket: project-development
acl: public-read
production:
<<: *defaults
bucket: project

Resources