Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ssl #17

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"database": "",
"user": "",
"password": ""
},
"ssl": {
"enabled": false,
"rejectUnauthorized": false
}
}
4 changes: 4 additions & 0 deletions config/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"database": "spatial",
"user": "postgres",
"password": "postgres"
},
"ssl": {
"enabled": false,
"rejectUnauthorized": false
}
}
7 changes: 6 additions & 1 deletion src/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ const config = require('config')
const pgPromise = require('pg-promise')
const { Data } = require('./repo')

const ssl = (process.env.SSL_ENABLED || config.ssl.enabled) && {
rejectUnauthorized: (process.env.REJECT_UNAUTHORIZED || config.ssl.rejectUnauthorized) || false
};

// Database connection details;
const cn = {
host: process.env.PG_HOST || config.db.host,
port: process.env.PG_PORT || config.db.port,
database: process.env.PG_DATABASE || config.db.database,
user: process.env.PG_USER || config.db.user,
password: process.env.PG_PASSWORD || config.db.password
password: process.env.PG_PASSWORD || config.db.password,
ssl,
}

const initOptions = {
Expand Down
4 changes: 2 additions & 2 deletions src/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Model.prototype.getData = (req, callback) => {

db.data.getGeometryColumnName(schema, table)
.then(result => {
const geom = result.f_geometry_column
const srid = result.srid
const geom = result?.f_geometry_column || 'null'
const srid = result?.srid || 'null'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is your intention with these values? I have refactored this module on the develop branch and plan to update with something like the following:

const result = await db.data.getGeometryColumnName(schema, table);

if (!result) {
  throw new Error('Invalid result from getGeometryColumnName');
}

To error out gracefully.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESRI Feature Services can support tables, which have no geometry. This
change keeps the provider from erroring when reading postgres tables
that have no geometry but can still be served as a Feature Layer

My intention is to be able to serve a table (no geometry) in a feature service. We have a use case where we are using Koop to create a feature service with tables for our Survey123 app to query and dynamically populate choices in the survey. When doing this initially I ran into exceptions because the postgres table had no columns of type geometry. The workaround I found was to set these to null and then Koop served a table as expected. Erroring gracefully here is still erroring when this is a case that Koop supports.


db.data.createGeoJson(id, geom, srid, schema + '.' + table)
.then(result => {
Expand Down