python, can't import Google Cloud Pub/Sub package - python-3.5

My script work normally, but the error occur when I run it on the docker.
app_1 | from google.cloud import pubsub
app_1 | File "/usr/local/lib/python3.5/site-packages/google/cloud/pubsub/__init__.py", line 30, in <module>
app_1 | from google.cloud.pubsub.client import Client
app_1 | File "/usr/local/lib/python3.5/site-packages/google/cloud/pubsub/client.py", line 19, in <module>
app_1 | from google.cloud.client import ClientWithProject
app_1 | ImportError: cannot import name 'ClientWithProject'
In docker requirement, I added google-cloud-pubsub==0.23.0

Related

React-Monaco Editor: Tree-Sitter resolution errors using NodeParserAdapter in React project

I'm trying to use the #cucumber/monaco editor library in a React project which uses tree-sitter for NodeParserAdapter but I'm getting a bunch of resolve errors in the tree-sitter when I do this. I'm importing the NodeParserAdapter, not the WasmParserAdapter from the cucumber/language-service as we aren't using WebAssembly in our project.
Environment: Node v16.17.1 (Docker Image 16.17)
Error Log:
[0]
[0] Search for the keywords to learn more about each warning.
[0] To ignore, add // eslint-disable-next-line to the line before.
[0]
[0] WARNING in ./node_modules/tree-sitter-c-sharp/bindings/node/index.js 2:2-77
[0] Module not found: Error: Can't resolve '../../build/Release/tree_sitter_c_sharp_binding' in '/usr/src/my_project/node_modules/tree-sitter-c-sharp/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-c-sharp/bindings/node/index.js 9:4-77
[0] Module not found: Error: Can't resolve '../../build/Debug/tree_sitter_c_sharp_binding' in '/usr/src/my_project/node_modules/tree-sitter-c-sharp/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-java/bindings/node/index.js 2:2-74
[0] Module not found: Error: Can't resolve '../../build/Release/tree_sitter_java_binding'
in '/usr/src/my_project/node_modules/tree-sitter-java/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-java/bindings/node/index.js 9:4-74
[0] Module not found: Error: Can't resolve '../../build/Debug/tree_sitter_java_binding' in '/usr/src/my_project/node_modules/tree-sitter-java/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-php/index.js 2:2-69
[0] Module not found: Error: Can't resolve './build/Release/tree_sitter_php_binding' in '/usr/src/my_project/node_modules/tree-sitter-php'
[0]
[0] WARNING in ./node_modules/tree-sitter-php/index.js 5:4-69
[0] Module not found: Error: Can't resolve './build/Debug/tree_sitter_php_binding' in '/usr/src/my_project/node_modules/tree-sitter-php'
[0]
[0] WARNING in ./node_modules/tree-sitter-python/bindings/node/index.js 2:2-76
[0] Module not found: Error: Can't resolve '../../build/Release/tree_sitter_python_binding' in '/usr/src/my_project/node_modules/tree-sitter-python/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-python/bindings/node/index.js 9:4-76
[0] Module not found: Error: Can't resolve '../../build/Debug/tree_sitter_python_binding'
in '/usr/src/my_project/node_modules/tree-sitter-python/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-ruby/bindings/node/index.js 2:2-74
[0] Module not found: Error: Can't resolve '../../build/Release/tree_sitter_ruby_binding'
in '/usr/src/my_project/node_modules/tree-sitter-ruby/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-ruby/bindings/node/index.js 9:4-74
[0] Module not found: Error: Can't resolve '../../build/Debug/tree_sitter_ruby_binding' in '/usr/src/my_project/node_modules/tree-sitter-ruby/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-typescript/bindings/node/index.js 2:2-80
[0] Module not found: Error: Can't resolve '../../build/Release/tree_sitter_typescript_binding' in '/usr/src/my_project/node_modules/tree-sitter-typescript/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter-typescript/bindings/node/index.js 9:4-80
[0] Module not found: Error: Can't resolve '../../build/Debug/tree_sitter_typescript_binding' in '/usr/src/my_project/node_modules/tree-sitter-typescript/bindings/node'
[0]
[0] WARNING in ./node_modules/tree-sitter/index.js 4:12-66
[0] Module not found: Error: Can't resolve './build/Release/tree_sitter_runtime_binding' in '/usr/src/my_project/node_modules/tree-sitter'
[0]
[0] WARNING in ./node_modules/tree-sitter/index.js 7:14-66
[0] Module not found: Error: Can't resolve './build/Debug/tree_sitter_runtime_binding' in
'/usr/src/my_project/node_modules/tree-sitter'
[0]
[0] webpack compiled with 14 warnings
Tree Sitter and the other tree-sitter-c-sharp, tree-sitter-java etc are all installed and in the node_modules directory of the project.
tree-sitter
tree-sitter-c-sharp
tree-sitter-cli
tree-sitter-java
tree-sitter-php
tree-sitter-python
tree-sitter-ruby
tree-sitter-typescript
And when I look in the tree-sitter/build/Release I can see the tree_sitter_runtime_binding.node file
root#abc123:/usr/src/my_project/node_modules/tree-sitter/build/Release# ls
obj.target tree_sitter.a tree_sitter_runtime_binding.node
So why can't tree-sitter resolve it?
Have tried Node 18, that didn't work, tried running the build command directly from the node_modules/tree-sitter directory, didn't work, have tried installing tree-sitter in a new folder on it's own and getting the same error. Any help much appreciated.
✅ What did you expect to see?
The tree-sitter package to resolve correctly and for the Monaco editor to work with the #cucumber/monaco library.
📦 Which tool/library version are you using?
+-- #cucumber/monaco#0.11.0
| +-- #cucumber/language-service#0.32.0
| | +-- #cucumber/cucumber-expressions#16.0.0
| | +-- #cucumber/gherkin-utils#8.0.0
| | +-- #cucumber/gherkin#24.0.0
| | +-- #cucumber/messages#19.1.4
| | +-- #types/js-search#1.4.0
| | +-- #types/mustache#4.2.1
| | +-- fuse.js#6.6.2
| | +-- js-search#2.0.0
| | +-- mustache#4.2.0
| | +-- tree-sitter-c-sharp#0.19.1
| | +-- tree-sitter-cli#0.20.6
| | +-- tree-sitter-java#0.19.1
| | +-- tree-sitter-php#0.19.0
| | +-- tree-sitter-python#0.20.1
| | +-- tree-sitter-ruby#0.19.0
| | +-- tree-sitter-typescript#0.20.1
| | +-- tree-sitter#0.20.0
| | +-- vscode-languageserver-types#3.17.2
| | `-- web-tree-sitter#0.20.5
| +-- monaco-editor#0.33.0
| `-- vscode-languageserver-types#3.17.2
Node.js 16.17.1, tried with later versions of Node but to no success.
React 18.2
🔬 How could we reproduce it?
Steps to reproduce the behavior:
Start a node:16.17 Docker container
Create a React project using the Create React App template
Install the Monaco editor library and #cucumber/monaco library
Create a TestEditor.jsx file
Import the NodeParserAdapter into the file
Bug should reproduce
Below is the code snippet I'm trying to run.
import React from 'react'
// Import the components
import VerticalNav from '../../components/navbar/VerticalNav'
import HorizontalNav from '../../components/navbar/HorizontalNav'
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
import MonacoEditor from '#monaco-editor/react'
import { configureMonaco } from '#cucumber/monaco'
import { ParameterTypeRegistry } from '#cucumber/cucumber-expressions'
import {
buildSuggestions,
ExpressionBuilder,
jsSearchIndex,
} from '#cucumber/language-service'
import { NodeParserAdapter } from '#cucumber/language-service/node'
import { render } from 'react-dom'
const value = `#foo
Feature: Hello
Scenario: Hi
Given I have 58 cukes in my belly
And this is an undefined step
| some | poorly |
| formatted | table |
`
async function Editor() {
monaco.languages.register({ id: 'typescript' })
const sources = [
{
languageName: 'java',
uri: 'file:///tmp/StepDefinitions.java',
content: `class StepDefinitions {
#Given("I have {int} cukes in my belly" )
void method1() {
}
#Given("there are {int} blind mice")
void method2() {
}
#Given("there is/are some/none/1 apple(s)")
void method2() {
}
}
`,
},
]
const adapter = new NodeParserAdapter('.')
await adapter.init()
const expressionBuilder = new ExpressionBuilder(adapter)
const { expressionLinks } = expressionBuilder.build(sources, [])
const expressions = expressionLinks.map((link) => link.expression)
const registry = new ParameterTypeRegistry()
const docs = buildSuggestions(
registry,
[
'I have 42 cukes in my belly',
'I have 96 cukes in my belly',
'there are 38 blind mice',
],
expressions,
)
const index = jsSearchIndex(docs)
return configureMonaco(monaco, index, expressions)
}
export default function EditorElement() {
const options = {
value,
language: 'gherkin',
theme: 'vs-dark',
// semantic tokens provider is disabled by default
'semanticHighlighting.enabled': true,
}
Editor()
.then((configureEditor) => {
// #ts-ignore
console.log('Hello World')
render(
<MonacoEditor
height="90vh"
options={options}
className="editor"
configure={configureEditor}
/>,
document.getElementById('editor'),
)
})
.catch((err) => console.error(err.stack))
return (
<>
<div className="flex">
<VerticalNav />
<div className="h-screen flex-1">
<HorizontalNav />
<div className="pt-9 w-[90%] m-auto">
<div id="editor"></div>
</div>
</div>
</div>
</>
)
}
I tried following the example in the try folder, just replacing the WasmParserAdapter with the NodeParserAdapter but then I couldn't get any further with the resolve errors.
Not sure if this is a problem with the tree-sitter library or a React project configuration problem. Tried a few solutions online but nothing seems to work. Any advice or help is much appreciated

