Browse Source

Use the RealmID in the Service rather than all of them

pull/22/head
Kegan Dougal 8 years ago
parent
commit
f7fd2d679f
  1. 24
      README.md
  2. 1
      src/github.com/matrix-org/go-neb/realms/jira/jira.go
  3. 30
      src/github.com/matrix-org/go-neb/services/jira/jira.go

24
README.md

@ -202,7 +202,7 @@ JIRA installation. Once that is complete, users can OAuth on the target JIRA ins
```
curl -X POST localhost:4050/admin/requestAuthSession --data-binary '{
"RealmID": "jirarealm",
"UserID": "@your_user_id:localhost",
"UserID": "@example:localhost",
"Config": {
}
}'
@ -218,7 +218,27 @@ Follow this link and grant access for NEB to act on your behalf.
### Create a JIRA bot
TODO
```
curl -X POST localhost:4050/admin/configureService --data-binary '{
"Type": "jira",
"Id": "jid",
"Config": {
"BotUserID": "@goneb:localhost",
"ClientUserID": "@example:localhost",
"Rooms": {
"!EmwxeXCVubhskuWvaw:localhost": {
"RealmID": "jirarealm",
"Projects": {
"BOTS": {
"Expand": true,
"Track": true
}
}
}
}
}
}'
```
# Developing on go-neb.

1
src/github.com/matrix-org/go-neb/realms/jira/jira.go

@ -264,7 +264,6 @@ func (r *JIRARealm) JIRAClient(userID string, allowUnauth bool) (*jira.Client, e
}
return nil, errors.New("No authenticated session found for " + userID)
}
// make an authenticated client
auth := r.oauth1Config(r.JIRAEndpoint)
httpClient := auth.Client(

30
src/github.com/matrix-org/go-neb/services/jira/jira.go

@ -129,21 +129,29 @@ func (s *jiraService) expandIssue(roomID, userID, issueKey string) interface{} {
return nil
}
// Use the person who *provisioned* the service to check for project keys
// rather than the person who mentioned the issue key, as it is unlikely
// some random who mentioned the issue will have the intended auth.
r, err := s.projectToRealm(s.ClientUserID, projectKey)
r, err := database.GetServiceDB().LoadAuthRealm(s.Rooms[roomID].RealmID)
if err != nil {
logger.WithError(err).Print("Failed to map project key to realm")
logger.WithFields(log.Fields{
"realm_id": s.Rooms[roomID].RealmID,
log.ErrorKey: err,
}).Print("Failed to load realm")
return nil
}
if r == nil {
logger.Print("No known project exists with that project key.")
return nil
jrealm, ok := r.(*realms.JIRARealm)
if !ok {
logger.WithField("realm_id", s.Rooms[roomID].RealmID).Print(
"Realm cannot be typecast to JIRARealm",
)
}
logger.WithFields(log.Fields{
"room_id": roomID,
"user_id": s.ClientUserID,
}).Print("Expanding issue")
logger.WithField("room_id", roomID).Print("Expanding issue")
cli, err := r.JIRAClient(s.ClientUserID, false)
// Use the person who *provisioned* the service to check for project keys
// rather than the person who mentioned the issue key, as it is unlikely
// some random who mentioned the issue will have the intended auth.
cli, err := jrealm.JIRAClient(s.ClientUserID, false)
if err != nil {
logger.WithFields(log.Fields{
log.ErrorKey: err,
@ -161,7 +169,7 @@ func (s *jiraService) expandIssue(roomID, userID, issueKey string) interface{} {
"m.notice",
fmt.Sprintf(
"%sbrowse/%s : %s",
r.JIRAEndpoint, issueKey, htmlSummaryForIssue(issue),
jrealm.JIRAEndpoint, issueKey, htmlSummaryForIssue(issue),
),
)
}

Loading…
Cancel
Save