-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
first go at an interface for auth plugins #120
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var strings = require('../../resources/'); | ||
var format = require('stringformat'); | ||
|
||
var builtin = { | ||
basic: { | ||
validate: function(authConfig){ | ||
var isValid = authConfig.username && authConfig.password; | ||
return { | ||
isValid: isValid, | ||
message: isValid ? '' : strings.errors.registry.CONFIGURATION_PUBLISH_BASIC_AUTH_CREDENTIALS_MISSING | ||
}; | ||
}, | ||
middleware: function(authConfig){ | ||
var express = require('express'); | ||
return express.basicAuth(authConfig.username, authConfig.password); | ||
} | ||
} | ||
}; | ||
|
||
var scheme; | ||
|
||
module.exports.validate = function(authConfig){ | ||
if(builtin[authConfig.type]){ | ||
scheme = builtin[authConfig.type]; | ||
} | ||
else { | ||
var cwd = process.cwd(); | ||
module.paths.push(cwd, path.join(cwd, 'node_modules')); | ||
|
||
var moduleName = 'oc-auth-' + authConfig.type; | ||
|
||
try { | ||
scheme = require(moduleName); | ||
} catch(err){ | ||
return { | ||
isValid: false, | ||
message: format(strings.errors.registry.CONFIGURATION_PUBLISH_AUTH_MODULE_NOT_FOUND, moduleName) | ||
}; | ||
} | ||
} | ||
|
||
return scheme.validate(authConfig); | ||
}; | ||
|
||
module.exports.middleware = function(authConfig){ | ||
return scheme.middleware(authConfig); | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for? Can't find any documentation about
module.paths
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's equivalent to
require.paths.push()
. It basically adds the parent node_modules folder to the list of paths searched by require. So that you can require a module in the upper node_modules folder.I nicked it from here: https://github.com/mochajs/mocha/blob/master/lib/mocha.js#L28
It's probably not the best way to do it. But I wasn't sure how to proceed in a world where npm3 might or might not flatten the modules folder.
Modifying the paths at runtime is bad, but I figured it's better than using
../../
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Ok, got it.
I think I'm more for a hapi-style initialisation in the way we did the plugin, so that you do the require on the initialisation and you solve this problem for free, but I'm ok with this too and we still can revisit later in case we have troubles with npm3.