initial commit

This commit is contained in:
Robert Stettner
2017-07-27 10:25:23 +01:00
commit 719fc279b6
7 changed files with 155 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
.idea
+14
View File
@@ -0,0 +1,14 @@
---
sudo: required
services:
- docker
language: generic
script:
- if [ "$TRAVIS_BRANCH" == "master" ]; then
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
docker build . -t robertstettner/drone-npm-auth;
docker push robertstettner/drone-npm-auth;
fi
+10
View File
@@ -0,0 +1,10 @@
FROM node:6.9.1-slim
# Install packages
RUN apt-get update && apt-get install -yq \
git \
expect-dev
ADD bin/ /bin
CMD npm-auth
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright 2017 (c) Robert Stettner <robert.stettner@gmail.com> (https://github.com/robertstettner)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+39
View File
@@ -0,0 +1,39 @@
# drone-npm-auth
[![Build Status](https://travis-ci.org/robertstettner/drone-npm-auth.svg?branch=master)](https://travis-ci.org/robertstettner/drone-npm-auth)
Drone plugin for authenticating into NPM to install private dependencies.
## Configuration
The following parameters are used to configure the plugin:
- `username`: The NPM username. Required.
- `password`: The NPM password. Required.
- `email`: The NPM email. Required.
- `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
```yaml
pipeline:
npm_auth:
image: robertstettner/drone-npm-auth
username: joebloggs
password: mypass
email: jb@me.com
build:
image: node:6
commands:
- npm install
- npm test
when:
event: [push, pull_request]
```
## License
MIT
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/expect
set timeout 20
set cmd [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set email [lindex $argv 3]
eval spawn $cmd
expect "Username: "
send "$username\r";
expect "Password: "
send "$password\r";
expect "Email: (this IS public) "
send "$email\r";
expect eof
puts $expect_out(buffer)
Executable
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
starttime=$(date +%s.%N)
username="${NPM_USERNAME:-$PLUGIN_USERNAME}"
password="${NPM_PASSWORD:-$PLUGIN_PASSWORD}"
email="${NPM_EMAIL:-$PLUGIN_EMAIL}"
registry="${NPM_REGISTRY:-$PLUGIN_REGISTRY}"
scope="${NPM_SCOPE:-$PLUGIN_SCOPE}"
path="${PLUGIN_PATH:-./}"
echo "-- Generating authentication from NPM..."
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
if [ -z "$registry" ]; then
registry="registry.npmjs.org"
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
endtime=$(date +%s.%N)
echo "duration: $(echo "$endtime $starttime" | awk '{printf "%f", $1 - $2}')s"
if [ ! -e ~/.npmrc ]; then
echo "-- Error logging into NPM"
exit 1
else
echo $(cat ~/.npmrc) | sed 's/[[:blank:]]\+/\n/g' > $path.npmrc
echo "-- NPM authentication generation done!"
fi