This repository has been archived by the owner on Oct 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
connect.clj
108 lines (97 loc) · 6.58 KB
/
connect.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
;
; Copyright 2017 Fintech Open Source Foundation
; SPDX-License-Identifier: Apache-2.0
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
(ns clj-symphony.connect
"Operations related to connections to a Symphony pod.")
(defn- parse-params
"Parses connection parameters, substituting a :pod-id for the default URLs,
if present."
[params]
(if-let [pod-id (:pod-id params)]
(dissoc (merge { :session-auth-url (str "https://" pod-id "-api.symphony.com/sessionauth")
:key-auth-url (str "https://" pod-id "-api.symphony.com/keyauth")
:agent-api-url (str "https://" pod-id ".symphony.com/agent") ; Note: no -api as of v1.46
:pod-api-url (str "https://" pod-id ".symphony.com/pod") } ; Note: not -api !
params)
:pod-id)
params))
(defn connect
"Connect to a Symphony pod as a given service account user. Returns a
'connection' object that should be used in all subsequent API calls.
`params` is a map containing:
| Key | Description |
|---------------------|-----------------------------------------------------------------------------------------------------------------------|
| `:pod-id` | The id of the pod to connect to - will autopopulate whichever of the 4 URLs aren't provided. (optional - see below) |
| `:session-auth-url` | The URL of the session authentication endpoint. (optional - see below) |
| `:key-auth-url` | The URL of the key authentication endpoint. (optional - see below) |
| `:agent-api-url` | The URL of the agent API. (optional - see below) |
| `:pod-api-url` | The URL of the Pod API. (optional - see below) |
| `:trust-store` | A pair of strings containing the path to the trust store and the password of the trust store. (mandatory) |
| `:user-cert` | A pair of strings containing the path to the bot user's certificate and the password of that certificate. (mandatory) |
| `:user-email` | The email address of the bot user. (mandatory) |
Note: if `:pod-id` is not provided, `:session-auth-url` and `:key-auth-url`
and `:agent-api-url` and `:pod-api-url` are all mandatory."
[params]
(let [params (parse-params params)
session-auth-url (:session-auth-url params)
key-auth-url (:key-auth-url params)
agent-api-url (:agent-api-url params)
pod-api-url (:pod-api-url params)
trust-store (:trust-store params)
user-cert (:user-cert params)
user-email (:user-email params)
jersey-client-config (doto (org.glassfish.jersey.client.ClientConfig.) ; Note: redundant as of SJC v1.1.5
(.register (org.symphonyoss.symphony.agent.invoker.JSON.)))
http-client (org.symphonyoss.client.impl.CustomHttpClient/getClient ^String (first user-cert) ^String (second user-cert)
^String (first trust-store) ^String (second trust-store)
jersey-client-config)
; Awaiting release of the fix for https://github.com/symphonyoss/symphony-java-client/issues/104
; sjc-config (-> (org.symphonyoss.client.SymphonyClientConfigBuilder/newBuilder)
; (.withSessionAuthUrl session-auth-url)
; (.withKeyAuthUrl key-auth-url)
; (.withPodUrl pod-api-url)
; (.withAgentUrl agent-api-url)
; (.withTrustStore (first trust-store) (.toCharArray ^String (second trust-store)))
; (.withUserCreds user-email (first user-cert) (.toCharArray ^String (second user-cert)))
; (.withJMXHealthcheck true)
; (.withServices true)
; (.build))
; connection (doto (org.symphonyoss.client.SymphonyClientFactory/getClient org.symphonyoss.client.SymphonyClientFactory$TYPE/V4)
; (.init http-client sjc-config))]
; connection))
connection (doto (org.symphonyoss.client.SymphonyClientFactory/getClient org.symphonyoss.client.SymphonyClientFactory$TYPE/V4)
(.setDefaultHttpClient http-client))
auth-client (org.symphonyoss.symphony.clients.AuthenticationClient. session-auth-url key-auth-url http-client)
auth (.authenticate auth-client)
_ (.init connection http-client auth ^String user-email ^String agent-api-url ^String pod-api-url)]
connection))
(defn disconnect
"Disconnect from a Symphony pod. The connection object should be discarded after this method is called."
[^org.symphonyoss.client.SymphonyClient c]
(.shutdown c))
(defn pod-version
"Returns the version of the Symphony pod at the other end of the given connection, as a string in `major.minor.bugfix` format."
[^org.symphonyoss.client.SymphonyClient c]
(.getPodVersion (.v2HealthCheckGet (.getAgentSystemApi (.getSymphonyApis c)) nil nil)))
(defn agent-version
"Returns the version of the Symphony agent at the other end of the given connection, as a string in `major.minor.bugfix` format."
[^org.symphonyoss.client.SymphonyClient c]
(.getAgentVersion (.v2HealthCheckGet (.getAgentSystemApi (.getSymphonyApis c)) nil nil)))
(defn version
"Deprecated - please use pod-version instead."
{ :deprecated "0.5.0" }
[c]
(pod-version c))