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

Fix return schemas #1441

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
16 changes: 8 additions & 8 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
flanders.core/def-map-type}}

:lint-as {puppetlabs.trapperkeeper.core/defservice clj-kondo.lint-as/def-catch-all
ctia.lib.compojure.api.core/GET clj-kondo.lint-as/def-catch-all
ctia.lib.compojure.api.core/PATCH clj-kondo.lint-as/def-catch-all
ctia.lib.compojure.api.core/POST clj-kondo.lint-as/def-catch-all
ctia.lib.compojure.api.core/PUT clj-kondo.lint-as/def-catch-all
ctia.lib.compojure.api.core/DELETE clj-kondo.lint-as/def-catch-all
ctia.lib.compojure.api.core/context clj-kondo.lint-as/def-catch-all

ctia.schemas.core/defschema clojure.core/def
ctia.lib.compojure.api.core/GET compojure.api.core/GET
ctia.lib.compojure.api.core/PATCH compojure.api.core/PATCH
ctia.lib.compojure.api.core/POST compojure.api.core/POST
ctia.lib.compojure.api.core/PUT compojure.api.core/PUT
ctia.lib.compojure.api.core/DELETE compojure.api.core/DELETE
ctia.lib.compojure.api.core/context compojure.api.core/context

ctia.schemas.core/defschema schemas.core/defschema

ctia.graphql.delayed/fn schema.core/fn}}
8 changes: 4 additions & 4 deletions .clj-kondo/ctia/schemas/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
`(do
~ddl
~spec-kw-ns
(def ~name-sym)))
(schema.core/defschema ~name-sym s/Any)))

(defmacro def-stored-schema [name-sym _sch]
`(def ~name-sym))
(defmacro def-stored-schema [name-sym sch]
`(schema.core/defschema ~name-sym ~sch))

(defmacro def-advanced-acl-schema [{:keys [name-sym
ddl
_spec-kw-ns
_open?]}]
`(do
~ddl
(def ~name-sym)))
(schema.core/defschema ~name-sym t/Any)))
6 changes: 4 additions & 2 deletions .clj-kondo/ctia/stores/es/store.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
[store-name
_entity
_stored-schema
_partial-stored-schema]
`(clojure.core/defrecord ~store-name [~(symbol "state")]))
_partial-stored-schema
& {:keys [extra-impls]}]
`(clojure.core/defrecord ~store-name [~(symbol "state")]
~@extra-impls))
8 changes: 4 additions & 4 deletions .clj-kondo/flanders/core.clj
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
(ns flanders.core)

