Skip to content

Commit

Permalink
CMR-9776: Resolve linter errors & warnings in common-app-lib; add lin…
Browse files Browse the repository at this point in the history
…ting config
  • Loading branch information
zimzoom committed Apr 24, 2024
1 parent bdd955b commit c585c59
Show file tree
Hide file tree
Showing 57 changed files with 152 additions and 171 deletions.
10 changes: 10 additions & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{:skip-comments true
;; no linting for all dev/user.clj namespaces
:config-in-ns {user {:ignore true}}
;; CMR custom macros
:lint-as {cmr.common.config/defconfig clojure.core/def
cmr.common.jobs/defjob clojure.core/defn
cmr.common.jobs/def-stateful-job clojure.core/defn
cmr.common.util/are3 clj-kondo.lint-as/def-catch-all}
;; dynamically generated functions/vars
:linters {:unresolved-var {:exclude [digest/md5 digest/sha-1]}}}
5 changes: 5 additions & 0 deletions .clj-kondo/rewrite-clj/rewrite-clj/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{:lint-as
{rewrite-clj.zip/subedit-> clojure.core/->
rewrite-clj.zip/subedit->> clojure.core/->>
rewrite-clj.zip/edit-> clojure.core/->
rewrite-clj.zip/edit->> clojure.core/->>}}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ browse-scaler/src/node_modules
.cider-repl-history
**/ignore.*
.calva*
*.clj-kondo
*.ruby-version
.cljfmt.edn
dev-system/local.edn
Expand Down
2 changes: 0 additions & 2 deletions common-app-lib/src/cmr/common_app/api/enabled.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
anything from writing on the NGAP side while we are transitioning."
(:require
[cheshire.core :as json]
[cmr.common.api.context :as context]
[cmr.transmit.cache.consistent-cache :as consistent-cache]
[cmr.common.cache :as cache]
[cmr.common.cache.in-memory-cache :as mem-cache]
[cmr.common.cache.single-thread-lookup-cache :as stl-cache]
[cmr.common.config :refer [defconfig]]
[cmr.common.log :refer [error warn]]
Expand Down
4 changes: 2 additions & 2 deletions common-app-lib/src/cmr/common_app/api/health.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[cmr.common.config :refer [defconfig]]
[cmr.common.log :refer [warn]]
[cmr.common.mime-types :as mt]
[compojure.core :refer :all]))
[compojure.core :refer [GET OPTIONS context]]))

(def health-cache-key
"The key used to store the health cache in the system cache map."
Expand Down Expand Up @@ -56,6 +56,6 @@
working as expected."
[health-fn]
(context "/health" []
(OPTIONS "/" req (common-routes/options-response))
(OPTIONS "/" _req (common-routes/options-response))
(GET "/" {:keys [request-context]}
(get-app-health request-context health-fn))))
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
(ns cmr.common-app.api.launchpad-token-validation
"Validate Launchpad token."
(:require
[cheshire.core :as json]
[clojure.data.codec.base64 :as base64]
[clojure.string :as string]
[cmr.common-app.config :as config]
[cmr.common.services.errors :as errors]
[cmr.common.util :as common-util]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
[cheshire.core :as json]
[cmr.common.cache :as cache]
[cmr.common.cache.in-memory-cache :as mem-cache]
[cmr.common.log :refer (info)]
[cmr.common.services.errors :as errors]
[cmr.common.util :as util]
[cmr.transmit.access-control :as access-control]
Expand Down Expand Up @@ -85,7 +84,7 @@
It expects the request context is already associated with the request."
[handler]
(fn [request]
(let [{:keys [request-context]} request]
(let [{:keys [_request-context]} request]
(-> request
(update-in [:request-context] add-user-id-and-sids-to-context)
(handler)))))
4 changes: 2 additions & 2 deletions common-app-lib/src/cmr/common_app/api/request_logger.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
[clojure.string :as string]
[cmr.common-app.config :as config]
[cmr.common.date-time-parser :as dtp]
[cmr.common.log :refer [debug info warn error report]]
[cmr.common.log :refer [report]]
[cmr.common.util :as util]
[cmr.common.time-keeper :as tk]
[digest :as digest]
[ring.middleware.params :as params]
[ring.util.codec :as codec]))

