Rails CQL cannot connect to AWS Keyspaces (AWS Cassandra) - ruby-on-rails

I am trying to connect from a Ruby on Rails application to AWS Keyspaces (AWS Cassandra), but I cannot manage to do it. I use the cequel gem and generated the config/cequel.yml which contains a similar thing to the following:
development:
host: "CONTACT_POINT"
username: "USER"
password: "PASS"
port: 9142
keyspace: key_development
max_retries: 3
retry_delay: 0.5
newrelic: true
ssl: true
server_cert: 'config/certs/AmazonRootCA1.pem'
replication:
class: NetworkTopologyStrategy
datacenter1: 3
datacenter2: 2
durable_writes: false
(Credentials where used in another app and they work which is working as expected.)
when I try to run:
rake cequel:keyspace:create
I get the following errors:
Cassandra::Errors::NoHostsAvailable: All attempted hosts failed: x.xxx.xxx.xxx (Cassandra::Errors::ServerError: Internal Server Error)

Set the dc to us-east-1 . drop the replication definition.

Related

Can't connect Rails app to Postgres using PG gem

I'm trying to connect a rails app to a remote Postgres database (using the PG gem) and getting issues.
I set my database.yaml file
development:
adapter: postgresql
encoding: unicode
database: testdb
username: testuser
password: "*******"
host: **.***.***.***
port: 5432
Then in my rails controller I have this line to connect to the db
conn = PG.connect( :dbname => 'testdb' )
And I get this error in response
"status": "error",
"message": "could not connect to server: No such file or directory\n\tIs the server running locally and accepting\n\tconnections on Unix domain socket \"/var/run/postgresql/.s.PGSQL.5432\"?\n"
I was under the impression that PG would pull from the database connection loaded in rails. If I do an inspect on the db configuration I see that it's pulling the database.yaml parameters
#<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd5ae0562d0 #env_name="development", #name="primary", #configuration_hash={:adapter=>"postgresql", :encoding=>"unicode", :database=>"testdb", :username=>"testuser", :password=>"*****", :host=>"**.***.***.***", :port=>5432}>
I'm able to successfully connect though if I pass in the necessary variables or connection string to PG instead
conn = PG::Connection.new( "postgresql://testuser:*******#**.***.***.***:5432/testdb" )

Can we change connection dynamicly to Elasticsearch server on Rails App at run time

I have 2 elasticsearch servers. On my rails app, can I change connection to the Elasticsearch servers at run time?
For example,
- If user 1 log in the app, it should connect to elasticsearch server 1
- If user 2 log in the app, it should connect to elasticsearch server 2
Thanks
You can use randomize_hosts when creating connection
args = {
hosts: "https://host1.local:9091,https://host2.local:9091",
adapter: :httpclient,
logger: (Rails.env.development? || Rails.env.test?) ? Rails.logger : nil,
reload_on_failure: false,
randomize_hosts: true,
request_timeout: 5
}
client = Elasticsearch::Client.new(args)
Randomize hosts doc
Here you can read about a different host selection strategy than round robin. You could implement your own ideas.

GitLab LDAP scondary strategy

