-
Notifications
You must be signed in to change notification settings - Fork 559
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from eduardoboucas/dev
Add v3 endpoints (and GitLab support)
- Loading branch information
Showing
42 changed files
with
11,877 additions
and
2,364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
.idea/ | ||
*.iml | ||
|
||
config.json | ||
config.*.json | ||
!config.test.json | ||
!config.example.json | ||
coverage/ | ||
node_modules/ | ||
staticman_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ cache: | |
notifications: | ||
email: false | ||
node_js: | ||
- '6' | ||
- '8.11.3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM node:6.7.0 | ||
FROM node:8.11.3 | ||
|
||
# Create app directory | ||
RUN mkdir -p /app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict' | ||
|
||
const gitFactory = require('../lib/GitServiceFactory') | ||
const oauth = require('../lib/OAuth') | ||
const RSA = require('../lib/RSA') | ||
const Staticman = require('../lib/Staticman') | ||
|
||
module.exports = (req, res) => { | ||
const staticman = new Staticman(req.params) | ||
staticman.setConfigPath() | ||
|
||
let requestAccessToken | ||
|
||
switch (req.params.service) { | ||
case 'gitlab': | ||
requestAccessToken = siteConfig => | ||
oauth.requestGitLabAccessToken( | ||
req.query.code, | ||
siteConfig.get('gitlabAuth.clientId'), | ||
siteConfig.get('gitlabAuth.clientSecret'), | ||
siteConfig.get('gitlabAuth.redirectUri') | ||
) | ||
break | ||
default: | ||
requestAccessToken = siteConfig => | ||
oauth.requestGitHubAccessToken( | ||
req.query.code, | ||
siteConfig.get('githubAuth.clientId'), | ||
siteConfig.get('githubAuth.clientSecret'), | ||
siteConfig.get('githubAuth.redirectUri') | ||
) | ||
} | ||
|
||
return staticman.getSiteConfig() | ||
.then(requestAccessToken) | ||
.then((accessToken) => { | ||
const git = gitFactory.create(req.params.service, { | ||
oauthToken: accessToken, | ||
version: req.params.version | ||
}) | ||
|
||
// TODO: Simplify this when v2 support is dropped. | ||
const getUser = req.params.version === '2' && req.params.service === 'github' | ||
? git.api.users.getAuthenticated({}).then(({data}) => data) | ||
: git.getCurrentUser() | ||
|
||
return getUser | ||
.then((user) => { | ||
res.send({ | ||
accessToken: RSA.encrypt(accessToken), | ||
user | ||
}) | ||
}) | ||
}) | ||
.catch((err) => { | ||
console.log('ERR:', err) | ||
|
||
const statusCode = err.statusCode || 401 | ||
|
||
res.status(statusCode).send({ | ||
statusCode, | ||
message: err.message | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.