(defn- request->uri
[request]
"Reconstruct a url that a request client may have asked for (assuming port
number was given). Special care is taken to scrub token from the URL parameter
list if provided at 'token'."
[request]
;; Another filter may have already parsed the parameters found at :query-params,
;; use that to save time, otherwise do it ourself from :query-string
(let [raw-query (or (:query-params request) (codec/form-encode (:query-string request)))
Expand Down
22 changes: 10 additions & 12 deletions common-app-lib/src/cmr/common_app/api/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
[cmr.common.cache :as cache]
[cmr.common.hash-cache :as hcache]
[cmr.common.jobs :as jobs]
[cmr.common.log :refer [debug info warn error]]
[cmr.common.mime-types :as mt]
[cmr.common.xml :as cx]
[compojure.core :refer [context GET POST]]
[ring.middleware.json :as ring-json]
[ring.util.codec :as rc]
[ring.util.response :as ring-resp]))

(def RESPONSE_REQUEST_ID_HEADER
Expand Down Expand Up @@ -107,15 +105,15 @@
"Create routes for the cache querying/management api"
(context "/caches" []
;; Get the list of caches
(GET "/" {:keys [params request-context headers]}
(GET "/" {:keys [_params request-context _headers]}
(acl/verify-ingest-management-permission request-context :read)
(let [caches (map name (keys (get-in request-context [:system :caches])))]
{:status 200
:body (json/generate-string caches)}))
;; Get the keys for the given cache
(GET "/:cache-name" {{:keys [cache-name] :as params} :params
(GET "/:cache-name" {{:keys [cache-name] :as _params} :params
request-context :request-context
headers :headers}
_headers :headers}
(acl/verify-ingest-management-permission request-context :read)
(let [cache (cache/context->cache request-context (keyword cache-name))]
(when cache
Expand All @@ -126,9 +124,9 @@
:body (json/generate-string result)}))))

;; Get the value for the given key for the given cache
(GET "/:cache-name/:cache-key" {{:keys [cache-name cache-key] :as params} :params
(GET "/:cache-name/:cache-key" {{:keys [cache-name cache-key] :as _params} :params
request-context :request-context
headers :headers}
_headers :headers}
(acl/verify-ingest-management-permission request-context :read)
(let [cache-key (keyword cache-key)
cache (cache/context->cache request-context (keyword cache-name))
Expand All @@ -143,7 +141,7 @@
:body (json/generate-string
{:error (format "missing key [%s] for cache [%s]" cache-key cache-name)})})))

(POST "/clear-cache" {:keys [request-context params headers]}
(POST "/clear-cache" {:keys [request-context _params _headers]}
(acl/verify-ingest-management-permission request-context :update)
(cache/reset-caches request-context)
(hcache/reset-caches request-context)
Expand All @@ -157,19 +155,19 @@
([additional-job-routes]
(context "/jobs" []
;; Pause all jobs
(POST "/pause" {:keys [request-context params headers]}
(POST "/pause" {:keys [request-context _params _headers]}
(acl/verify-ingest-management-permission request-context :update)
(jobs/pause-jobs (get-in request-context [:system :scheduler]))
{:status 204})

;; Resume all jobs
(POST "/resume" {:keys [request-context params headers]}
(POST "/resume" {:keys [request-context _params _headers]}
(acl/verify-ingest-management-permission request-context :update)
(jobs/resume-jobs (get-in request-context [:system :scheduler]))
{:status 204})

;; Retrieve status of jobs - whether they are paused or active
(GET "/status" {:keys [request-context params headers]}
(GET "/status" {:keys [request-context _params _headers]}
(acl/verify-ingest-management-permission request-context :update)
(let [paused? (jobs/paused? (get-in request-context [:system :scheduler]))]
{:status 200
Expand Down Expand Up @@ -245,7 +243,7 @@
"Adds a number of security related response headers."
[handler]
(fn [{context :request-context :as request}]
(if-let [request-id (cxt/context->request-id context)]
(if-let [_request-id (cxt/context->request-id context)]
(-> request
(handler)
(assoc-in [:headers RESPONSE_STRICT_TRANSPORT_SECURITY_HEADER] "max-age=31536000")
Expand Down
6 changes: 3 additions & 3 deletions common-app-lib/src/cmr/common_app/app_events.clj
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"Add a shutdown hook to call the CMR app stop command found in most if not all
CMR microservices. Caller must supply a function that calls the application's
stop function such as: #(cmr.search.system/stop system)"
[app-name stop-thread]
[_app-name stop-thread]
(.addShutdownHook (Runtime/getRuntime) (new Thread stop-thread)))

(defn dump-on-exit-hook
Expand All @@ -70,5 +70,5 @@
(comment
;; use these to create a memory file locally for use in Visual VM
(config/set-dump-diagnostics-on-exit-to! "/tmp/dump-auto.txt")
(dump-heap "/tmp/dump.txt" true)
(dump-heap "/tmp/dump.hprof" false))
(dump-heap "appname1" "/tmp/dump.txt" true)
(dump-heap "appname2" "/tmp/dump.hprof" false))
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@
collection-found))

(defn get-collection-for-gran-acls
[context coll-concept-id]
"Gets a single collection from the cache by concept id. If collection is not found in cache, but exists in elastic, it will add it to the cache and will return the found collection."
[context coll-concept-id]
(let [coll-by-concept-id-cache (hash-cache/context->cache context coll-by-concept-id-cache-key)
collection (hash-cache/get-value coll-by-concept-id-cache
coll-by-concept-id-cache-key
Expand All @@ -132,7 +132,7 @@
(time-strs->clj-times collection))))

(defjob RefreshCollectionsCacheForGranuleAclsJob
[ctx system]
[_ctx system]
(refresh-entire-cache {:system system}))

(defn refresh-collections-cache-for-granule-acls-job
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[cmr.common.config :refer [defconfig]]
[cmr.common.hash-cache :as hash-cache]
[cmr.common.jobs :refer [defjob]]
[cmr.common.log :as log :refer (debug info warn error)]
[cmr.common.log :as log :refer (info warn)]
[cmr.common.redis-log-util :as rl-util]
[cmr.common.util :as util]
[cmr.redis-utils.config :as redis-config]
Expand Down Expand Up @@ -116,7 +116,7 @@
:type Long})

(defjob RefreshHumanizerAliasCache
[ctx system]
[_ctx system]
(refresh-entire-cache {:system system}))

(defn refresh-humanizer-alias-cache-job
Expand Down
8 changes: 4 additions & 4 deletions common-app-lib/src/cmr/common_app/humanizer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
"Map of humanizer JSON type values to functions which take a field value and
humanizer configuration and return a transformed field value. The functions
can assume that the humanizer should be applied to the value."
(fn [humanizer value]
(fn [humanizer _value]
(:type humanizer)))

(defmethod to-human "trim_whitespace"
[humanizer value]
[_humanizer value]
(assoc value
:value (str/trim (str/replace (:value value) #"\s+" " "))))

(defmethod to-human "capitalize"
[humanizer value]
[_humanizer value]
(assoc value
:value (->> (str/split (:value value) #"\b")
(map str/capitalize)
Expand All @@ -48,7 +48,7 @@
:value (:replacement_value humanizer)))

(defmethod to-human "ignore"
[humanizer value]
[_humanizer _value]
nil)

(defmethod to-human "priority"
Expand Down
2 changes: 1 addition & 1 deletion common-app-lib/src/cmr/common_app/services/jvm_info.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(:require
[cmr.common.config :refer [defconfig]]
[cmr.common.jobs :refer [defjob]]
[cmr.common.log :refer [debug warn info error]])
[cmr.common.log :refer [info]])
(:import
(java.lang Runtime)))

Expand Down
6 changes: 3 additions & 3 deletions common-app-lib/src/cmr/common_app/services/kms_fetcher.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
{...}]}
:providers [...]}"
(:require
[clojure.string :as string]
[cmr.common-app.services.kms-lookup :as kms-lookup]
[cmr.common.cache :as cache]
[cmr.common.log :refer [error]]
[cmr.common.redis-log-util :as rl-util]
[cmr.common.util :as util]
[cmr.redis-utils.config :as redis-config]
[cmr.redis-utils.redis-cache :as redis-cache]
[cmr.transmit.kms :as kms])
(:import (clojure.lang ExceptionInfo)))
[cmr.transmit.kms :as kms]))

(def nested-fields-mappings
"Mapping from field name to the list of subfield names in order from the top of the hierarchy to
Expand Down Expand Up @@ -77,7 +77,7 @@
[keyword-scheme keyword-scheme-value]
[keyword-scheme (get kms-cache-value keyword-scheme)])))))
(catch Exception e
(if (clojure.string/includes? (ex-message e) "Carmine connection error")
(if (string/includes? (ex-message e) "Carmine connection error")
(error "fetch-gcmd-keywords-map found redis carmine exception. Will return nil result." e)
(throw e)))))

Expand Down
3 changes: 1 addition & 2 deletions common-app-lib/src/cmr/common_app/services/kms_lookup.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
[cmr.common.util :as util]
[cmr.redis-utils.config :as redis-config]
[cmr.redis-utils.redis-hash-cache :as rhcache]
[cmr.transmit.kms :as kms])
(:import (clojure.lang ExceptionInfo)))
[cmr.transmit.kms :as kms]))

(def kms-short-name-cache-key
"The key used to store the data generated from KMS into a short name index cache
Expand Down
11 changes: 4 additions & 7 deletions common-app-lib/src/cmr/common_app/services/search.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
"This contains common code for implementing search capabilities in a CMR application"
(:require
[cmr.common.util :as u]
[cmr.common.cache.fallback-cache :as fallback-cache]
[cmr.common.cache.single-thread-lookup-cache :as stl-cache]
[cmr.common.config :as cfg :refer [defconfig]]
[cmr.common.log :refer (debug info warn error)]
[cmr.common.log :refer (info)]
[cmr.common.services.errors :as errors]
[cmr.common.cache :as cache]
[cmr.common.cache.in-memory-cache :as mem-cache]
[cmr.common-app.services.search.query-validation :as qv]
[cmr.common-app.services.search.query-execution :as qe]
[cmr.common-app.services.search.query-model :as qm]
Expand Down Expand Up @@ -58,20 +55,20 @@
(defn validate-query
"Validates a query model. Throws an exception to return to user with errors.
Returns the query model if validation is successful so it can be chained with other calls."
[context query]
[_context query]
(if-let [errors (seq (qv/validate query))]
(errors/throw-service-errors :bad-request errors)
query))

(defmulti search-results->response
"Converts query search results into a string response."
(fn [context query results]
(fn [_context query _results]
[(:concept-type query) (qm/base-result-format query)]))

(defmulti single-result->response
"Returns a string representation of a single concept in the format
specified in the query."
(fn [context query results]
(fn [_context query _results]
[(:concept-type query) (qm/base-result-format query)]))

(defn- add-scroll-results-to-cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

(defmulti parse-elastic-item
"Parses the Elasticsearch response into a map that can be used to enforce ACLs."
(fn [concept-type elastic-result]
(fn [concept-type _elastic-result]
concept-type))

(defmethod parse-elastic-item :collection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(ns cmr.common-app.services.search.complex-to-simple
(:require [cmr.common-app.services.search.query-model :as cqm]))
(ns cmr.common-app.services.search.complex-to-simple)

(defprotocol ComplexQueryToSimple
"Defines a function to convert a complex / high level query/condition into simpler ones that
Expand Down Expand Up @@ -34,6 +33,6 @@
;; catch all
java.lang.Object
(reduce-query-condition
[this context]
[this _context]
;; do nothing
this))
Loading

0 comments on commit c585c59

Please sign in to comment.