@@ -12,8 +12,31 @@ class Insight(AtlassianRestAPI):
12
12
# https://insight-javadoc.riada.io/insight-javadoc-8.6/insight-rest/
13
13
14
14
def __init__ (self , * args , ** kwargs ):
15
+ kwargs ["api_root" ] = "rest/insight/1.0"
16
+ # If cloud is set to true, trigger private __cloud__init method
17
+ if kwargs .get ("cloud" ):
18
+ args , kwargs = self .__cloud_init (* args , ** kwargs )
15
19
super (Insight , self ).__init__ (* args , ** kwargs )
16
20
21
+ def __cloud_init (self , * args , ** kwargs ):
22
+ # trigger a normal init and avoid looping
23
+ del kwargs ["cloud" ]
24
+ temp = Insight (* args , ** kwargs )
25
+ # retrieve cloud workspace id and generate the api_root
26
+ kwargs ["api_root" ] = "/jsm/insight/workspace/{}/v1/" .format (temp .__get_workspace_id ())
27
+ # insight cloud uses the atlassian base url, not custom instnace urls
28
+ kwargs ["url" ] = "https://api.atlassian.com"
29
+ # set cloud back to true and return
30
+ kwargs ["cloud" ] = True
31
+ # Insight cloud is particular about its headers..
32
+ self .default_headers = {"Accept" : "application/json" }
33
+ return args , kwargs
34
+
35
+ def __get_workspace_id (self ):
36
+ return self .get ("rest/servicedeskapi/insight/workspace" , headers = self .default_headers ,)["values" ][
37
+ 0
38
+ ]["workspaceId" ]
39
+
17
40
# Attachments
18
41
def get_attachments_of_objects (self , object_id ):
19
42
"""
@@ -45,7 +68,9 @@ def get_attachments_of_objects(self, object_id):
45
68
commentOutput: (string)
46
69
url: required(string)
47
70
"""
48
- url = "rest/insight/1.0/attachments/object/{objectId}" .format (objectId = object_id )
71
+ if self .cloud :
72
+ raise NotImplementedError
73
+ url = self .url_joiner (self .api_root , "attachments/object/{objectId}" .format (objectId = object_id ))
49
74
return self .get (url )
50
75
51
76
def upload_attachment_to_object (self , object_id , filename ):
@@ -54,6 +79,8 @@ def upload_attachment_to_object(self, object_id, filename):
54
79
:param object_id: int
55
80
:param filename: str, name, if file in current directory or full path to file
56
81
"""
82
+ if self .cloud :
83
+ raise NotImplementedError
57
84
log .warning ("Adding attachment..." )
58
85
url = "rest/insight/1.0/attachments/object/{objectId}" .format (objectId = object_id )
59
86
with open (filename , "rb" ) as attachment :
@@ -65,6 +92,8 @@ def delete_attachment(self, attachment_id):
65
92
Add attachment to Object
66
93
:param attachment_id: int
67
94
"""
95
+ if self .cloud :
96
+ raise NotImplementedError
68
97
log .warning ("Adding attachment..." )
69
98
url = "rest/insight/1.0/attachments/{attachmentId}" .format (attachmentId = attachment_id )
70
99
return self .delete (url )
@@ -103,6 +132,8 @@ def add_comment_to_object(self, comment, object_id, role):
103
132
"canDelete": true
104
133
}
105
134
"""
135
+ if self .cloud :
136
+ raise NotImplementedError
106
137
params = {"comment" : comment , "objectId" : object_id , "role" : role }
107
138
url = "rest/insight/1.0/comment/create"
108
139
return self .post (url , params = params )
@@ -113,6 +144,8 @@ def get_comment_of_object(self, object_id):
113
144
:param object_id:
114
145
:return:
115
146
"""
147
+ if self .cloud :
148
+ raise NotImplementedError
116
149
url = "rest/insight/1.0/comment/object/{objectId}" .format (objectId = object_id )
117
150
return self .get (url )
118
151
@@ -130,15 +163,15 @@ def get_icon_by_id(self, id):
130
163
"url48": "http://jira/rest/insight/1.0/icon/1/icon.png?size=48"
131
164
}
132
165
"""
133
- url = "rest/insight/1.0/ icon/{id}" .format (id = id )
166
+ url = self . url_joiner ( self . api_root , " icon/{id}" .format (id = id ) )
134
167
return self .get (url )
135
168
136
169
def get_all_global_icons (self ):
137
170
"""
138
171
All existing global icons
139
172
:return:
140
173
"""
141
- url = "rest/insight/1.0/ icon/global"
174
+ url = self . url_joiner ( self . api_root , " icon/global")
142
175
return self .get (url )
143
176
144
177
# Import
@@ -149,7 +182,7 @@ def start_import_configuration(self, id):
149
182
:param id:
150
183
:return:
151
184
"""
152
- url = "rest/insight/1.0/ import/start/{id}". format ( id = id )
185
+ url = self . url_joiner ( self . api_root , " import/start/{id}" )
153
186
return self .post (url )
154
187
155
188
# Index
@@ -159,22 +192,37 @@ def reindex_insight(self):
159
192
Should the reindex clean the index before doing the reindex
160
193
:return:
161
194
"""
162
- url = "rest/insight/1.0/index/reindex/start"
195
+ if self .cloud :
196
+ raise NotImplementedError
197
+ url = self .url_joiner (self .api_root , "index/reindex/start" )
163
198
return self .post (url )
164
199
165
200
def reindex_current_node_insight (self ):
166
201
"""
167
202
Should the reindex clean the index before doing the reindex
168
203
:return:
169
204
"""
170
- url = "rest/insight/1.0/index/reindex/currentnode"
205
+ if self .cloud :
206
+ raise NotImplementedError
207
+ url = self .url_joiner (self .api_root , "index/reindex/currentnode" )
171
208
return self .post (url )
172
209
173
210
# IQL
174
211
# Resource dedicated to finding objects based on the Insight Query Language (IQL)
175
- def iql (self , iql , object_schema_id , page = 1 , order_by_attribute_id = None , order_asc = True , result_per_page = 25 ,
176
- include_attributes = True , include_attributes_deep = 1 , include_type_attributes = False ,
177
- include_extended_info = False , extended = None ):
212
+ def iql (
213
+ self ,
214
+ iql ,
215
+ object_schema_id ,
216
+ page = 1 ,
217
+ order_by_attribute_id = None ,
218
+ order_asc = True ,
219
+ result_per_page = 25 ,
220
+ include_attributes = True ,
221
+ include_attributes_deep = 1 ,
222
+ include_type_attributes = False ,
223
+ include_extended_info = False ,
224
+ extended = None ,
225
+ ):
178
226
"""
179
227
180
228
:param iql:
@@ -201,5 +249,5 @@ def iql(self, iql, object_schema_id, page=1, order_by_attribute_id=None, order_a
201
249
params ["includeExtendedInfo" ] = include_extended_info
202
250
if extended :
203
251
params ["extended" ] = extended
204
- url = "rest/insight/1.0/ iql/objects"
252
+ url = self . url_joiner ( self . api_root , " iql/objects")
205
253
return self .get (url , params = params )
0 commit comments