Template or copy configuration

- Create ormconfig.json
- Change to using a dictionary for environmental variables

Change-Id: Ic02e813040f5a2b3d1f9d411970365a8f7e9955e
diff --git a/README.md b/README.md
index d74e19a..0ddb42d 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,16 @@
 
 ONF Timesheets Web App
 
+This role deploys the timesheets web application, found in these two repos:
+
+- https://github.com/opennetworkinglab/timesheetsdb
+- https://github.com/opennetworkinglab/timesheetsui
+
+See the configuration variables given in the `defaults/main.yml` file for the
+database connection, and external service credentials.
+
+Also requires a private key from Docusign, stored in a file named
+`docusignPrivate.key` somewhere in the file lookup path.
 
 ## Requirements
 
@@ -13,15 +23,10 @@
 
 Minimum ansible version: 2.9.5
 
-## Defaults
-
-List of default values for variables:
-
 ## Example Playbook
 
 ```yaml
 - hosts: all
-  vars:
   roles:
     - timesheets
 ```
diff --git a/defaults/main.yml b/defaults/main.yml
index d643fe3..a5930ed 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -24,3 +24,27 @@
 timesheets_pg_db_port: 5432
 timesheets_pg_db_username: "timesheets_db_user"
 timesheets_pg_db_password: "timesheets_db_pass"
+
+timesheets_env_vars:
+  NAME: "Timesheets"
+  AUTHENTICATION_SECRET: "secret"
+  DATABASE_NAME: "{{ timesheets_pg_db }}"
+  DATABASE_PORT: "{{ timesheets_pg_db_port }}"
+  DATABASE_USER: "{{ timesheets_pg_db_username }}"
+  DATABASE_PASS: "{{ timesheets_pg_db_password }}"
+  DOCUSIGN_BASE_PATH: "https://docusign.net/restapi"
+  DOCUSIGN_TOKEN_URL: "https://account.docusign.com/oauth/token"
+  DOCUSIGN_ACCOUNT_ID: "uuid"
+  DOCUSIGN_ISS: "uuid"
+  DOCUSIGN_SUB: "uuid"
+  DOCUSIGN_AUD: "account.docusign.com"
+  DOCUSIGN_SCOPE: "signature impersonation"
+  GOOGLE_CLIENT_ID: "id"
+  GOOGLE_CLIENT_SECRET: "secret"
+  GOOGLE_PROJECT_ID: "example-timesheets-project"
+  GOOGLE_AUTH_URI: "https://accounts.google.com/o/oauth2/auth"
+  GOOGLE_TOKEN_URI: "https://oauth2.googleapis.com/token"
+  GOOGLE_AUTH_PROVIDER_X509_CERT_URL: "https://www.googleapis.com/oauth2/v1/certs"
+  GOOGLE_REDIRECT_URIS: "urn:ietf:wg:oauth:2.0:oob, http://localhost"
+  GOOGLE_DOC_PARENT_FOLDER: "folder"
+  GOOGLE_DOC_URL_TEMPLATE: "https://drive.google.com/file/d/id/view"
diff --git a/molecule/default/files/docusignPrivate.key b/molecule/default/files/docusignPrivate.key
new file mode 100644
index 0000000..da6abcf
--- /dev/null
+++ b/molecule/default/files/docusignPrivate.key
@@ -0,0 +1,3 @@
+# dummy docusignPrivate.key
+# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
diff --git a/tasks/main.yml b/tasks/main.yml
index 73e55e5..9700ccd 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -42,6 +42,26 @@
   notify:
     - "restart-timesheetsdb"
 
+- name: Create ormconfig.json file from template
+  template:
+    src: "ormconfig.json.j2"
+    dest: "{{ timesheets_dir }}/db/ormconfig.json"
+    owner: "root"
+    group: "{{ timesheets_groupname }}"
+    mode: "0640"
+  notify:
+    - "restart-timesheetsdb"
+
+- name: Copy the the Docusign key
+  copy:
+    src: "docusignPrivate.key"
+    dest: "{{ timesheets_dir }}/db/docusignPrivate.key"
+    owner: "root"
+    group: "{{ timesheets_groupname }}"
+    mode: "0640"
+  notify:
+    - "restart-timesheetsdb"
+
 - name: Install timesheetsdb
   become: true
   become_user: "{{ timesheets_username }}"
diff --git a/templates/default.timesheetsdb.j2 b/templates/default.timesheetsdb.j2
index 749062c..e0aaadc 100644
--- a/templates/default.timesheetsdb.j2
+++ b/templates/default.timesheetsdb.j2
@@ -4,7 +4,6 @@
 #}
 # /etc/default/timesheetsdb
 # {{ ansible_managed }}
-DATABASE_NAME = {{ timesheets_pg_db }}
-DATABASE_PORT = {{ timesheets_pg_db_port }}
-DATABASE_USER = {{ timesheets_pg_db_username }}
-DATABASE_PASS = {{ timesheets_pg_db_password }}
+{% for key, val in timesheets_env_vars.items() %}
+{{ key }}="{{ val }}"
+{% endfor %}
diff --git a/templates/ormconfig.json.j2 b/templates/ormconfig.json.j2
new file mode 100644
index 0000000..0f0cbc4
--- /dev/null
+++ b/templates/ormconfig.json.j2
@@ -0,0 +1,19 @@
+{#
+SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
+SPDX-License-Identifier: Apache-2.0
+#}
+[
+  {
+    "type": "postgres",
+    "host": "localhost",
+    "port": {{ timesheets_pg_db_port }},
+    "username": "{{ timesheets_pg_db_username }}",
+    "password": "{{ timesheets_pg_db_password }}",
+    "database": "{{ timesheets_pg_db }}",
+    "entities": ["dist/**/*.entity{ .ts,.js}"],
+    "synchronize": false,
+    "migrations": ["dist/migrations/*{.ts,.js}"],
+    "migrationsTableName": "migrations_typeorm",
+    "migrationsRun": true
+  }
+]