Skip to content

Commit

Permalink
CORE-2013: started cleaning up some lint warnings reported by clj-kondo
Browse files Browse the repository at this point in the history
  • Loading branch information
slr71 committed Sep 30, 2024
1 parent 21ce028 commit 62b45d8
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 79 deletions.
3 changes: 3 additions & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{:lint-as {slingshot.slingshot/try+ clojure.core/try}
:linters {:unresolved-var {:exclude [clojure-commons.error-codes
ring.util.http-response]}}}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ Dockerfile.local
terrain.properties
.eastwood
.calva
.clj-kondo
.clj-kondo/*
!.clj-kondo/config.edn
.lsp
4 changes: 2 additions & 2 deletions src/terrain/auth/user_attributes.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns terrain.auth.user-attributes
(:use [slingshot.slingshot :only [try+]])
(:require [clojure.string :as string]
[clojure.tools.logging :as log]
[clojure-commons.response :as resp]
[clojure-commons.exception-util :as cxu]
[slingshot.slingshot :refer [try+]]
[terrain.clients.iplant-groups.subjects :as subjects]
[terrain.util.config :as cfg]
[terrain.util.jwt :as jwt]
Expand Down Expand Up @@ -74,7 +74,7 @@
:commonName (:description subject)})
(catch [:status 404] _
(cxu/internal-system-error (str "fake user " username " not found")))
(catch Object o
(catch Object _
(cxu/internal-system-error (str "fake user lookup for username " username " failed")))))

(defn fake-user-from-attributes
Expand Down
13 changes: 4 additions & 9 deletions src/terrain/clients/app_exposer.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
(ns terrain.clients.app-exposer
(:use [kameleon.uuids :only [uuidify]])
(:require [cemerick.url :as curl]
[clj-http.client :as client]
[terrain.util.config :as config]
[terrain.clients.apps.raw :as apps]
[ring.util.io :as ring-io]
[clojure.tools.logging :as log]
[clojure.java.io :as io]
[terrain.auth.user-attributes :refer [current-user]]))

(defn- augment-query
Expand Down Expand Up @@ -48,7 +43,7 @@
(:body (client/post (app-exposer-url ["vice" "admin" "analyses" analysis-id "time-limit"] {} :no-user true) {:as :json})))

(defn get-resources
"Calls app-exposer's GET /vice/listing endpoint, with filter as the query filter map.
"Calls app-exposer's GET /vice/listing endpoint, with filter as the query filter map.
Returns only results applicable to the user."
[filter]
(:body (client/get (app-exposer-url ["vice" "listing"] filter) {:as :json})))
Expand Down Expand Up @@ -211,8 +206,8 @@
(client/delete {:as :json})
(:body)))

;;; For the (list-metadata) function, we bypass the query map handling built
;;; into (app-exposer-url) to use the one from clj-http because the former
;;; For the (list-metadata) function, we bypass the query map handling built
;;; into (app-exposer-url) to use the one from clj-http because the former
;;; does not handle having an seq of values for an entry while the latter does.
;;; This isn't necessary for other calls, so the change was not made in the
;;; (app-exposer-url) function.
Expand Down Expand Up @@ -256,4 +251,4 @@
[]
(-> (app-exposer-url ["instantlaunches" "quicklaunches" "public"] {})
(client/get {:as :json})
(:body)))
(:body)))
8 changes: 4 additions & 4 deletions src/terrain/clients/apps/raw.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(ns terrain.clients.apps.raw
(:use [clojure-commons.core :only [remove-nil-values]]
[terrain.util :only [disable-redirects]]
[terrain.util.transformers :only [secured-params]])
(:require [cemerick.url :as curl]
[clj-http.client :as client]
[terrain.util.config :as config]))
[clojure-commons.core :refer [remove-nil-values]]
[terrain.util :refer [disable-redirects]]
[terrain.util.config :as config]
[terrain.util.transformers :refer [secured-params]]))

(def apps-sort-params [:limit :offset :sort-field :sort-dir :app-type])
(def base-search-params (conj apps-sort-params :search))
Expand Down
1 change: 0 additions & 1 deletion src/terrain/clients/async_tasks.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns terrain.clients.async-tasks
(:require [async-tasks-client.core :as async-tasks-client]
[clojure.string :as string]
[terrain.util.config :as config]))

(defn run-async-thread
Expand Down
4 changes: 0 additions & 4 deletions src/terrain/clients/bags.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
(ns terrain.clients.bags
(:use [clojure-commons.error-codes]
[slingshot.slingshot :only [try+ throw+]])
(:require [clj-http.client :as http]
[cemerick.url :refer [url]]
[clojure.tools.logging :as log]
[terrain.util.config :as config]))

(defn- bags-url
Expand Down Expand Up @@ -48,7 +45,6 @@
nil)

(defn get-default-bag
[username]
[username]
(:body (http/get (bags-url [username "default"]) {:as :json})))

Expand Down
11 changes: 5 additions & 6 deletions src/terrain/clients/coge.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
(ns terrain.clients.coge
(:use [clojure-commons.core :only [remove-nil-values]]
[terrain.auth.user-attributes :only [current-user]]
[terrain.clients.util :only [with-trap]]
[slingshot.slingshot :only [throw+ try+]])
(:require [cemerick.url :as curl]
[cheshire.core :as cheshire]
[clj-http.client :as http]
[clojure.tools.logging :as log]
[clojure-commons.error-codes :as ce]
[clojure-commons.core :refer [remove-nil-values]]
[slingshot.slingshot :refer [throw+]]
[terrain.auth.user-attributes :refer [current-user]]
[terrain.clients.util :refer [with-trap]]
[terrain.util.config :as config]
[terrain.util.jwt :as jwt]))

Expand All @@ -34,7 +33,7 @@

(defn- export-fasta-request
"Builds the request to export the FastA file for a genome into iRODS."
[user genome-id {:keys [notify overwrite destination]}]
[user genome-id {:keys [notify overwrite]}]
(cheshire/encode
{:type export-fasta-job-type
:parameters (remove-nil-values
Expand Down
8 changes: 2 additions & 6 deletions src/terrain/clients/dashboard_aggregator.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
(ns terrain.clients.dashboard-aggregator
(:use [clojure-commons.error-codes]
[slingshot.slingshot :only [try+ throw+]])
(:require [clj-http.client :as http]
(:require [clj-http.client :as http]
[cemerick.url :refer [url]]
[cheshire.core :as json]
[clojure.tools.logging :as log]
[terrain.util.config :as config]))

(defn- dashboard-aggregator-url
Expand All @@ -21,4 +17,4 @@
(:body (http/get (dashboard-aggregator-url ["users" username] limit) {:as :json})))

([{:keys [limit] :or {limit 8}}]
(:body (http/get (dashboard-aggregator-url limit) {:as :json}))))
(:body (http/get (dashboard-aggregator-url limit) {:as :json}))))
67 changes: 26 additions & 41 deletions src/terrain/clients/data_info.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
(ns terrain.clients.data-info
(:use [clojure-commons.core :only [remove-nil-values]]
[slingshot.slingshot :only [throw+ try+]]
[terrain.auth.user-attributes :only [current-user]])
(:require [clj-http.client :as http]
[clojure.string :as string]
[clojure.tools.logging :as log]
Expand All @@ -10,52 +7,54 @@
[cheshire.core :as json]
[me.raynes.fs :as fs]
[clj-icat-direct.icat :as db]
[clojure-commons.core :refer [remove-nil-values]]
[clojure-commons.error-codes :as error]
[clojure-commons.file-utils :as ft]
[clojure-commons.assertions :as assertions]
[slingshot.slingshot :refer [throw+ try+]]
[terrain.auth.user-attributes :refer [current-user]]
[terrain.clients.data-info.raw :as raw]
[terrain.services.filesystem.common-paths :as cp]
[terrain.services.filesystem.create :as cr]
[terrain.services.filesystem.icat :as icat]
[terrain.services.filesystem.sharing :as sharing]
[terrain.services.filesystem.stat :as st]
[terrain.services.filesystem.users :as users]
[terrain.services.filesystem.uuids :as uuids]
[terrain.services.filesystem.validators :as validators]
[terrain.util.config :as cfg])
(:import [clojure.lang IPersistentMap ISeq Keyword]
[java.util UUID]))

(defn ^Boolean irods-running?
(defn irods-running?
"Determines whether or not iRODS is running."
[]
^Boolean []
(-> (raw/request :get [] {:content-type :json})
:body
json/decode
(get "iRODS")))


(defn ^String user-home-folder
(defn user-home-folder
"Determines the home folder for the given user.
Parameters:
user - the user of the home folder.
Returns:
It returns the absolute path to the home folder."
[^String user]
^String [^String user]
(cp/user-home-dir user))


(defn ^String user-base-paths
(defn user-base-paths
"Fetches the home and trash paths for the given user.
Parameters:
user - the user of the base paths.
Returns:
A map of the absolute paths to the home and trash folders."
[^String user]
^String [^String user]
(-> (raw/base-paths user)
:body
(json/decode true)))
Expand Down Expand Up @@ -195,12 +194,6 @@
(let [path-uuid (uuid-for-path user source)]
(raw/rename user path-uuid (ft/basename dest))))

(defn- move-single
"Uses the data-info single-item directory change endpoint to move an item to a different directory."
[user source dest]
(let [path-uuid (uuid-for-path user source)]
(raw/move-single user path-uuid dest)))

(defn move
"Uses the data-info bulk mover endpoint to move items into a new directory."
[{:keys [user]} {:keys [sources dest]}]
Expand Down Expand Up @@ -283,19 +276,7 @@
[user data-id]
(:body (raw/get-avus user data-id :as :json)))

(defn ^ISeq list-user-groups
"retrieves a list of groups names a given user belongs to
Params:
user - the username of the user of interest
Returns:
It returns the list of group names."
[^String user]
(users/list-user-groups user))


(defn ^IPersistentMap stat-by-uuid
(defn stat-by-uuid
"Resolves a stat info for the entity with a given UUID.
Params:
Expand All @@ -304,14 +285,14 @@
Returns:
It returns a path-stat map containing an additional UUID field."
[^String user ^UUID uuid & {:keys [filter-include filter-exclude]}]
^IPersistentMap [^String user ^UUID uuid & {:keys [filter-include filter-exclude]}]
(-> (raw/collect-path-info user :ids [uuid] :filter-include filter-include :filter-exclude filter-exclude)
:body
json/decode
(get-in ["ids" (str uuid)])
walk/keywordize-keys))

(defn ^ISeq stats-by-uuids
(defn stats-by-uuids
"Resolves the stat info for the entities with the given UUIDs. The results are not paged.
Params:
Expand All @@ -327,7 +308,7 @@
Returns:
It returns a path-stat map containing an additional UUID field."
[user uuids params]
^ISeq [user uuids params]
(let [params (select-keys params [:ignore-missing :ignore-inaccessible :filter-include :filter-exclude])]
(-> (http/post (raw/data-info-url "/path-info")
{:query-params (assoc params :user user)
Expand All @@ -337,7 +318,7 @@
:body
:ids)))

(defn ^ISeq stats-by-uuids-paged
(defn stats-by-uuids-paged
"Resolves the stat info for the entities with the given UUIDs. The results are paged.
Params:
Expand All @@ -353,10 +334,14 @@
Returns:
It returns a page of stat info maps."
^ISeq
[^String user
^String sort-field
^String sort-order
^Integer limit



^Integer offset
^ISeq uuids
info-types]
Expand All @@ -373,7 +358,7 @@
:total (db/number-of-uuids-in-folder user (cfg/irods-zone) uuids info-types)}))


(defn ^Boolean uuid-accessible?
(defn uuid-accessible?
"Indicates if a data item is readable by a given user.
Parameters:
Expand All @@ -382,7 +367,7 @@
Returns:
It returns true if the user can access the data item, otherwise false"
[^String user ^UUID data-id]
^Boolean [^String user ^UUID data-id]
(uuids/uuid-accessible? user data-id))


Expand All @@ -397,19 +382,19 @@
(throw+ {:error_code error/ERR_NOT_FOUND :uuid data-id})))


(defn ^String resolve-data-type
(defn resolve-data-type
"Given filesystem id, it returns the type of data item it is, file or folder.
Parameters:
data-id - The UUID of the data item to inspect
Returns:
The type of the data item, `file` or `folder`"
[^UUID data-id]
^String [^UUID data-id]
(icat/resolve-data-type data-id))


(defn ^IPersistentMap share
(defn share
"grants access to a list of data entities for a list of users by a user
Params:
Expand All @@ -428,7 +413,7 @@
:path - the path the user didn't get access to
:reason - the reason access wasn't granted
:perm - the permission that was granted"
[^String user ^ISeq share-withs ^ISeq fpaths ^String perm]
^IPersistentMap [^String user ^ISeq share-withs ^ISeq fpaths ^String perm]
(sharing/share user share-withs fpaths perm))


Expand Down Expand Up @@ -470,15 +455,15 @@
(assertions/request-failure full-msg)))


(defn ^String mk-data-path-url-path
(defn mk-data-path-url-path
"This function constructs the url path to the resource backing a given data item.
Parameters:
path - the absolute iRODS path to the data item
Returns:
It returns the data-info URL path to the corresponding resource"
[^String path]
^String [^String path]
(let [nodes (fs/split path)
nodes (if (= "/" (first nodes)) (next nodes) nodes)]
(str "data/path/" (string/join "/" (map url/url-encode nodes)))))
Expand Down
2 changes: 1 addition & 1 deletion src/terrain/clients/data_info/raw.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(ns terrain.clients.data-info.raw
(:use [medley.core :only [remove-vals]])
(:require [clojure.tools.logging :as log]
[cemerick.url :as url]
[me.raynes.fs :as fs]
[medley.core :refer [remove-vals]]
[cheshire.core :as json]
[clj-http.client :as http]
[terrain.util.config :as cfg])
Expand Down
Loading

0 comments on commit 62b45d8

Please sign in to comment.