Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Add a feature flag for Palveluväylä API
Browse files Browse the repository at this point in the history
  • Loading branch information
solita-antti-mottonen committed Nov 24, 2023
1 parent a194de6 commit 2a0575b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion etp-backend/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
prismatic/schema-generators {:mvn/version "0.1.5"}
ring/ring-mock {:mvn/version "0.4.0"}
org.xmlunit/xmlunit-core {:mvn/version "2.9.1"}}
:jvm-opts ["-Djava.awt.headless=true"]}
:jvm-opts ["-Djava.awt.headless=true" "-DALLOW_PALVELUVAYLA_API=true"]}
:test {:main-opts ["-e" "(run-tests-and-exit!)" "-A:dev"]}
:test-ci {:main-opts ["-e" "(run-tests-with-junit-reporter-and-exit!)" "-A:dev"]}
:coverage {:extra-deps {cloverage/cloverage {:mvn/version "1.2.4"}}
Expand Down
58 changes: 35 additions & 23 deletions etp-backend/src/main/clj/solita/etp/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@
(def use-local-env-credentials?
(not (System/getenv "FILES_BUCKET_NAME")))

(defn env [name default]
(or (System/getenv name) default))
(defn find-configuration
"Return configuration value for given key. Returns first hit in order from given reader"
([key readers default]
(-> (some identity (->> readers (map #(% key)))) (or default))))

(defn env
([name] (env name nil))
([name default] (or (System/getenv name) default)))

(defn property
[name] (System/getProperty name))

(defn env-or-resource [env-name resource-path]
(or (System/getenv env-name)
Expand All @@ -24,40 +33,40 @@
(defn db
([] (db {}))
([opts]
{:solita.etp/db (merge {:adapter "postgresql"
:server-name (env "DB_HOST" "localhost")
:port-number (env "DB_PORT" 5432)
:username (env "DB_USER" "etp_app")
:password (env "DB_PASSWORD" "etp")
:database-name (env "DB_DATABASE" "etp_dev")
{:solita.etp/db (merge {:adapter "postgresql"
:server-name (env "DB_HOST" "localhost")
:port-number (env "DB_PORT" 5432)
:username (env "DB_USER" "etp_app")
:password (env "DB_PASSWORD" "etp")
:database-name (env "DB_DATABASE" "etp_dev")
:current-schema (env "DB_SCHEMA" "etp")}
opts)}))

(defn http-server
([] (http-server {}))
([opts]
{:solita.etp/http-server (merge {:port (env "HTTP_SERVER_PORT" 8080)
{:solita.etp/http-server (merge {:port (env "HTTP_SERVER_PORT" 8080)
:max-body (* 1024 1024 50)
:thread 20
:ctx {:db (ig/ref :solita.etp/db)
:aws-s3-client (ig/ref :solita.etp/aws-s3-client)}}
:thread 20
:ctx {:db (ig/ref :solita.etp/db)
:aws-s3-client (ig/ref :solita.etp/aws-s3-client)}}
opts)}))

(defn aws-s3-client
([] (aws-s3-client {}))
([{:keys [client bucket]}]
{:solita.etp/aws-s3-client
{:client (merge
{:api :s3
:region "eu-central-1"}
(when use-local-env-credentials?
{:credentials-provider (credentials/basic-credentials-provider
{:access-key-id "minio"
:secret-access-key "minio123"})
:endpoint-override {:protocol :http
:hostname "localhost"
:port 9000}})
client)
{:api :s3
:region "eu-central-1"}
(when use-local-env-credentials?
{:credentials-provider (credentials/basic-credentials-provider
{:access-key-id "minio"
:secret-access-key "minio123"})
:endpoint-override {:protocol :http
:hostname "localhost"
:port 9000}})
client)
:bucket (or bucket (env "FILES_BUCKET_NAME" "files"))}}))

(defn- prepare-emails [name default]
Expand Down Expand Up @@ -121,7 +130,7 @@

(def suomifi-viestit-proxy? (edn/read-string (env "SUOMIFI_VIESTIT_PROXY" "false")))
(def suomifi-viestit-paperitoimitus? (edn/read-string (env "SUOMIFI_VIESTIT_PAPERITOIMITUS" "false")))
(def suomifi-viestit-laheta-tulostukseen? (edn/read-string (env "SUOMIFI_VIESTIT_LAHETA_TULOSTUKSEEN" "false")))
(def suomifi-viestit-laheta-tulostukseen? (edn/read-string (env "SUOMIFI_VIESTIT_LAHETA_TULOSTUKSEEN" "false")))
(def suomifi-viestit-endpoint-url (env "SUOMIFI_VIESTIT_ENDPOINT_URL" nil))
(def suomifi-viestit-viranomaistunnus (env "SUOMIFI_VIESTIT_VIRANOMAISTUNNUS" nil))
(def suomifi-viestit-palvelutunnus (env "SUOMIFI_VIESTIT_PALVELUTUNNUS" nil))
Expand All @@ -139,3 +148,6 @@
(def url-signing-key-id (env "URL_SIGNING_KEY_ID" "DEVENV_KEY_ID"))
(def url-signing-public-key (env-or-resource "URL_SIGNING_PUBLIC_KEY" "cf-signed-url/example.pub.pem"))
(def url-signing-private-key (env-or-resource "URL_SIGNING_PRIVATE_KEY" "cf-signed-url/example.key.pem"))

;; Feature flags
(def allow-palveluvayla-api (Boolean/parseBoolean (find-configuration "ALLOW_PALVELUVAYLA_API" [env property] "false")))
10 changes: 5 additions & 5 deletions etp-backend/src/main/clj/solita/etp/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@
["/internal"
(concat (tag "Laskutus API" laskutus-api/routes)
(tag "Laatija Internal API" laatija-api/internal-routes))]
["/palveluvayla" ["/openapi.json" {:get {:no-doc true
:openapi {:info {:title "Energiatodistuspalvelu API" :description "Hae energiatodistuksia pdf tai json muodoissa"}
:id "Palveluväylä"}
:handler (openapi/create-openapi-handler)}}]
(openapi-id "Palveluväylä" palveluvayla/routes)]])
(when config/allow-palveluvayla-api
["/palveluvayla" ["/openapi.json" {:get {:no-doc true :openapi {:info {:title "Energiatodistuspalvelu API" :description "Hae energiatodistuksia pdf tai json muodoissa"}
:id "Palveluväylä"}
:handler (openapi/create-openapi-handler)}}]
(openapi-id "Palveluväylä" palveluvayla/routes)])])

(def default-string-coercion-options-with-project-specific-ones
"Add more schemas that support coercion to default configuration in addition to those supported by schema coercion out of the box"
Expand Down

0 comments on commit 2a0575b

Please sign in to comment.