mirror of
https://github.com/actions/setup-node.git
synced 2025-07-27 08:58:24 +02:00
.
This commit is contained in:
parent
beb1329f9f
commit
2b95e76931
7736 changed files with 1874747 additions and 51184 deletions
77
node_modules/@octokit/rest/plugins/authentication/index.js
generated
vendored
77
node_modules/@octokit/rest/plugins/authentication/index.js
generated
vendored
|
@ -1,21 +1,76 @@
|
|||
module.exports = authenticationPlugin
|
||||
module.exports = authenticationPlugin;
|
||||
|
||||
const beforeRequest = require('./before-request')
|
||||
const requestError = require('./request-error')
|
||||
const validate = require('./validate')
|
||||
const { createTokenAuth } = require("@octokit/auth-token");
|
||||
const { Deprecation } = require("deprecation");
|
||||
const once = require("once");
|
||||
|
||||
function authenticationPlugin (octokit, options) {
|
||||
if (!options.auth) {
|
||||
return
|
||||
const beforeRequest = require("./before-request");
|
||||
const requestError = require("./request-error");
|
||||
const validate = require("./validate");
|
||||
const withAuthorizationPrefix = require("./with-authorization-prefix");
|
||||
|
||||
const deprecateAuthBasic = once((log, deprecation) => log.warn(deprecation));
|
||||
const deprecateAuthObject = once((log, deprecation) => log.warn(deprecation));
|
||||
|
||||
function authenticationPlugin(octokit, options) {
|
||||
// If `options.authStrategy` is set then use it and pass in `options.auth`
|
||||
if (options.authStrategy) {
|
||||
const auth = options.authStrategy(options.auth);
|
||||
octokit.hook.wrap("request", auth.hook);
|
||||
octokit.auth = auth;
|
||||
return;
|
||||
}
|
||||
|
||||
validate(options.auth)
|
||||
// If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance
|
||||
// is unauthenticated. The `octokit.auth()` method is a no-op and no request hook is registred.
|
||||
if (!options.auth) {
|
||||
octokit.auth = () =>
|
||||
Promise.resolve({
|
||||
type: "unauthenticated"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const isBasicAuthString =
|
||||
typeof options.auth === "string" &&
|
||||
/^basic/.test(withAuthorizationPrefix(options.auth));
|
||||
|
||||
// If only `options.auth` is set to a string, use the default token authentication strategy.
|
||||
if (typeof options.auth === "string" && !isBasicAuthString) {
|
||||
const auth = createTokenAuth(options.auth);
|
||||
octokit.hook.wrap("request", auth.hook);
|
||||
octokit.auth = auth;
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise log a deprecation message
|
||||
const [deprecationMethod, deprecationMessapge] = isBasicAuthString
|
||||
? [
|
||||
deprecateAuthBasic,
|
||||
'Setting the "new Octokit({ auth })" option to a Basic Auth string is deprecated. Use https://github.com/octokit/auth-basic.js instead. See (https://octokit.github.io/rest.js/#authentication)'
|
||||
]
|
||||
: [
|
||||
deprecateAuthObject,
|
||||
'Setting the "new Octokit({ auth })" option to an object without also setting the "authStrategy" option is deprecated and will be removed in v17. See (https://octokit.github.io/rest.js/#authentication)'
|
||||
];
|
||||
deprecationMethod(
|
||||
octokit.log,
|
||||
new Deprecation("[@octokit/rest] " + deprecationMessapge)
|
||||
);
|
||||
|
||||
octokit.auth = () =>
|
||||
Promise.resolve({
|
||||
type: "deprecated",
|
||||
message: deprecationMessapge
|
||||
});
|
||||
|
||||
validate(options.auth);
|
||||
|
||||
const state = {
|
||||
octokit,
|
||||
auth: options.auth
|
||||
}
|
||||
};
|
||||
|
||||
octokit.hook.before('request', beforeRequest.bind(null, state))
|
||||
octokit.hook.error('request', requestError.bind(null, state))
|
||||
octokit.hook.before("request", beforeRequest.bind(null, state));
|
||||
octokit.hook.error("request", requestError.bind(null, state));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue