-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from lilsweetcaligula/implement-github-auth
Implement GitHub auth
- Loading branch information
Showing
51 changed files
with
2,723 additions
and
501 deletions.
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
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
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] | ||
|
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,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" | ||
|
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,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 | ||
|
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,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 | ||
|
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 @@ | ||
#!/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 | ||
|
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,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 | ||
|
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,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 }) | ||
}) | ||
|
Oops, something went wrong.