-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CMR-9187 - Sending provider events to ordering (#1934)
* Calling CRM Ordering when a provider is created or updated so that it can resync the copy of providers that it has * Update to transmit access control to use same client id as ordering Co-authored-by: K. Lucia Z. <[email protected]>
- Loading branch information
Showing
12 changed files
with
132 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"data": { | ||
"syncProviders": { | ||
"added": [], | ||
"deleted": [], | ||
"message": "0 providers changed" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
(ns cmr.transmit.ordering | ||
"Handle all communications to the CMR-Ordering application, a graphql app which | ||
processes orders for Earthdata Search and CMR. This application needs to know | ||
when CMR has changed a provider so that it can download the latest provider | ||
list" | ||
|
||
(:require | ||
[clj-http.client :as client] | ||
[cmr.common.api.context :as ctxt] | ||
[cmr.common.log :as log :refer (debug info warn error)] | ||
[cmr.common.mime-types :as mime] | ||
[cmr.transmit.config :as config] | ||
[cmr.transmit.connection :as conn] | ||
[clojure.core.async :as async] | ||
[clojure.string :as string])) | ||
|
||
;; GraphQl query to call mutation of data | ||
;; query='mutation SyncProvider {syncProviders {added,deleted,message}}' | ||
;; server="https://cmr.sit.earthdata.nasa.gov/ordering/api" | ||
;; curl -s \ | ||
;; --header 'Content-Type: application/json' \ | ||
;; --data "{\"query\": \"$query\"}" \ | ||
;; "$server" | ||
|
||
(def order-provider-sync-message | ||
"mutation SyncProvider {syncProviders {added,deleted,message}}") | ||
|
||
(defn- context->just-token | ||
"graph-ql does not require bearer in the token" | ||
[context] | ||
(-> context | ||
:token | ||
(string/replace-first "Bearer:" "") | ||
(string/replace-first "bearer:" "") | ||
string/trim)) | ||
|
||
(defn- send-to-ordering | ||
"A generic message send action" | ||
[context message] | ||
(let [conn (config/context->app-connection context :ordering) | ||
url (conn/root-url conn) | ||
token (context->just-token context) | ||
params (merge | ||
(config/conn-params conn) | ||
{:body (format "{\"query\": \"%s\"}" message) | ||
:headers (merge | ||
(ctxt/context->http-headers context) | ||
{:content-type mime/json | ||
:client-id config/cmr-client-id | ||
config/token-header token}) | ||
:throw-exceptions false}) | ||
response (client/post url params)] | ||
(info (format "Provider change event, notifying [%s] - response is [%s]\n" url response)))) | ||
|
||
(defn notify-ordering | ||
"Sent a message to the sync mutation at cmr-ordering" | ||
[context] | ||
(debug "sending sync message to cmr-ordering") | ||
(async/go (send-to-ordering context order-provider-sync-message))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(ns cmr.transmit.test.ordering | ||
"Contains unit tests for verifying ordering notifications." | ||
(:require [clojure.test :refer :all] | ||
[clj-http.client :as client] | ||
[cmr.common.util :refer [are3]] | ||
[cmr.transmit.ordering :as ordering])) | ||
|
||
(deftest just-token-test | ||
(testing "Test token prep function to ensure graphql gets the correct form" | ||
(are3 | ||
[expected provided] | ||
(do (let [context {:token provided}] | ||
(is (= expected (#'cmr.transmit.ordering/context->just-token context))))) | ||
"No bearer" "1234" "1234" | ||
"Upper case bearer" "1234" "Bearer:1234" | ||
"Lower case bearer" "1234" "bearer:1234" | ||
"Spaces around bearer" "1234" " bearer: 1234" | ||
"nothing" "" "" | ||
"bearer but no token" "" " Bearer: "))) |