Using AWS DocumentDB with Sail.js configuration - node.js

I'm trying to use AWS DocumentDB which is MongoDB compatible but unable successfully connect to the database.
Are there are any additional parameters that I need to pass into Sails.js datastores.js configuration?
Currently, my configs are as following:
adapter: 'sails-mongo',
url: 'mongodb://*****:*****#********.cluster-dasdsasd.us-east-1.docdb.amazonaws.com:27017/?ssl_ca_certs=rds-combined-ca-bundle.pem&replicaSet=rs0',

Looking at Sails, i would suggest disable TLS in DocumentDB[1] and try connecting. I suspect that should fix the issue for you. I am wondering if it is able to find the pem file on you applications path (This part of URL - ?ssl_ca_certs=rds-combined-ca-bundle.pem)
[1] https://docs.aws.amazon.com/documentdb/latest/developerguide/security.encryption.ssl.html

Related

auth0 custom DB connection Postgres Connection Error

We are using auth0 for user authentication & authorization, and configured custom DB with postgresDB.
Auth0 account is using node 16 as runtime engine for running custom DB scripts.
Loaded postgres template and modified with required changes.
When testing the script, it was giving error saying postgres.connection is not a function.
The same code works well for other account which have node 12 as runtime.
Any suggestions?
This is common issue when using old version of pg.
Latest pg version supported in Auth0 is 8.7.1
Ref: https://auth0-extensions.github.io/canirequire/#pg
So you can update the statement
require('pg')
to
require('pg#8.7.1')
Also please refere https://node-postgres.com/apis/client for correct way to use the Client from pg.

Configuring Azure PostgreSQL in Gitlab EE

I am searching for some help in how to configure Azure PostgreSQL DB in a Docker Swarm based Gitlab instance.
Initially, I followed the documentation in https://docs.gitlab.com/13.6/ee/administration/postgresql/external.html. Yet I came to find out that the default provided user is in the form of username, whereas Azure requires it to be in the form of username#hostname. I tried passing the username in the gitlab.rb file (gitlab_rails['db_username'] = 'username#hostname') but it still failed, even after replacing the # with the %40 as URI encoded.
After some extensive searching, I found this documentation - https://docs.gitlab.com/13.6/ee/administration/environment_variables.html, which suggests using the DATABASE_URL environment variable to set the full connection string in the form postgresql://username:password#hostname:port/dbname, which I did and it did solve the issue for Gitlab itself communicating with Azure PostgreSQL (in this case I replaced the username with username%40hostname, according to Azure requirements).
Allas, the success was short lived since then I came to find out that neither Puma and Sidekiq can connect to the database, always throwing the following error:
==> /var/log/gitlab/sidekiq/current <==
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432"?
After some searching, I found that gitlab-ctl is generating the following file when starting the Gitlab instance:
# This file is managed by gitlab-ctl. Manual changes will be
# erased! To change the contents below, edit /etc/gitlab/gitlab.rb
# and run `sudo gitlab-ctl reconfigure`.
production:
adapter: postgresql
encoding: unicode
collation:
database: <database>
username: "<username>"
password:
host: "/var/opt/gitlab/postgresql"
port: 5432
socket:
sslmode:
sslcompression: 0
sslrootcert:
sslca:
load_balancing: {"hosts":[]}
prepared_statements: false
statement_limit: 1000
connect_timeout:
variables:
statement_timeout:
(database and username where removed)
Pretty much it ignores the DATABASE_URL env variable and assumes the now non-existing configuration parameters in gitlab.rb.
So, right now, I'm a bit out of options and was wondering if anyone has had a similar issue and, if so, how where you able to overcome this.
Any help is appreciated.
Thanks in advance.
TL/DR: Pass the username#hostname string directly into the gitlab_rails['db_username'] in double quotes. The documentation for connecting to an Azure PostgreSQL in the official Gitlab page is not correct.
So, after some searching and going deep into the Gitlab configuration, I came to find out that the issue is very specific and related with the usage of docker secrets.
In my gitlab.rb configuration file, in the database configuration part, I'm using the following:
### GitLab database settings
###! Docs: https://docs.gitlab.com/omnibus/settings/database.html
###! **Only needed if you use an external database.**
gitlab_rails['db_adapter'] = "postgresql"
gitlab_rails['db_encoding'] = "unicode"
gitlab_rails['db_database'] = File.read('/run/secrets/postgresql_database')
gitlab_rails['db_username'] = File.read('/run/secrets/postgresql_user')
gitlab_rails['db_password'] = File.read('/run/secrets/postgresql_password')
gitlab_rails['db_host'] = File.read('/run/secrets/postgresql_host')
gitlab_rails['db_port'] = File.read('/run/secrets/postgresql_port')
gitlab_rails['db_sslmode'] = 'require'
Now, this exact configuration was used previously for testing purposes and worked (but without the usage of Azure PostgreSQL database). And I'm passing the correct secrets to docker and I've confirmed that the secrets in fact, do exist.
(Sidenote: Also, I've established that Gitlab uses the method ActiveRecord::Base.establish_connection from the Ruby ActiveRecord::Base library in order to connect to the database)
Yet, when using the username#hostname configuration for the user and passing that into the postgresql_user secret, suddenly the ActiveRecord::Base.establish_connection method assumes that the #hostname is the actual hostname to where I want to connect to. And I've confirmed that the secret is being generated correctly inside the docker container
Now, it gets even stranger because if I pass the username#hostname string directly to the gitlab.rb file - gitlab_rails['db_username'] parameter - in double quotes, it suddenly starts connecting without complaining.
So, in short, if using an Azure PostgreSQL database for a dockerized Gitlab instance and using secrets to pass the configuration to the gitlab.rb file, don't pass the username#hostame through a secret, but put it directly in the gitlab.rb file.
I don't know if this is a specific issue of Ruby or of Gitlab (I'm not a Ruby developer), but I did try converting the File.read output to a String, to a symbol, used the File.open('filepath', &:readline) and other shenanigans, but nothing worked. So, if anyone out there would care to add their reason for this, please feel free to do so.
Also, the tutorial provided by Azure - https://learn.microsoft.com/pt-pt/azure/postgresql/connect-ruby - doesn't work with Gitlab, since it complains about the %40.
Hope this can help anyone out there.

