Skip to content

Commit

Permalink
Merge pull request #12 from lilsweetcaligula/implement-github-auth
Browse files Browse the repository at this point in the history
Implement GitHub auth
  • Loading branch information
rjrodger authored Aug 30, 2021
2 parents c61b8d8 + 77f7cdb commit 2f6593d
Show file tree
Hide file tree
Showing 51 changed files with 2,723 additions and 501 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@ local/setup.sh
*.zip


# Files useful for development
# Files generated by scripts, or tools, useful for development
devassets
4 changes: 2 additions & 2 deletions deploy/aws/sns/create-topics.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
aws sns create-topic --name nodezoo_process_payment_role_payment
aws sns create-topic --name nodezoo_login_with_github_role_web_scope_public
aws sns create-topic --name nodezoo_login_user_role_web_scope_public
aws sns create-topic --name nodezoo_role_web_scope_public_search_pkgs
aws sns create-topic --name nodezoo_role_web_scope_public_show_pkg
Expand All @@ -11,13 +12,12 @@ aws sns create-topic --name nodezoo_bookmark_pkg_role_web_scope_account
aws sns create-topic --name nodezoo_list_bookmarks_role_web_scope_account
aws sns create-topic --name nodezoo_is_premium_role_web_scope_account
aws sns create-topic --name nodezoo_checkout_for_premium_role_web_scope_account_submit_checkout
aws sns create-topic --name nodezoo_need_part_role_info
aws sns create-topic --name nodezoo_collect_part_role_info
aws sns create-topic --name nodezoo_get_info_role_info
aws sns create-topic --name nodezoo_role_info_test_true
aws sns create-topic --name nodezoo_need_part_role_info
aws sns create-topic --name nodezoo_get_package_role_source_source_npm
aws sns create-topic --name nodezoo_pull_package_role_source_source_npm
aws sns create-topic --name nodezoo_need_part_role_info
aws sns create-topic --name nodezoo_get_package_role_source_source_github
aws sns create-topic --name nodezoo_pull_package_role_source_source_github
aws sns create-topic --name nodezoo_get_rate_limit_role_source_source_github
Expand Down
16 changes: 16 additions & 0 deletions env/local/.env.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER='[email protected]'
SMTP_PASS='abcdefghij'

GITHUB_CLIENT_ID='fake_gh_client_id'
GITHUB_CLIENT_SECRET='fake_gh_client_secret'

NPM_REGISTRY_URL='http://localhost:9090'
NPM_API_URL='http://localhost:9090'
GITHUB_API_URL='http://localhost:9999'
GITHUB_URL='http://localhost:9999'

USER_ACCESS_TOKEN='mock_api_github_user_access_token'
[email protected]

16 changes: 16 additions & 0 deletions env/local/scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Bash 'strict' mode
#
set -euo pipefail
IFS=$'\n\t'


export LOCAL_DEVASSETS_DIRPATH='./env/local/devassets'

export FRONTEND_PID_DIRPATH="${LOCAL_DEVASSETS_DIRPATH}"
export FRONTEND_PID_FILEPATH="${FRONTEND_PID_DIRPATH}/frontend.pid"

export FRONTEND_LOG_DIRPATH="${LOCAL_DEVASSETS_DIRPATH}"
export FRONTEND_LOG_FILEPATH="${FRONTEND_LOG_DIRPATH}/frontend.log"

60 changes: 60 additions & 0 deletions env/local/scripts/frontend-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# Bash 'strict' mode
#
set -euo pipefail
IFS=$'\n\t'


source ./env/sim/scripts/common.sh


test -d "${FRONTEND_PID_DIRPATH}" || mkdir "${FRONTEND_PID_DIRPATH}"


tmppidpath=$(mktemp)


# For more information on acquisition a pid of a background-running process,
# please see:
#
# https://stackoverflow.com/questions/20254155/how-to-run-nohup-and-write-its-pid-file-in-a-single-bash-statement#answer-54516616
#

# Clearing the pid so that later we know - if the pid-file is empty,
# then the frontend server failed to start.
#

nohup npm run local-serve --prefix ./srv/web/www2 > \
"${FRONTEND_LOG_FILEPATH}" 2>&1 &

echo $! > "${tmppidpath}"

sleep 5


if cat "${tmppidpath}" | pgrep -P $! > "${tmppidpath}";
then
# For more information on why we are incrementing the pid,
# please see:
#
# https://stackoverflow.com/questions/20254155/how-to-run-nohup-and-write-its-pid-file-in-a-single-bash-statement#comment-63204696
#
# Please note that this workaround may turn out to be suboptimal.
# Better alternatives, if there are any available ones, would be welcome.
#
pid=$(head -n1 "${tmppidpath}")
frontend_pid=$(($pid+1))

echo "${frontend_pid}" > "${FRONTEND_PID_FILEPATH}"
cat "${FRONTEND_LOG_FILEPATH}"
else
# If the pid-file is empty, then the frontend server failed to start.
#

