Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Credentials in default-env.json #87

Open
T1mey opened this issue Nov 9, 2021 · 6 comments
Open

Credentials in default-env.json #87

T1mey opened this issue Nov 9, 2021 · 6 comments

Comments

@T1mey
Copy link

T1mey commented Nov 9, 2021

Hi,

I'll try running

npx cds-dbm deploy -create-db --load-via delta

but (in SAP BAS) the default-env.json is not picked up. Here's my file (values replaced)

{
	"VCAP_SERVICES": {
		"postgresql-db": [
			{
				"label": "postgresql-db",
				"provider": null,
				"plan": "standard",
				"name": "wp-postgres-tool",
				"tags": [
					"relational",
					"database"
				],
				"instance_guid": "guid",
				"instance_name": "wp-postgres-tool",
				"binding_guid": "guid",
				"binding_name": null,
				"credentials": {
					"username": "user",
					"password": "pass",
					"hostname": "db.com",
					"dbname": "xxx",
					"port": "4071",
					"uri": "postgres://url",
				"syslog_drain_url": null,
				"volume_mounts": []
			}
		],

It tries to connect to localhost...

TypeError: Cannot read property 'username' of undefined
    at getCredentialsForClient (/home/user/projects/onboarding-tool-cap/node_modules/cds-dbm/dist/adapter/PostgresAdapter.js:53:26)
@bartdp86
Copy link

I have the same issue but locally, when checking issue sapmentors/cds-pg#142, the issue is not localhost but the tag relational instead of plain
to test locally I added in @sap/cds-compiler/lib/sql-indentifier.js the relation sqlDialect, but on BTP that is not an option...

@gregorwolf
Copy link
Collaborator

Maybe @sjvans can help here. I've worked around this problem by setting the User-Provided Variables CDS_CONFIG to:

{
  "requires": {
    "database": {
      "dialect": "plain",
      "impl": "cds-pg",
      "model": "csn.json",
      "credentials": {
        "username": "user",
        "password": "pass",
        "hostname": "host",
        "dbname": "db",
        "port": "3285",
        "uri": "postgres://user:pass@host:3285/db",
        "sslcert": "cert",
        "sslrootcert": "cert"
      }
    }
  }
}

But that is of course not the solution. We either need the SAP BTP PostgreSQL Hyperscaler Service to set the Tag "plain" or that CAP would also search for the tags relational or database that are set in the service binding:

		"postgresql-db": [
			{
				"label": "postgresql-db",
				"provider": null,
				"plan": "trial",
				"name": "pg-beershop-database",
				"tags": [
					"relational",
					"database"
				],

@gregorwolf
Copy link
Collaborator

OK, thanks to the comment sapmentors/cds-pg#263 (comment) from @sebastianesch regarding the service lookup of CAP I've added:

        "vcap": {
          "name": "pg-beershop-database"
        }

to main/package.json#L91. I've tested also kind and set it to postgresql-db as this is the label of the service. But that did not produce a match. I think that is a bug in the CAP lookup for services. CC: @sjvans

@sebastianesch
Copy link

At the moment the service from VCAP is only picked up when either the tag is 'db' - as this is the service name from the cds.requires section (which is merged with the cds-pg section) AND/OR 'plain', the dialect from the cds-pg section.

You should be able to set the tags for your service instance either in your MTA descriptor or via the CF CLI.

@gregorwolf
Copy link
Collaborator

Hi @sebastianesch thank you for the tip. I've added now

      service-tags:
        - plain

to the PostgreSQL Service section of main/mta.yaml#L113. Now the credential lookup works without any issues.

@harshadporwal47
Copy link

harshadporwal47 commented Sep 4, 2022

Hi @gregorwolf , In my case I am creating the database service using cockpit. In the mta.yaml I am using below code.

resources:
  - name: xxx-xxxx-xxxxxxxx-database
    type: org.cloudfoundry.existing-service

How do I update 'plain' service-tags. Can you please help?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants