@@ -12,8 +12,31 @@ class Insight(AtlassianRestAPI):
1212 # https://insight-javadoc.riada.io/insight-javadoc-8.6/insight-rest/
1313
1414 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 )
1519 super (Insight , self ).__init__ (* args , ** kwargs )
1620
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+
1740 # Attachments
1841 def get_attachments_of_objects (self , object_id ):
1942 """
@@ -45,7 +68,9 @@ def get_attachments_of_objects(self, object_id):
4568 commentOutput: (string)
4669 url: required(string)
4770 """
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 ))
4974 return self .get (url )
5075
5176 def upload_attachment_to_object (self , object_id , filename ):
@@ -54,6 +79,8 @@ def upload_attachment_to_object(self, object_id, filename):
5479 :param object_id: int
5580 :param filename: str, name, if file in current directory or full path to file
5681 """
82+ if self .cloud :
83+ raise NotImplementedError
5784 log .warning ("Adding attachment..." )
5885 url = "rest/insight/1.0/attachments/object/{objectId}" .format (objectId = object_id )
5986 with open (filename , "rb" ) as attachment :
@@ -65,6 +92,8 @@ def delete_attachment(self, attachment_id):
6592 Add attachment to Object
6693 :param attachment_id: int
6794 """
95+ if self .cloud :
96+ raise NotImplementedError
6897 log .warning ("Adding attachment..." )
6998 url = "rest/insight/1.0/attachments/{attachmentId}" .format (attachmentId = attachment_id )
7099 return self .delete (url )
@@ -103,6 +132,8 @@ def add_comment_to_object(self, comment, object_id, role):
103132 "canDelete": true
104133 }
105134 """
135+ if self .cloud :
136+ raise NotImplementedError
106137 params = {"comment" : comment , "objectId" : object_id , "role" : role }
107138 url = "rest/insight/1.0/comment/create"
108139 return self .post (url , params = params )
@@ -113,6 +144,8 @@ def get_comment_of_object(self, object_id):
113144 :param object_id:
114145 :return:
115146 """
147+ if self .cloud :
148+ raise NotImplementedError
116149 url = "rest/insight/1.0/comment/object/{objectId}" .format (objectId = object_id )
117150 return self .get (url )
118151
@@ -130,15 +163,15 @@ def get_icon_by_id(self, id):
130163 "url48": "http://jira/rest/insight/1.0/icon/1/icon.png?size=48"
131164 }
132165 """
133- url = "rest/insight/1.0/ icon/{id}" .format (id = id )
166+ url = self . url_joiner ( self . api_root , " icon/{id}" .format (id = id ) )
134167 return self .get (url )
135168
136169 def get_all_global_icons (self ):
137170 """
138171 All existing global icons
139172 :return:
140173 """
141- url = "rest/insight/1.0/ icon/global"
174+ url = self . url_joiner ( self . api_root , " icon/global")
142175 return self .get (url )
143176
144177 # Import
@@ -149,7 +182,7 @@ def start_import_configuration(self, id):
149182 :param id:
150183 :return:
151184 """
152- url = "rest/insight/1.0/ import/start/{id}". format ( id = id )
185+ url = self . url_joiner ( self . api_root , " import/start/{id}" )
153186 return self .post (url )
154187
155188 # Index
@@ -159,22 +192,37 @@ def reindex_insight(self):
159192 Should the reindex clean the index before doing the reindex
160193 :return:
161194 """
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" )
163198 return self .post (url )
164199
165200 def reindex_current_node_insight (self ):
166201 """
167202 Should the reindex clean the index before doing the reindex
168203 :return:
169204 """
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" )
171208 return self .post (url )
172209
173210 # IQL
174211 # 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+ ):
178226 """
179227
180228 :param iql:
@@ -201,5 +249,5 @@ def iql(self, iql, object_schema_id, page=1, order_by_attribute_id=None, order_a
201249 params ["includeExtendedInfo" ] = include_extended_info
202250 if extended :
203251 params ["extended" ] = extended
204- url = "rest/insight/1.0/ iql/objects"
252+ url = self . url_joiner ( self . api_root , " iql/objects")
205253 return self .get (url , params = params )
0 commit comments