How to define a New SailJS Session Store

Can anyone provide me reference or sample code on how to define a Custom Sessions Store in SailsJS. Currently, only MongoDB and Redis are provided, but I would like to use Disk as a Session Adapter on development environment.
Ok, so I found one: https://www.npmjs.com/package/session-file-store
Here is what needs to be done in config/session.js
adapter: 'session-file-store'
Other configuration options as required

How to use the ChromeApp to connect to a node.js server?

I have a Node.js server and I'd like to know how I could do for the ChromeApp to work with it. I tried putting "http://localhost:3000" (server address) on the runtime:
chrome.app.runtime.onLaunched.addListener(function () {
chrome.app.window.create('http://localhost:3000');
});
But it doesn't even launch. Does someone have an idea on what I could do?
Thanks.
You cannot launch external URLs with chrome.app.window.create. In fact if you check the chrome.runtime.lastError property you will see the following error:
The URL used for window creation must be local for security reasons.
I suggest you look into using the <webview> tag as it is much more appropriate for your use-case.

Couchbase - Unable to store key and value though bucket is connected to successfully

I've been trying to set up a Couchbase server. But unable to store any value and value.
Following Couchbase manual, I simply install Couchbase, refer the Couchbase Client .NET (Enyim.Caching) into project, then re-configure Couchbase section in app setting with my local pool url (http://local:8091/pools).
I can though connect to connect to bucket through set up CouchbaseClient and CouchbaseClientConfiguration, but unable to store any key-value after that (by .Store(StoreMode.Set, key, value) always returns false).
Any help will be appreciated.
Could you confirm that your local pool URL is http://localhost:8091/pools/default and not http://local:8091/pools? Also, what are the versions of the server and client that you're using?
Thanks.

Resources