(defmacro def-enum-type [name _values & _opts]
`(def ~name))
`(def ~name 'something))

(defmacro def-entity-type [name description & map-entries]
`(do
~description
~map-entries
(def ~name)))
(def ~name 'something)))

(defmacro def-eq [name value & opts]
`(do
~value
~opts
(def ~name)))
(def ~name 'something)))

(defmacro def-map-type [name map-entries & opts]
`(do
~map-entries
~opts
(def ~name)))
(def ~name 'something)))
9 changes: 9 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(def cheshire-version "5.10.2")
(def clj-http-fake-version "1.0.3")
(def clj-kondo-version "2024.08.02-SNAPSHOT")
(def clj-version "1.11.3")
(def jackson-version "2.15.2")
(def jackson-databind-version "2.15.2")
Expand All @@ -24,6 +25,7 @@

To add a new build, add an entry here and use CTIA_CI_PROFILES to select it."
{:next-clojure (str base-ci-profiles ",+next-clojure")
:clj-kondo (str "+test,+ci,+clj-kondo")
:uberjar "uberjar"
:default base-ci-profiles})
(def ci-profiles
Expand Down Expand Up @@ -232,6 +234,12 @@
;; "Full report at: /tmp/clojure-8187773283812483853.edn"
"-Dclojure.main.report=stderr"
"-XX:-OmitStackTraceInFastThrow"]}
:clj-kondo {:dependencies [[clj-kondo/clj-kondo ~clj-kondo-version]]
:aliases {"clj-kondo" ~(concat ["run" "-m" "clj-kondo.main/main" "--lint"]
["src" "test" "debug"]
["--config" ".clj-kondo/config.edn"
"--fail-level" "warning"
"--cache"])}}
:next-clojure {:dependencies [[org.clojure/clojure "1.12.0-master-SNAPSHOT"]]
:repositories [["snapshots" "https://oss.sonatype.org/content/repositories/snapshots/"]]}
:jmx {:jvm-opts ["-Dcom.sun.management.jmxremote"
Expand Down Expand Up @@ -335,6 +343,7 @@
"split-test" ["trampoline"
"with-profile" ~ci-profiles ;https://github.com/circleci/circleci.test/issues/13
"run" "-m" "ctia.dev.split-tests/dir" :project/test-paths]
"lint-kondo" ["with-profile" "clj-kondo" "clj-kondo"]
"tests" ["with-profile" ~ci-profiles "run" "-m" "circleci.test"]

"ci-run-tests" ["with-profile" ~ci-profiles "do" "clean," "javac," "split-test" ":no-gen"]
Expand Down
3 changes: 2 additions & 1 deletion src/ctia/auth/capabilities.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
(name plural)
(name entity)))))))

(s/defn all-entity-capabilities [] :- #{(s/pred simple-keyword?)}
(s/defn all-entity-capabilities :- #{(s/pred simple-keyword?)}
[]
(apply set/union
(map #(gen-capabilities-for-entity-and-accesses
% (keys prefixes))
Expand Down
1 change: 0 additions & 1 deletion src/ctia/bulk/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@

(s/defn patch-bulk
[bulk
tempids :- TempIDs
auth-identity :- auth/AuthIdentity
params
services :- APIHandlerServices]
Expand Down
1 change: 0 additions & 1 deletion src/ctia/bulk/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
:auth-identity auth-identity
(core/validate-bulk-size! bulk services)
(ok (core/patch-bulk bulk
{} ;; transient ids only supported via PATCH bundle/import
auth-identity
(common/wait_for->refresh wait_for)
services))))
Expand Down
1 change: 0 additions & 1 deletion src/ctia/bundle/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
[ctia.store :as store]
[ctia.store-service.schemas :refer [GetStoreFn]]
[ctim.domain.id :as id]
[ring.util.http-response :refer [bad-request!]]
[schema.core :as s]
[schema-tools.core :as st])
(:import
Expand Down
3 changes: 1 addition & 2 deletions src/ctia/bundle/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
BundleExportOptions
BundleExportQuery]]
[ctia.http.routes.common :as common]
[ctia.schemas.core :refer [APIHandlerServices NewBundle]]
[ctia.schemas.core :refer [APIHandlerServices]]
[ring.swagger.json-schema :refer [describe]]
[ring.util.http-response :refer [ok bad-request]]
[schema-tools.core :as st]
[schema.core :as s]))

(def export-capabilities
Expand Down
13 changes: 6 additions & 7 deletions src/ctia/entity/asset_mapping.clj
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@

(s/defn realize-asset-mapping
:- (RealizeFnResult (with-error StoredAssetMapping))
[{:keys [asset_ref]
:as new-entity}
[new-entity
id tempids & rest-args]
(delayed/fn :- (with-error StoredAssetMapping)
[rt-ctx :- GraphQLRuntimeContext]
(-> asset-mapping-default-realize
(schemas/lift-realize-fn-with-context rt-ctx)
(apply new-entity id tempids rest-args)
(asset/set-asset-ref tempids))))
[rt-ctx :- GraphQLRuntimeContext]
(-> asset-mapping-default-realize
(schemas/lift-realize-fn-with-context rt-ctx)
(apply new-entity id tempids rest-args)
(asset/set-asset-ref tempids))))

(def asset-mapping-mapping
{"asset-mapping"
Expand Down
3 changes: 1 addition & 2 deletions src/ctia/entity/investigation/flanders_schemas.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns ctia.entity.investigation.flanders-schemas
(:require [ctim.schemas.common :as c]
[flanders.core :as f :refer [def-entity-type def-eq]]
[schema.core :as s]))
[flanders.core :as f :refer [def-entity-type def-eq]]))

(def type-identifier "investigation")

Expand Down
12 changes: 7 additions & 5 deletions src/ctia/flows/crud.clj
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@

(s/defn find-create-entity-id
[services :- HTTPShowServices]
(s/fn [{identity-obj :identity
:keys [entity-type tempids]} :- FlowMap
entity] :- s/Str
(s/fn :- s/Str
[{identity-obj :identity
:keys [entity-type tempids]} :- FlowMap
entity]
(or
(get tempids (:id entity))
(when-let [entity-id (find-checked-id entity services)]
Expand All @@ -93,8 +94,9 @@

(s/defn ^:private find-existing-entity-id
[prev-entity-fn]
(s/fn [_fm :- FlowMap
{id :id :as _entity}] :- (s/maybe s/Str)
(s/fn :- (s/maybe s/Str)
[_fm :- FlowMap
{id :id :as _entity}]
(if (and (seq id) (prev-entity-fn id))
(id/str->short-id id)
id)))
Expand Down
2 changes: 1 addition & 1 deletion src/ctia/schemas/graphql/pagination.clj
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
[{:keys [data paging]} :- Result
{:keys [forward-paging?
backward-paging?
offset]}] :- ConnectionParams
offset]}]
(let [edges (data->edges data offset)]
{:pageInfo
{:hasNextPage (or (and forward-paging?
Expand Down
2 changes: 0 additions & 2 deletions test/ctia/bulk/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,11 @@
"visible entities that the user is not allowed to write on are returned as forbidden errors"))]
(testing "bulk-patch shall properly patch submitties entitites"
(let [other-group-res (sut/patch-bulk bulk-patch
{}
other-group-ident
{:refresh "true"}
services)
{:keys [sightings indicators]}
(sut/patch-bulk bulk-patch
{}
ident
{:refresh "true"}
services)]
Expand Down
2 changes: 1 addition & 1 deletion test/ctia/entity/vulnerability/cpe_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns ctia.entity.vulnerability.cpe-test
(:require
[clojure.test :refer :all]
[clojure.test :refer [are deftest is testing use-fixtures]]
[clj-momo.test-helpers.core :as mth]
[ctia.entity.vulnerability.cpe :as sut]))

Expand Down
2 changes: 2 additions & 0 deletions test/ctia/http/routes/graphql/attack_pattern_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
[fake-whoami-service :as whoami-helpers]
[graphql :as gh]
[store :refer [test-for-each-store-with-app]]]
ctia.entity.feedback.schemas
ctia.entity.relationship.schemas
[ctim.examples.attack-patterns :refer [new-attack-pattern-maximal]]))

(use-fixtures :once (join-fixtures [mth/fixture-schema-validation
Expand Down
2 changes: 2 additions & 0 deletions test/ctia/http/routes/graphql/incident_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
[fake-whoami-service :as whoami-helpers]
[graphql :as gh]
[store :refer [test-for-each-store-with-app]]]
ctia.entity.feedback.schemas
ctia.entity.relationship.schemas
[ctim.examples.incidents :refer [new-incident-maximal]]))

(use-fixtures :once (join-fixtures [mth/fixture-schema-validation
Expand Down
38 changes: 19 additions & 19 deletions test/ctia/http/routes/ring_swagger_leak_test.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns ctia.http.routes.ring-swagger-leak-test
(:require [clojure.test :refer [deftest is testing]]
(:require [clojure.test :refer [deftest is]]
[ring.swagger.coerce :as sut]))

(defmacro when-class [cls & body]
Expand All @@ -10,21 +10,21 @@
;;JDK 9+
(when-class java.lang.ref.Cleaner
(deftest ring-swagger-leak-test
(let [cleaner (java.lang.ref.Cleaner/create)]
(let [released? (atom false)
collectable (doto (fn [])
sut/time-matcher
sut/custom-matcher
sut/coercer)
_ (.register cleaner collectable (reify
Runnable
(run [_] (reset! released? true))))]
(reduce (fn [_ i]
(System/gc)
(System/runFinalization)
(Thread/sleep 100)
(if @released?
(reduced nil)
(println "WARNING: potential memory leak in" `ring-swagger-leak-test)))
nil (range 100))
(is @released?)))))
(let [cleaner (java.lang.ref.Cleaner/create)
released? (atom false)
collectable (doto (fn [])
sut/time-matcher
sut/custom-matcher
sut/coercer)
_ (.register cleaner collectable (reify
Runnable
(run [_] (reset! released? true))))]
(reduce (fn [_ _]
(System/gc)
(System/runFinalization)
(Thread/sleep 100)
(if @released?
(reduced nil)
(println "WARNING: potential memory leak in" `ring-swagger-leak-test)))
nil (range 100))
(is @released?))))
3 changes: 1 addition & 2 deletions test/ctia/task/settings_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
(:require [clojure.test :refer [deftest is testing use-fixtures]]
[ctia.task.settings :as sut]
[ctia.stores.es.init :as init]
[ctia.test-helpers.es :as es-helpers]
[clj-momo.test-helpers.core :as mth]
[ductile
[index :as es-index]
[conn :as es-conn]]
[ctia.test-helpers
[core :as h :refer [fixture-ctia]]
[es :refer [fixture-properties:es-store fixture-delete-store-indexes]]]))
[es :as es-helpers :refer [fixture-properties:es-store fixture-delete-store-indexes]]]))

(defn fixture-update-stores [t]
(h/with-config-transformer*
Expand Down
2 changes: 1 addition & 1 deletion test/ctia/test_helpers/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
[schema.core :as s])
(:import [java.util UUID]))

(def ^:dynamic ^:private *current-app*)
(def ^:dynamic ^:private *current-app* nil)

(defn set-of-es-versions-to-test []
{:post [(set? %)]}
Expand Down
3 changes: 1 addition & 2 deletions test/ctia/test_helpers/core_test.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(ns ctia.test-helpers.core-test
(:require [clojure.test :refer [deftest is testing]]
[ctia.test-helpers.core :as sut])
(:import [clojure.lang ExceptionInfo]
[java.util UUID]))
(:import [clojure.lang ExceptionInfo]))

(deftest split-property-to-keywords-test
(is (= (sut/split-property-to-keywords
Expand Down
3 changes: 1 addition & 2 deletions test/ctia/test_helpers/pagination.clj
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@
(id/long-id->id last-id)))
base-x-next (format "limit=%s&offset=%s"
limit
(+ offset limit)
search-after-id)
(+ offset limit))
expected-x-next (if search-after-id
(str base-x-next "&search_after=" search-after-id)
base-x-next)
Expand Down