This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
148 additions
and
83 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
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,60 @@ | ||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
var KongaApiService = require('../services/KongaApiService') | ||
var ConsumerService = require('../services/ConsumerService') | ||
|
||
|
||
module.exports = function hook(sails) { | ||
return { | ||
|
||
process: function process(next) { | ||
|
||
|
||
if(!sails.config.expose_api) return next() | ||
|
||
var konga_api = { | ||
"name" : "konga", | ||
"request_path" : "/konga", | ||
"strip_request_path" : true, | ||
"preserve_host" : true, | ||
"upstream_url" : sails.config.konga_url + '/api', | ||
"plugins" : [{ | ||
"name" : "key-auth", | ||
"config.key_names" : ["apiKey"] | ||
}] | ||
} | ||
|
||
var konga_api_consumer = { | ||
"username" : "konga", | ||
"custom_id" : "konga", | ||
"acls" : ["konga"], | ||
"authorizations" : [,{ | ||
"name" : "key-auth" | ||
}] | ||
} | ||
|
||
KongaApiService.apis.register(konga_api,function(err,api) { | ||
KongaApiService.consumers.create(konga_api_consumer,function(err,consumer){ | ||
ConsumerService.sync(function(err,done){ | ||
return next() | ||
}) | ||
}) | ||
}) | ||
}, | ||
|
||
/** | ||
* Method that runs automatically when the hook initializes itself. | ||
* | ||
* @param {Function} next Callback function to call after all is done | ||
*/ | ||
initialize: function initialize(next) { | ||
var self = this; | ||
|
||
// Wait for sails orm hook to be loaded | ||
sails.after('hook:orm:loaded', function onAfter() { | ||
self.process(next); | ||
}); | ||
} | ||
}; | ||
}; |
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,25 @@ | ||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
|
||
/** | ||
* Policy to set necessary update data to body. Note that this policy will also remove some body items. | ||
* | ||
* @param {Request} request Request object | ||
* @param {Response} response Response object | ||
* @param {Function} next Callback function | ||
*/ | ||
module.exports = function exposedApi(request, response, next) { | ||
sails.log.verbose(__filename + ':' + __line + ' [Policy.exposedApi() called]'); | ||
|
||
|
||
if(!sails.config.expose_api) { | ||
var error = new Error(); | ||
error.message = 'Forbidden' | ||
error.status = 403; | ||
return next(error) | ||
} | ||
|
||
return next() | ||
|
||
}; |
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
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