SSL Error accessing azure datastore for Azure Auto ML

I am implementing Azure AutoML dashboard in a docker container.
When I access container without Docker it works. But in docker it gives SSL Error.
def upload_dataset_to_blob(ws):
datastore = ws.get_default_datastore()
datastore.upload_files(files=[
'/usr/src/mediafiles/train.csv'], target_path='beeeerrr-dataset/tabular/', overwrite=True, show_progress=True)
datastore.upload_files(files=[
'/usr/src/mediafiles/valid.csv'], target_path='beeeerrr-dataset/tabular/', overwrite=True, show_progress=True)
datastore.upload_files(files=[
'/usr/src/mediafiles/test.csv'], target_path='beeeerrr-dataset/tabular/', overwrite=True, show_progress=True)
train_dataset = Dataset.Tabular.from_delimited_files(
validate=False,
path=[(datastore, 'beeree-dataset/tabular/train.csv')])
valid_dataset = Dataset.Tabular.from_delimited_files(
validate=False,
path=[(datastore, 'beeree-dataset/tabular/valid.csv')])
test_dataset = Dataset.Tabular.from_delimited_files(
path=[(datastore, 'beeree-dataset/tabular/test.csv')])
return train_dataset, valid_dataset, test_dataset
This is the error I am getting
Uploading an estimated of 1 files
app_1 | Uploading /usr/src/mediafiles/train.csv
app_1 | Uploaded /usr/src/mediafiles/train.csv, 1 files out of an estimated total of 1
app_1 | Uploaded 1 files
app_1 | Uploading an estimated of 1 files
app_1 | Uploading /usr/src/mediafiles/valid.csv
app_1 | Uploaded /usr/src/mediafiles/valid.csv, 1 files out of an estimated total of 1
app_1 | Uploaded 1 files
app_1 | Uploading an estimated of 1 files
app_1 | Uploading /usr/src/mediafiles/test.csv
app_1 | Uploaded /usr/src/mediafiles/test.csv, 1 files out of an estimated total of 1
app_1 | Uploaded 1 files
app_1 | <bound method DataReference._get_normalized_path of $AZUREML_DATAREFERENCE_blob_test_data>
app_1 | Internal Server Error: /azureml/train/
app_1 | Traceback (most recent call last):
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/data/dataset_error_handling.py", line 65, in _validate_has_data
app_1 | dataflow.verify_has_data()
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/dataprep/api/_loggerfactory.py", line 206, in wrapper
app_1 | return func(*args, **kwargs)
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/dataprep/api/dataflow.py", line 875, in verify_has_data
app_1 | if len(self.take(1)._to_pyrecords()) == 0:
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/dataprep/api/dataflow.py", line 792, in _to_pyrecords
app_1 | self._engine_api.execute_anonymous_activity(
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/dataprep/api/_aml_helper.py", line 38, in wrapper
app_1 | return send_message_func(op_code, message, cancellation_token)
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/dataprep/api/engineapi/api.py", line 120, in execute_anonymous_activity
app_1 | response = self._message_channel.send_message('Engine.ExecuteActivity', message_args, cancellation_token)
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/dataprep/api/engineapi/engine.py", line 291, in send_message
app_1 | raise_engine_error(response['error'])
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/dataprep/api/errorhandlers.py", line 10, in raise_engine_error
app_1 | raise ExecutionError(error_response)
app_1 | azureml.dataprep.api.errorhandlers.ExecutionError:
app_1 | Error Code: ScriptExecution.DatastoreResolution.Unexpected
app_1 | Failed Step: XXXXXXXXXXXXXXXXXXXXXXXXX
app_1 | Error Message: ScriptExecutionException was caused by DatastoreResolutionException.
app_1 | DatastoreResolutionException was caused by UnexpectedException.
app_1 | Unexpected failure making request to fetching info for Datastore 'workspaceblobstore' in subscription: 'XXXXXXXXXXXXXXXXXXXXXXXXX', resource group: 'django-env', workspace: 'ml-demo-main'. Using base service url: https://centralus.experiments.azureml.net. HResult: 0x80131501.
app_1 | The SSL connection could not be established, see inner exception.
app_1 | | session_id=XXXXXXXXXXXXXXXXXXXXXXXXX
app_1 |
app_1 | During handling of the above exception, another exception occurred:
app_1 |
app_1 | Traceback (most recent call last):
app_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
app_1 | response = get_response(request)
app_1 | File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
app_1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
app_1 | File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
app_1 | return self.dispatch(request, *args, **kwargs)
app_1 | File "/usr/local/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
app_1 | return handler(request, *args, **kwargs)
app_1 | File "/usr/src/app/azure_ml/views.py", line 50, in get
app_1 | azureml_train1()
app_1 | File "/usr/src/app/azure_ml/rough.py", line 39, in azureml_train1
app_1 | train_dataset, valid_dataset, test_dataset = upload_dataset_to_blob(ws)
app_1 | File "/usr/src/app/utils/azure_ml/dataset.py", line 28, in upload_dataset_to_blob
app_1 | train_dataset = Dataset.Tabular.from_delimited_files(
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/data/_loggerfactory.py", line 126, in wrapper
app_1 | return func(*args, **kwargs)
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/data/dataset_factory.py", line 322, in from_delimited_files
app_1 | dataflow = _transform_and_validate(
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/data/dataset_factory.py", line 966, in _transform_and_validate
app_1 | _validate_has_data(dataflow, 'Cannot load any data from the specified path. '
app_1 | File "/usr/local/lib/python3.8/site-packages/azureml/data/dataset_error_handling.py", line 68, in _validate_has_data
app_1 | raise DatasetValidationError(error_message + '\n' + e.compliant_message, exception=e)
app_1 | azureml.data.dataset_error_handling.DatasetValidationError: DatasetValidationError:
app_1 | Message: Cannot load any data from the specified path. Make sure the path is accessible and contains data.
app_1 | ScriptExecutionException was caused by DatastoreResolutionException.
app_1 | DatastoreResolutionException was caused by UnexpectedException.
app_1 | Unexpected failure making request to fetching info for Datastore 'workspaceblobstore' in subscription: 'XXXXXXXXXXXXXXXXXXXXXXXXX', resource group: 'django-env', workspace: 'ml-demo-main'. Using base service url: https://centralus.experiments.azureml.net. HResult: 0x80131501.
app_1 | Failed due to inner exception of type: HttpRequestException
app_1 | | session_id=XXXXXXXXXXXXXXXXXXXXXXXXX
app_1 | InnerException None
app_1 | ErrorResponse
app_1 | {
app_1 | "error": {
app_1 | "code": "UserError",
app_1 | "message": "Cannot load any data from the specified path. Make sure the path is accessible and contains data.\nScriptExecutionException was caused by DatastoreResolutionException.\n DatastoreResolutionException was caused by UnexpectedException.\n Unexpected failure making request to fetching info for Datastore 'workspaceblobstore' in subscription: 'XXXXXXXXXXXXXXXXXXXXXXXXX', resource group: 'django-env', workspace: 'ml-demo-main'. Using base service url: https://centralus.experiments.azureml.net. HResult: 0x80131501.\n Failed due to inner exception of type: HttpRequestException\n| session_id=XXXXXXXXXXXXXXXXXXXXXXXXX"
app_1 | }
app_1 | }
It uploads the file successfully but while accessing back it gives following error
I am using Service Principal for authentication.
def get_workspace():
svr_pr = ServicePrincipalAuthentication(
tenant_id=settings.TENANT_ID,
service_principal_id=settings.SERVICE_PRINCIPAL_ID,
service_principal_password=settings.SERVICE_PRINCIPAL_PASSWORD
)
ws = Workspace(
subscription_id=settings.SUBSCRIPTION_ID,
resource_group=settings.RESOURCE_GROUP,
workspace_name=settings.WORKSPACE_NAME,
auth=svr_pr
)
return ws
I faced the same problem, and after some debugging, I found the following in the log files:
Failed to retrieve datastore with exception: System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> System.TypeInitializationException: The type initializer for 'SslMethods' threw an exception.
---> System.TypeInitializationException: The type initializer for 'Ssl' threw an exception.
---> System.TypeInitializationException: The type initializer for 'SslInitializer' threw an exception.
---> Interop+Crypto+OpenSslCryptographicException: error:0E076071:configuration file routines:MODULE_RUN:unknown module name
at Interop.SslInitializer..cctor()
--- End of inner exception stack trace ---
at Interop.Ssl..cctor()
--- End of inner exception stack trace ---
at Interop.Ssl.SslV2_3Method()
at Interop.Ssl.SslMethods..cctor()
--- End of inner exception stack trace ---
This pointed me to this thread: https://github.com/dotnet/runtime/issues/29855
It seems .NET 2.1 tries to use OpenSSL 1.0 while the distro's config at /etc/ssl/openssl.conf is not compatible with that. This has been reported to exist for multiple Debian versions.
Possible solutions:
Comment out the ssl_conf value in /etc/ssl/openssl.cnf
Uninstall OpenSSL 1.0.x
Set CLR_OPENSSL_VERSION_OVERRIDE=1.1 to force OpenSSL 1.1 to be used. (2.1 prefers binding to OpenSSL 1.0.x because that's what it shipped with... it only uses 1.1 if explicitly told to, or if 1.0 isn't available)
I'd tried the last one, and in my case it resolved the problem. I am using Debian Buster.

Can't authenticate with mongoDB from docker-compose service

What I'm trying to do
I'm trying to set up a docker-compose definition, where I have a mongoDB container, and a nodeJS container that connects to it.
version: "3.9"
services:
events-db:
image: mongo
volumes:
- db-volume:/data/db
environment:
MONGO_INITDB_ROOT_USERNAME: $SANDBOX_DB_USER
MONGO_INITDB_ROOT_PASSWORD: $SANDBOX_DB_PASS
MONGO_INITDB_DATABASE: sandboxdb
app:
image: node:15.12.0
user: node
working_dir: /home/node/app
volumes:
- ./:/home/node/app:ro
environment:
MDB_CONNECTION: mongodb://$SANDBOX_DB_USER:$SANDBOX_DB_PASS#events-db:27017/sandboxdb
command: node myapp
depends_on:
- events-db
volumes:
db-volume:
Along with a .env file that declares the credentials (planning to use proper env variables when I deploy this to a production environment):
SANDBOX_DB_USER=myuser
SANDBOX_DB_PASS=myp4ss
Finally, my nodejs script, myapp.js is simply trying to connect, grab a reference to a collection, and insert a document:
require('dotenv').config()
const { MongoClient } = require('mongodb')
async function main () {
console.log('Connecting')
const client = new MongoClient(process.env.MDB_CONNECTION, {
connectTimeoutMS: 10000,
useUnifiedTopology: true,
})
await client.connect()
const db = client.db()
const events = db.collection('events')
console.log('Inserting an event')
await events.insertOne({
type: 'foo',
timestamp: new Date(),
})
console.log('Done.')
process.exit(0)
}
if (require.main === module) {
main()
}
Result
When I run docker-compose config I see the following output, so I would expect it to work:
$ docker-compose config
services:
app:
command: node myapp
depends_on:
events-db:
condition: service_started
environment:
MDB_CONNECTION: mongodb://myuser:myp4ss#events-db:27017/sandboxdb
image: node:15.12.0
user: node
volumes:
- C:\workspace\dcsandbox:/home/node/app:ro
working_dir: /home/node/app
events-db:
environment:
MONGO_INITDB_DATABASE: sandboxdb
MONGO_INITDB_ROOT_PASSWORD: myp4ss
MONGO_INITDB_ROOT_USERNAME: myuser
image: mongo
volumes:
- db-volume:/data/db:rw
version: '3.9'
volumes:
db-volume: {}
However, when I run docker-compose up I see that my node container is unable to connect to the mongoDB to insert an event:
events-db_1 | {"t":{"$date":"2021-04-07T13:57:36.793+00:00"},"s":"I", "c":"NETWORK", "id":23016, "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
app_1 | Connecting
events-db_1 | {"t":{"$date":"2021-04-07T13:57:38.811+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.27.0.3:34164","connectionId":1,"connectionCount":1}}
events-db_1 | {"t":{"$date":"2021-04-07T13:57:38.816+00:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn1","msg":"client metadata","attr":{"remote":"172.27.0.3:34164","client":"conn1","doc":{"driver":{"name":"nodejs","version":"3.6.6"},"os":{"type":"Linux","name":"linux","architecture":"x64","version":"4.19.128-microsoft-standard"},"platform":"'Node.js v15.12.0, LE (unified)"}}}
events-db_1 | {"t":{"$date":"2021-04-07T13:57:38.820+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.27.0.3:34166","connectionId":2,"connectionCount":2}}
events-db_1 | {"t":{"$date":"2021-04-07T13:57:38.822+00:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn2","msg":"client metadata","attr":{"remote":"172.27.0.3:34166","client":"conn2","doc":{"driver":{"name":"nodejs","version":"3.6.6"},"os":{"type":"Linux","name":"linux","architecture":"x64","version":"4.19.128-microsoft-standard"},"platform":"'Node.js v15.12.0, LE (unified)"}}}
events-db_1 | {"t":{"$date":"2021-04-07T13:57:38.822+00:00"},"s":"I", "c":"ACCESS", "id":20251, "ctx":"conn2","msg":"Supported SASL mechanisms requested for unknown user","attr":{"user":"myuser#sandboxdb"}}
events-db_1 | {"t":{"$date":"2021-04-07T13:57:38.823+00:00"},"s":"I", "c":"ACCESS", "id":20249, "ctx":"conn2","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-256","principalName":"myuser","authenticationDatabase":"sandboxdb","client":"172.27.0.3:34166","result":"UserNotFound: Could not find user \"myuser\" for db \"sandboxdb\""}}
events-db_1 | {"t":{"$date":"2021-04-07T13:57:38.824+00:00"},"s":"I", "c":"ACCESS", "id":20249, "ctx":"conn2","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","principalName":"myuser","authenticationDatabase":"sandboxdb","client":"172.27.0.3:34166","result":"UserNotFound: Could not find user \"myuser\" for db \"sandboxdb\""}}
events-db_1 | {"t":{"$date":"2021-04-07T13:57:38.826+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn1","msg":"Connection ended","attr":{"remote":"172.27.0.3:34164","connectionId":1,"connectionCount":1}}
app_1 | /home/node/app/node_modules/mongodb/lib/cmap/connection.js:268
app_1 | callback(new MongoError(document));
app_1 | ^
app_1 |
app_1 | MongoError: Authentication failed.
app_1 | at MessageStream.messageHandler (/home/node/app/node_modules/mongodb/lib/cmap/connection.js:268:20)
app_1 | at MessageStream.emit (node:events:369:20)
app_1 | at processIncomingData (/home/node/app/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
app_1 | at MessageStream._write (/home/node/app/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
app_1 | at writeOrBuffer (node:internal/streams/writable:395:12)
app_1 | at MessageStream.Writable.write (node:internal/streams/writable:340:10)
app_1 | at Socket.ondata (node:internal/streams/readable:750:22)
app_1 | at Socket.emit (node:events:369:20)
app_1 | at addChunk (node:internal/streams/readable:313:12)
app_1 | at readableAddChunk (node:internal/streams/readable:288:9) {
app_1 | ok: 0,
app_1 | code: 18,
app_1 | codeName: 'AuthenticationFailed'
app_1 | }
events-db_1 | {"t":{"$date":"2021-04-07T13:57:38.832+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn2","msg":"Connection ended","attr":{"remote":"172.27.0.3:34166","connectionId":2,"connectionCount":0}}
dcsandbox_app_1 exited with code 1
I've put the full output at https://pastebin.com/uNyJ6tiy
and the example code at this repo: https://github.com/akatechis/example-docker-compose-mongo-node-auth
After some more digging, I managed to figure it out. The issue is that the MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD variables simply set the root user's credentials, and the MONGO_INITDB_DATABASE simply sets the initial database for scripts in /docker-entrypoint-initdb.d.
By default, the root user is added to the admin database, so by removing the /sandboxdb part of the connection string, I was able to have my node app authenticate against the admin DB as the root user.
While this doesn't quite accomplish what I wanted initially (to create a separate, non-root user for my database, and use that to authenticate), I think this puts me on the right path to using an init script to set up the user accounts I want to have.

How do i specify the path in node/express correctly to read my certificate files?

This is my file structure simplified
app-folder
-> dist
-> server.js
-> src
-> server.ts
-> key.pem
-> cert.pem
This is the simplified content of the server.ts file to read the certificate files
import fs from 'fs';
const options = {
key: fs.readFileSync('../key.pem'),
cert: fs.readFileSync('../cert.pem')
};
This is the error i am getting
server | internal/fs/utils.js:307
server | throw err;
server | ^
server |
server | Error: ENOENT: no such file or directory, open '../key.pem'
server | at Object.openSync (fs.js:476:3)
server | at Object.readFileSync (fs.js:377:35)
server | at Object.<anonymous> (/usr/src/app/dist/server.js:18:23)
server | at Module._compile (internal/modules/cjs/loader.js:1063:30)
server | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
server | at Module.load (internal/modules/cjs/loader.js:928:32)
server | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
server | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
server | at internal/main/run_main_module.js:17:47 {
server | errno: -2,
server | syscall: 'open',
server | code: 'ENOENT',
server | path: '../key.pem'
server | }
server exited with code 1
I created the key and certificate following this
tutorial
Hoangdv pointed out that i use docker which is correct this is my Dockerfile:
FROM node:14
# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN npm install -g nodemon
# Install dependencies
COPY package.json .
RUN npm install
# Bundle app source
COPY . .
RUN npx tsc
EXPOSE 8080
Does COPY . . not copy the certificates already?
Relative paths will be resolved relative to the current working directory as determined by calling process.cwd().
--- node.js docs
import fs from 'fs';
import path from 'path';
const options = {
key: fs.readFileSync(path.resolve(__dirname, '../key.pem')),
cert: fs.readFileSync(path.resolve(__dirname, '../cert.pem'))
};
Try,
var resolve = require('path').resolve
key : resolve('../key.pem')
cert : resolve('../cert.pem')

How to customize Bootstrap variables in a React app?

I'm using facebook's create-react-app. I've completed all the instructions to add SASS to my app, now I'm trying to add Bootstrap and customize the theme. I've been able to add bootstrap but the customizing of the variables is not working. Here is my setup:
package.json
"bootstrap": "^4.0.0-beta",
In my React layout container:
import 'bootstrap/dist/css/bootstrap.css';
import '../styles/custom_bootstrap.scss';
Bootstrap is working fine but the customizations/overrides are not having an effect.
custom_bootstrap.scss:
$theme-colors: (
primary: orange
) !default;
The primary is still blue. What am I doing wrong here?
Updated
MainLayout.jsx
import '../styles/index.css'
index.scss
#import 'custom_bootstrap';
#import 'bootstrap/scss/bootstrap';
If I remove #import 'custom_bootstrap'; bootstrap compiles successfully.
If I add it back and update the following:
_custom_bootstrap.scss
$theme-colors: (
primary: orange
) !default;
I'm getting compile errors like so:
09:44:56 web.1 | => changed: /Users/xxx/sites/xxx/client/src/styles/index.scss
09:44:56 web.1 | {
09:44:56 web.1 | "status": 1,
09:44:56 web.1 | "file": "/Users/xxx/sites/xxx/client/node_modules/bootstrap/scss/_forms.scss",
09:44:56 web.1 | "line": 280,
09:44:56 web.1 | "column": 21,
09:44:56 web.1 | "message": "argument `$color` of `rgba($color, $alpha)` must be a color\n\nBacktrace:\n\tnode_modules/bootstrap/scss/_forms.scss:280, in function `rgba`\n\tnode_modules/bootstrap/scss/_forms.scss:280",
09:44:56 web.1 | "formatted": "Error: argument `$color` of `rgba($color, $alpha)` must be a color\n\n Backtrace:\n \tnode_modules/bootstrap/scss/_forms.scss:280, in function `rgba`\n \tnode_modules/bootstrap/scss/_forms.scss:280\n on line 280 of node_modules/bootstrap/scss/_forms.scss\n>> background-color: rgba($form-feedback-invalid-color,.8);\n --------------------^\n"
09:44:56 web.1 | }
It looks like you're importing the compiled bootstrap CSS:
import 'bootstrap/dist/css/bootstrap.css';
Variables you set in your custom SCSS won't have any effect on this.
Import your variables, then bootstrap's SCSS. Omit the !default flag. Example:
styles/styles.scss
#import 'variables';
#import '[relative path to boostrap]/scss/bootstrap';
styles/_variables.scss
$theme-colors: (
primary: orange
);
You cannot change sass variables that are in the compiled .css bootstrap file. They are no longer sass variables at that point. You need to override them before they are compiled. So start by importing in bootstrap to your custom file and then override it. Then you can compile it all into one .css file.
import 'bootstrap/dist/css/bootstrap.scss';
$theme-colors: (
primary: orange
) !default;

Resources