I'm using GitLab CE Omnibus package (gitlab_7.7.2-omnibus.5.4.2.ci-1_amd64) on a clean Debian (debian-7.8.0-amd64) installation.
I followed the installation process on https://about.gitlab.com/downloads/ and everything works fine.
I modified /etc/gitlab/gitlab.rb to use a single LDAP server for authentification.
Which worked also as expected.
But when I tried to use a secondary LDAP connection "gitlab-ctl reconfigure" gives me the output:
---- Begin output of /opt/gitlab/bin/gitlab-rake cache:clear ----
STDOUT:
STDERR: rake aborted!
Devise::OmniAuth::StrategyNotFound: Could not find a strategy with name `Ldapsecondary'. Please ensure it is required or explicitly set it using the :strategy_class option .
Tasks: TOP => cache:clear => environment
(See full trace by running task with --trace)
---- End output of /opt/gitlab/bin/gitlab-rake cache:clear ----
So, the problem is that I can use the LDAP connection 'main' but I cannot use the connection 'secondary'.
Is there any possibility to use two different LDAP connection in the CE edition at once?
I'm new to ruby [on rails]. I found something in /opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/ldap/config.rb but I'm not able to debug anything.
Here are my settings in /etc/gitlab/gitlab.rb
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-EOS # remember to close this block with 'EOS' below
main: # 'main' is the GitLab 'provider ID' of this LDAP server
label: 'First Company'
host: '192.168.100.1'
port: 389
uid: 'sAMAccountName'
method: 'tls' # "tls" or "ssl" or "plain"
bind_dn: 'debian#firstcompany.local'
password: 'Passw0rd'
active_directory: true
allow_username_or_email_login: false
base: 'dc=firstcompany,dc=local'
user_filter: '(&(objectClass=person)(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))'
## EE only
group_base: ''
admin_group: ''
sync_ssh_keys: false
secondary: # 'secondary' is the GitLab 'provider ID' of second LDAP server
label: 'Second Company'
host: '192.168.200.1'
port: 389
uid: 'sAMAccountName'
method: 'tls' # "tls" or "ssl" or "plain"
bind_dn: 'debian#secondcompany.local'
password: 'Passw0rd'
active_directory: true
allow_username_or_email_login: false
base: 'dc=secondcompany,dc=local'
user_filter: '(&(objectClass=person)(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))'
## EE only
group_base: ''
admin_group: ''
sync_ssh_keys: false
EOS
Thank you very much!
Multiple LDAP servers is an EE feature so setting the config in CE won't do anything. You can see the feature in GitLab documentation.
With GitLab 14.7 (January 2022, seven years later), this is now possible! (for hosted instances)
LDAP failover support
You can now specify multiple hosts (using hosts) in your GitLab LDAP configuration.
GitLab will use the first reachable host. This ensures continuity of access to GitLab should one of your LDAP hosts become unresponsive.
Thanks to Mathieu Parent for the contribution!
See Documentation and Issue.

Unable to perform queries on mongodb started with --auth switch in rails 3 with mongoid.

Simplified case:
I create a new rails 3.2 project, without active record. I add mongoid 3.0.0.rc to the Gemfile and then rails g mongoid:config. I edit my mongoid.yml to look like the one I have posted below (except that hosts is now set to localhost:27068).
I have added an admin user to mongodb:
$ mongo localhost/admin
> db.addUser(myadmin,adminpass)
Also I have added a regular user to my database:
use mydb
> db.addUser(myuser, mypassword)
I confirm that I can connect to my database:
$ mongo localhost/mydb -u myuser -pmypassword
MongoDB shell version: 2.0.4
connecting to: localhost/mydb
> _
After that, I start mongod with --auth switch to force authentication:
$ mongod --auth --dbpath /my/db/path
Now that everything seems to be OK, I create some random scaffold like:
$ rails g scaffold User name email
and try to run the project in the browser: localhost:3000/users. BOOM! I'm hit with the error message posted below.
Is this a bug in mongoid? Or am I missing something?
Original Question
I'm unable to do anything on my MongoHQ hosted database in a Rails 3.2 project with mongoid 3 rc. A simple query for login action gives me something like this error message:
The operation: #<Moped::Protocol::Query
#length=83
#request_id=3
#response_to=0
#op_code=2004
#flags=[]
#full_collection_name="mydb.users"
#skip=0
#limit=-1
#selector={"name"=>"Abbas"}
#fields=nil>
failed with error 10057: "unauthorized db:mydb lock type:-1 client [some ip]"
Here's what my mongoid.yml looks like:
development:
sessions:
default:
database: mydb
user: myuser
password: mypassword
hosts:
- flame.mongohq.com:27068
options:
consistency: :strong
options:
include_type_for_serialization: true
So I'm doing it the wrong way. The db user is not marked as "Read-only" in MongoHQ panel. And I'm NOT deploying to Heroku; just testing on my localhost.
Any help is appreciated.

how to set Seamless database pool read slave database as default?

I have problem with seamless gem
development:
adapter: jdbcmysql
database: mydb_development
username: read_user
password: abc123
pool_adapter: jdbcmysql
port: 3306
master:
host: master-db.example.com
port: 6000
username: master_user
password: 567pass
read_pool:
- host: read-db-1.example.com
pool_weight: 2
- host: read-db-2.example.com
it should read for slave right [read-db-1.example.com] ? but it was weird.. it always read to master database [mydb_development] .
do you have any suggestion, how should i do to configure this gem for default read to slave database?
Thank you
Specify pool_weight=0 in the master configuration
By default, the master connection will be included in the read pool. If you would like to dedicate this connection only for write operations, you should set the pool weight to zero.
seam_leass_database_pool plugin

Resources