From f7fd2d679fa3f72cd73c1278d84377d19ee16034 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 12 Aug 2016 09:31:39 +0100 Subject: [PATCH] Use the RealmID in the Service rather than all of them --- README.md | 24 +++++++++++++-- .../matrix-org/go-neb/realms/jira/jira.go | 1 - .../matrix-org/go-neb/services/jira/jira.go | 30 ++++++++++++------- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 446bc46..23d3db8 100644 --- a/README.md +++ b/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. diff --git a/src/github.com/matrix-org/go-neb/realms/jira/jira.go b/src/github.com/matrix-org/go-neb/realms/jira/jira.go index c28f9cf..a48bdd5 100644 --- a/src/github.com/matrix-org/go-neb/realms/jira/jira.go +++ b/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( diff --git a/src/github.com/matrix-org/go-neb/services/jira/jira.go b/src/github.com/matrix-org/go-neb/services/jira/jira.go index 3900fc3..bdc4dc1 100644 --- a/src/github.com/matrix-org/go-neb/services/jira/jira.go +++ b/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), ), ) }