@@ -57,16 +57,20 @@ def __init__(self, *args, **kwargs):
57
57
if db_settings ['USER' ] and db_settings ['PASSWORD' ]:
58
58
super (JiraManagerMixin , self ).__init__ (
59
59
server = db_settings ['NAME' ],
60
- basic_auth = (db_settings ['USER' ],
61
- db_settings ['PASSWORD' ]))
60
+ basic_auth = (
61
+ db_settings ['USER' ],
62
+ db_settings ['PASSWORD' ]
63
+ )
64
+ )
62
65
elif db_settings ['SECURITY' ]:
63
66
jwt = {
64
67
'secret' : db_settings ['SECURITY' ].shared_secret ,
65
- 'payload' : db_settings ['SECURITY' ].key
68
+ 'payload' : { 'iss' : db_settings ['SECURITY' ].key },
66
69
}
67
70
super (JiraManagerMixin , self ).__init__ (
68
71
server = db_settings ['NAME' ],
69
- jwt = jwt )
72
+ jwt = jwt
73
+ )
70
74
except Exception as err :
71
75
logger .error (err )
72
76
@@ -252,12 +256,30 @@ def delete(self):
252
256
253
257
class JiraIssueModel (JiraIssue ):
254
258
def __init__ (self , * args , ** kwargs ):
255
- db = self .get_db ().connection
256
259
options = copy .copy (JIRA .DEFAULT_OPTIONS )
257
- options ['server' ] = db .uri
258
260
session = ResilientSession ()
259
- session .auth = (db .user , db .password )
261
+ jwt = None
262
+ if self .AtlassianMeta .db :
263
+ # dynamic models via jira-addon
264
+ db = connections .databases [self .AtlassianMeta .db ]
265
+ options ['server' ] = db ['NAME' ]
266
+ sc = db ['SECURITY' ]
267
+ jwt = {
268
+ 'secret' : sc .shared_secret ,
269
+ 'payload' : {'iss' : sc .key },
270
+ }
271
+ else :
272
+ # static models
273
+ db = self .get_db ().connection
274
+ options ['server' ] = db .uri
275
+ session .auth = (db .user , db .password )
276
+
277
+ # Jira model init self.key = None, keep a copy & restore
278
+ self .jira_key = self .key
260
279
super (JiraIssueModel , self ).__init__ (options , session )
280
+ self .key = self .jira_key
281
+ if jwt :
282
+ self ._session = self .__class__ .jira ._session
261
283
262
284
263
285
class Issue (models .base .Model , JiraIssueModel ):
@@ -274,7 +296,7 @@ class Issue(models.base.Model, JiraIssueModel):
274
296
275
297
def __init__ (self , * args , ** kwargs ):
276
298
super (Issue , self ).__init__ (* args , ** kwargs )
277
- self .find (args [ 0 ] )
299
+ self .find (self . jira_key )
278
300
279
301
def __getattr__ (self , name ):
280
302
if name == 'links' :
0 commit comments