mirror of
https://github.com/robertstettner/drone-npm-auth.git
synced 2026-06-04 18:23:58 +08:00
Adds token as a method of authentication
This commit is contained in:
@@ -7,15 +7,18 @@ Drone plugin for authenticating into NPM to install private dependencies.
|
||||
|
||||
The following parameters are used to configure the plugin:
|
||||
|
||||
- `username`: The NPM username. Required.
|
||||
- `password`: The NPM password. Required.
|
||||
- `email`: The NPM email. Required.
|
||||
- `token`: The NPM token. Required (when not using credentials).
|
||||
- `username`: The NPM username. Required (when using credentials).
|
||||
- `password`: The NPM password. Required (when using credentials).
|
||||
- `email`: The NPM email. Required (when using credentials).
|
||||
- `registry`: The NPM registry. Defaults to the default NPM registry.
|
||||
- `scope`: Scope of the NPM authentication. Optional.
|
||||
- `path`: Output path of the generated `.npmrc` file. Defaults to `./`.
|
||||
|
||||
### Drone configuration example
|
||||
|
||||
#### Using credentials
|
||||
|
||||
```yaml
|
||||
pipeline:
|
||||
npm_auth:
|
||||
@@ -33,6 +36,22 @@ pipeline:
|
||||
event: [push, pull_request]
|
||||
```
|
||||
|
||||
#### Using token
|
||||
|
||||
```yaml
|
||||
pipeline:
|
||||
npm_auth:
|
||||
image: robertstettner/drone-npm-auth
|
||||
token: a12445e4424c121323a
|
||||
|
||||
build:
|
||||
image: node:6
|
||||
commands:
|
||||
- npm install
|
||||
- npm test
|
||||
when:
|
||||
event: [push, pull_request]
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
|
||||
+26
-21
@@ -7,33 +7,38 @@ email="${NPM_EMAIL:-$PLUGIN_EMAIL}"
|
||||
registry="${NPM_REGISTRY:-$PLUGIN_REGISTRY}"
|
||||
scope="${NPM_SCOPE:-$PLUGIN_SCOPE}"
|
||||
path="${PLUGIN_PATH:-./}"
|
||||
|
||||
echo "-- Generating authentication from NPM..."
|
||||
token="${NPM_TOKEN:-$PLUGIN_TOKEN}"
|
||||
|
||||
set -e
|
||||
|
||||
if [ -z "$username" ]; then
|
||||
echo "-- Username is not set!"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$password" ]; then
|
||||
echo "-- Password is not set!"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$email" ]; then
|
||||
echo "-- Email is not set!"
|
||||
exit 1
|
||||
fi
|
||||
echo "-- Setting up authentication from NPM..."
|
||||
|
||||
if [ -z "$registry" ]; then
|
||||
registry="registry.npmjs.org"
|
||||
fi
|
||||
if [ -z "$scope" ]; then
|
||||
scope_option=""
|
||||
else
|
||||
scope_option="--scope=$scope"
|
||||
fi
|
||||
if [ -z "$token" ]; then
|
||||
if [ -z "$username" ]; then
|
||||
echo "-- Username is not set!"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$password" ]; then
|
||||
echo "-- Password is not set!"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$email" ]; then
|
||||
echo "-- Email is not set!"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$scope" ]; then
|
||||
scope_option=""
|
||||
else
|
||||
scope_option="--scope=$scope"
|
||||
fi
|
||||
|
||||
expect-npm-auth "npm login --registry $registry $scope_option" $username $password $email >/dev/null 2>&1
|
||||
expect-npm-auth "npm login --registry $registry $scope_option" $username $password $email >/dev/null 2>&1
|
||||
else
|
||||
echo "//$registry/:_authToken=$token" > ~/.npmrc
|
||||
fi
|
||||
|
||||
endtime=$(date +%s.%N)
|
||||
echo "duration: $(echo "$endtime $starttime" | awk '{printf "%f", $1 - $2}')s"
|
||||
@@ -43,5 +48,5 @@ if [ ! -e ~/.npmrc ]; then
|
||||
exit 1
|
||||
else
|
||||
echo $(cat ~/.npmrc) | sed 's/[[:blank:]]\+/\n/g' > $path.npmrc
|
||||
echo "-- NPM authentication generation done!"
|
||||
echo "-- NPM authentication done!"
|
||||
fi
|
||||
Reference in New Issue
Block a user