echo 'ERROR: the frontend server failed to start.'
cat "${FRONTEND_LOG_FILEPATH}" > /dev/stderr

exit 1
fi

12 changes: 12 additions & 0 deletions env/local/scripts/frontend-stop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Bash 'strict' mode
#
set -euo pipefail
IFS=$'\n\t'


source ./env/sim/scripts/common.sh

cat "${FRONTEND_PID_FILEPATH}" | xargs kill -9

50 changes: 50 additions & 0 deletions env/local/scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash


# Bash 'strict' mode
#
set -euo pipefail
IFS=$'\n\t'


# Setting up frontend
#
./env/local/scripts/frontend-start.sh


test -d ./env/local/devassets || mkdir ./env/local/devassets


# Setting up the mock npm API
#
if ! test -d ./env/local/devassets/mock-api-npm; then
git clone [email protected]:lilsweetcaligula/mock-api-npm.git \
./env/local/devassets/mock-api-npm

# Link the mock server to the host environment. This is required
# to be able to pass env vars to the mock server.
#
cp ./env/local/.env ./env/local/devassets/mock-api-npm/.env

npm install --prefix ./env/local/devassets/mock-api-npm
fi

docker-compose -f ./env/local/devassets/mock-api-npm/docker-compose.yaml up -d


# Setting up the mock GitHub API
#
if ! test -d ./env/local/devassets/mock-api-github; then
git clone [email protected]:lilsweetcaligula/mock-api-github.git \
./env/local/devassets/mock-api-github

# Link the mock server to the host environment. This is required
# to be able to pass env vars to the mock server.
#
cp ./env/local/.env ./env/local/devassets/mock-api-github/.env

npm install --prefix ./env/local/devassets/mock-api-github
fi

docker-compose -f ./env/local/devassets/mock-api-github/docker-compose.yaml up -d

24 changes: 24 additions & 0 deletions env/local/scripts/teardown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash


# Bash 'strict' mode
#
set -euo pipefail
IFS=$'\n\t'


# There is currently no need to tear down the frontend in the local env.
#


# Tearing down the mock npm API
#
docker-compose -f ./env/local/devassets/mock-api-npm/docker-compose.yaml down
rm ./env/local/devassets/mock-api-npm -rf


# Tearing down the mock GitHub API
#
docker-compose -f ./env/local/devassets/mock-api-github/docker-compose.yaml down
rm ./env/local/devassets/mock-api-github -rf

135 changes: 135 additions & 0 deletions env/local/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
require('dotenv').config({ path: './env/local/.env' })


const Seneca = require('seneca')
const Model = require('../../model/model.json')
const TasksCollection = require('./tasks')


const Nock = require('nock')
//
// We only want our locally-mounted system to be able
// to make local connections, and not external ones.
//
Nock.disableNetConnect()
Nock.enableNetConnect('localhost')


const seneca = Seneca({ log: 'flat' })
seneca.context.model = Model

seneca
.test('print')
.error(console.log)
.use('promisify')
.use('entity')
.use('mem-store')
.use('search-mem', {
search: {
fields: ['name'],
storeFields: ['name', 'version', 'giturl', 'desc', 'readme'],
searchOptions: {
fuzzy: true
}
}
})
.use('repl')
.use('reload')
.use('user')
.use('member')
.use('group')


const host = process.env.SMTP_HOST

if (null == host) {
throw new Error('missing SMTP_HOST env var')
}


const port = process.env.SMTP_PORT

if (null == port) {
throw new Error('missing SMTP_PORT env var')
}


const user = process.env.SMTP_USER

if (null == user) {
throw new Error('missing SMTP_USER env var')
}


const pass = process.env.SMTP_PASS

if (null == pass) {
throw new Error('missing SMTP_PASS env var')
}


seneca.use('simple-mail', {
transport: {
pool: true,
secure: false, // <-- You might want to change that.
host,
port,
auth: {
user,
pass
}
}
})


const npm_registry_url = process.env.NPM_REGISTRY_URL

if (null == npm_registry_url) {
throw new Error('missing NPM_REGISTRY_URL env var')
}


const github_api_url = process.env.GITHUB_API_URL

if (null == github_api_url) {
throw new Error('missing process env var')
}


const options = {
npm_registry_url,
github_api_url,

ingester: {
sleep_ms_between_iterations: 5e3,
sleep_ms_between_fetches: 1e3
},

github_srv: {
wait_ms_on_npm: 2e3
}
}

for(const [name, srv] of Object.entries(Model.main.srv)) {
seneca.use('../../srv/'+name+'/'+name+'-srv.js', options)
}


seneca.ready(() => {
// NOTE: Creating the Premium Users group.
//
seneca.act('make:group,role:group', {
owner_id: null,
group: { name: 'Premium Users', mark: 'pu', code: 'PremiumUsers' },
unique: true
}, err => {
if (err) {
throw err
}
})

// NOTE: Scheduling the tasks.
//
TasksCollection.run({ seneca })
})

Loading

0 comments on commit 2f6593d

Please sign in to comment.