generated from fis-g4/sample-microservice
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #38 from fis-g4/task/037
Task/037
- Loading branch information
Showing
18 changed files
with
591 additions
and
352 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,10 +18,9 @@ jobs: | |
|
||
- name: Decrypt Google credentials.json | ||
env: | ||
GOOGLE_API_PW: ${{ secrets.GCP_CREDENTIALS_PK }} | ||
GCP_CREDENTIALS: ${{ secrets.ENCODED_GCP_CREDENTIALS }} | ||
run: | | ||
gpg --quiet --batch --yes --decrypt --passphrase="$GOOGLE_API_PW" \ | ||
--output $GITHUB_WORKSPACE/GoogleCloudKey.json GoogleCloudKey.json.gpg | ||
echo "$GCP_CREDENTIALS" | base64 --decode > GoogleCloudKey.json | ||
- name: Make envfile | ||
uses: SpicyPizza/[email protected] | ||
|
@@ -50,12 +49,16 @@ jobs: | |
envkey_GCF_VERIFY_TOKEN_ENDPOINT: ${{ vars.GCF_VERIFY_TOKEN_ENDPOINT }} | ||
envkey_GCF_GET_PAYLOAD_FROM_TOKEN_ENDPOINT: ${{ vars.GCF_GET_PAYLOAD_FROM_TOKEN_ENDPOINT }} | ||
envkey_SENDINBLUE_API_KEY: ${{ secrets.CI_SENDINBLUE_API_KEY }} | ||
envkey_COURSES_SERVICE_USERNAME: ${{ secrets.CI_COURSES_SERVICE_USERNAME }} | ||
envkey_COURSES_SERVICE_PASSWORD: ${{ secrets.CI_COURSES_SERVICE_PASSWORD }} | ||
envkey_PAYMENT_SERVICE_USERNAME: ${{ secrets.CI_PAYMENT_SERVICE_USERNAME }} | ||
envkey_PAYMENT_SERVICE_PASSWORD: ${{ secrets.CI_PAYMENT_SERVICE_PASSWORD }} | ||
directory: ./server | ||
file_name: .env | ||
fail_on_empty: false | ||
sort_keys: false | ||
|
||
- name: Start MongoDB | ||
- name: Start MongoDBs | ||
uses: supercharge/[email protected] | ||
with: | ||
mongodb-version: ${{ vars.CI_MONGODB_VERSION }} | ||
|
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 |
---|---|---|
@@ -1,80 +1,124 @@ | ||
import { PlanType, User, UserRole } from './models/user'; | ||
import bcrypt from 'bcrypt'; | ||
import { PlanType, User, UserRole } from './models/user' | ||
import bcrypt from 'bcrypt' | ||
|
||
const SALT_ROUNDS: number = parseInt(process.env.SALT_ROUNDS ?? "10"); | ||
const POPULATE_DB_ON_EACH_RELOAD: boolean = process.env.RESET_DB_ON_EACH_RELOAD === "true"; | ||
const salt = bcrypt.genSaltSync(SALT_ROUNDS); | ||
const SALT_ROUNDS: number = parseInt(process.env.SALT_ROUNDS ?? '10') | ||
const POPULATE_DB_ON_EACH_RELOAD: boolean = | ||
process.env.RESET_DB_ON_EACH_RELOAD === 'true' | ||
const salt = bcrypt.genSaltSync(SALT_ROUNDS) | ||
|
||
const bucketUrl = process.env.GCS_BUCKET_URL ?? ''; | ||
const bucketName = process.env.GCS_BUCKET_NAME ?? ''; | ||
const bucketUrl = process.env.GCS_BUCKET_URL ?? '' | ||
const bucketName = process.env.GCS_BUCKET_NAME ?? '' | ||
|
||
function populateUsers() { | ||
User.build({ | ||
firstName: 'Maria', | ||
firstName: 'Maria', | ||
lastName: 'Doe', | ||
username: 'mariaDoe', | ||
password: bcrypt.hashSync('maria1234', salt), | ||
email: '[email protected]', | ||
profilePicture: bucketUrl + "/" + bucketName + '/default-user.jpg', | ||
profilePicture: bucketUrl + '/' + bucketName + '/default-user.jpg', | ||
coinsAmount: 0, | ||
plan: PlanType.FREE, | ||
plan: PlanType.BASIC, | ||
role: UserRole.USER, | ||
}).save(); | ||
}).save() | ||
|
||
User.build({ | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
username: 'johnDoe', | ||
password: bcrypt.hashSync('john1234', salt), | ||
email: '[email protected]', | ||
profilePicture: bucketUrl + "/" + bucketName + '/default-user.jpg', | ||
profilePicture: bucketUrl + '/' + bucketName + '/default-user.jpg', | ||
coinsAmount: 100, | ||
plan: PlanType.PREMIUM, | ||
plan: PlanType.ADVANCED, | ||
role: UserRole.USER, | ||
}).save(); | ||
}).save() | ||
} | ||
|
||
function populateAdmins() { | ||
User.build({ | ||
firstName: 'Admin', | ||
lastName: 'User', | ||
username: process.env.ADMIN_USERNAME ?? 'admin', | ||
password: bcrypt.hashSync(process.env.ADMIN_PASSWORD ?? 'password', salt), | ||
password: bcrypt.hashSync( | ||
process.env.ADMIN_PASSWORD ?? 'password', | ||
salt | ||
), | ||
email: process.env.ADMIN_EMAIL ?? '[email protected]', | ||
profilePicture: bucketUrl + "/" + bucketName + '/default-user.jpg', | ||
profilePicture: bucketUrl + '/' + bucketName + '/default-user.jpg', | ||
coinsAmount: 99999, | ||
plan: PlanType.PRO, | ||
role: UserRole.ADMIN, | ||
}).save(); | ||
}).save() | ||
|
||
User.build({ | ||
firstName: 'Courses', | ||
lastName: 'Admin User', | ||
username: process.env.COURSES_SERVICE_USERNAME ?? '', | ||
password: bcrypt.hashSync(process.env.COURSES_SERVICE_PASSWORD ?? '', salt), | ||
password: bcrypt.hashSync( | ||
process.env.COURSES_SERVICE_PASSWORD ?? '', | ||
salt | ||
), | ||
email: '[email protected]', | ||
profilePicture: bucketUrl + "/" + bucketName + '/default-user.jpg', | ||
profilePicture: bucketUrl + '/' + bucketName + '/default-user.jpg', | ||
coinsAmount: 99999, | ||
plan: PlanType.PRO, | ||
role: UserRole.ADMIN, | ||
}).save() | ||
|
||
User.build({ | ||
firstName: 'Payments', | ||
lastName: 'Admin User', | ||
username: process.env.PAYMENT_SERVICE_USERNAME ?? '', | ||
password: bcrypt.hashSync( | ||
process.env.PAYMENT_SERVICE_PASSWORD ?? '', | ||
salt | ||
), | ||
email: '[email protected]', | ||
profilePicture: bucketUrl + '/' + bucketName + '/default-user.jpg', | ||
coinsAmount: 99999, | ||
plan: PlanType.PRO, | ||
role: UserRole.ADMIN, | ||
}).save(); | ||
}).save() | ||
} | ||
|
||
async function populateDB() { | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
|
||
console.log('Populating DB...'); | ||
|
||
User.collection.countDocuments().then((count) => { | ||
if (count === 0 || POPULATE_DB_ON_EACH_RELOAD) { | ||
User.collection.drop().then(()=>{ | ||
console.log('Populating DB with example users...') | ||
|
||
User.collection.drop().then(() => { | ||
populateUsers() | ||
}); | ||
console.log('Populated!') | ||
}) | ||
} | ||
|
||
User.find({ role: UserRole.ADMIN }) | ||
.countDocuments() | ||
.then((count) => { | ||
if (count === 0 || POPULATE_DB_ON_EACH_RELOAD) { | ||
console.log('Populating DB with admin users...') | ||
populateAdmins() | ||
console.log('Populated!') | ||
} | ||
}) | ||
}) | ||
} else { | ||
User.find({ role: UserRole.ADMIN }).countDocuments().then((count) => { | ||
if(count === 0) { | ||
console.log('Populating DB with admin users...') | ||
populateAdmins() | ||
console.log('Populated!') | ||
}else{ | ||
User.deleteMany({ role: UserRole.ADMIN }).then(() => { | ||
console.log('Populating DB with admin users...') | ||
populateAdmins() | ||
console.log('Populated!') | ||
}) | ||
} | ||
}) | ||
|
||
console.log('Populated!'); | ||
} | ||
|
||
} | ||
|
||
export default populateDB; | ||
export default populateDB |
Oops, something went wrong.