Skip to content

Commit

Permalink
Merge pull request #91 from gbuisson/issue-#78
Browse files Browse the repository at this point in the history
Refactored references
  • Loading branch information
polygloton committed Mar 10, 2016
2 parents 83161ba + 04e9ca7 commit 8a2703e
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 152 deletions.
34 changes: 10 additions & 24 deletions src/cia/schemas/relationships.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,32 @@
(s/optional-key :relationship) s/Str}
reference-map))

(defn relation [string-type map-type]
(s/conditional
map? map-type
:else string-type))

(s/defschema RelatedIndicators
[(relation IndicatorReference
(enriched-ref {:indicator IndicatorReference}))])
[(enriched-ref {:indicator_id IndicatorReference})])

(s/defschema RelatedActors
[(relation ActorReference
(enriched-ref {:actor ActorReference}))])
[(enriched-ref {:actor_id ActorReference})])

(s/defschema RelatedCampaigns
[(relation CampaignReference
(enriched-ref {:campaign CampaignReference}))])
[(enriched-ref {:campaign_id CampaignReference})])

(s/defschema RelatedCOAs
[(relation COAReference
(enriched-ref {:COA COAReference}))])
[(enriched-ref {:COA_id COAReference})])

(s/defschema RelatedExploitTargets
[(relation ExploitTargetReference
(enriched-ref {:exploit_target ExploitTargetReference}))])
[(enriched-ref {:exploit_target_id ExploitTargetReference})])

(s/defschema RelatedIncidents
[(relation IncidentReference
(enriched-ref {:incident IncidentReference}))])
[(enriched-ref {:incident_id IncidentReference})])

(s/defschema RelatedIndicators
[(relation IndicatorReference
(enriched-ref {:indicator IndicatorReference}))])
[(enriched-ref {:indicator_id IndicatorReference})])

(s/defschema RelatedJudgements
[(relation JudgementReference
(enriched-ref {:judgement JudgementReference}))])
[(enriched-ref {:judgement_id JudgementReference})])

(s/defschema RelatedTTP
(enriched-ref {:ttp TTPReference}))
(enriched-ref {:ttp_id TTPReference}))

(s/defschema RelatedTTPs
[(relation TTPReference
RelatedTTP)])
[(enriched-ref {:ttp_id TTPReference})])
36 changes: 14 additions & 22 deletions src/cia/stores/es/mapping.clj
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
(def related-identities
{:type "nested"
:properties (assoc related
:identity string)})
:identity_id string)})

(def related-actors
{:type "nested"
:properties (assoc related
:actor string)})
:actor_id string)})

(def tg-identity
{:type "nested"
Expand Down Expand Up @@ -95,39 +95,39 @@
{:type "nested"
:properties
(assoc related
:indicator string)})
:indicator_id string)})

(def related-judgements
{:type "nested"
:properties
(assoc related
:judgement string)})
:judgement_id string)})

(def related-coas
{:type "nested"
:properties
(assoc related
:COA string)})
:COA_id string)})

(def related-campaigns
{:type "nested"
:properties
(assoc related
:campaign string)})
:campaign_id string)})

(def related-exploit-targets
{:type "nested"
:properties (assoc related
:exploit_target string)})
:exploit_target_id string)})
(def related-ttps
{:type "nested"
:properties (assoc related
:ttp string)})
:ttp_id string)})

(def related-incidents
{:type "nested"
:properties (assoc related
:incident string)})
:incident_id string)})

(def indicator-sightings
{:type "nested"
Expand Down Expand Up @@ -302,9 +302,7 @@
:reason string
:source_uri string
:reason_uri string
;;:indicators related-indicators
;;TBD enable again when proper schema is integrated
:indicators {:type "nested" :enabled false}
:indicators related-indicators
:owner string
:created ts
:modified ts}}})
Expand All @@ -331,7 +329,6 @@
:type string
:observable observable
:judgements related-judgements
;;:judgements {:type "nested"}
:composite_indicator_expression {:type "nested"
:properties
{:operator string
Expand Down Expand Up @@ -384,13 +381,9 @@
:sophistication string
:intended_effect string
:planning_and_operational_support string
;;:observed_TTPs
;; related-ttps TBD enable again when schema is stricter
:observed_TTPs {:type "nested" :enabled false}
;;:associated_campaigns related-campaigns
:associated_campaigns {:type "nested" :enabled false}
;;:associated_actors related-actors
:associated_actors {:type "nested" :enabled false}
:observed-ttps related-ttps
:associated_campaigns related-campaigns
:associated_actors related-actors
:confidence string
:owner string
:created ts
Expand Down Expand Up @@ -461,8 +454,7 @@
:related_observables observable
:leveraged_TTPs related-ttps
:attributed_actors related-actors
;; :related_incidents related-incidents
:related_incidents {:type "nested" :enabled false}
:related_incidents related-incidents
:intended_effect string
:owner string
:created ts
Expand Down
2 changes: 1 addition & 1 deletion src/cia/stores/es/query.clj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
:path "judgements"
:query
(q/bool {:must
(q/terms :judgements.judgement
(q/terms :judgements.judgement_id
judgement-ids)}))]

(q/filtered :filter f)))
Expand Down
4 changes: 2 additions & 2 deletions src/cia/stores/memory.clj
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@
(filter (fn [indicator]
(some (fn [judgement-relation]
(let [judgement-id (if (map? judgement-relation)
(:judgement judgement-relation)
judgement-relation)]
(:judgement_id judgement-relation)
judgement-relation)]
(contains? judgement-ids judgement-id)))
(:judgements indicator)))
(vals @indicator-state))))
Expand Down
2 changes: 1 addition & 1 deletion src/cia/stores/sql/judgement.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

(def judgement-indicator-relationship-map
{:entity-relationship-key :indicators
:relationship-reference-key :indicator
:relationship-reference-key :indicator_id
:entity-id-key :judgement_id
:other-id-key :indicator_id})

Expand Down
Loading

0 comments on commit 8a2703e

Please sign in to comment.