From 34af85c04ebec85b2e035ae9fafe09327b892ded Mon Sep 17 00:00:00 2001 From: Artem-Darius Atlas Date: Thu, 29 Jun 2023 16:08:30 +0300 Subject: [PATCH] feat: auth service init --- apps/auth/.ASC_MANIFEST | 13 + apps/auth/.env.example | 6 + apps/auth/.gitignore | 335 ++++++++++++++++++ apps/auth/Dockerfile | 32 ++ apps/auth/LICENSE | 11 + apps/auth/README.md | 32 ++ apps/auth/prisma/.gitignore | 1 + apps/auth/serving/.gitignore | 225 ++++++++++++ apps/auth/serving/database.env.example | 3 + apps/auth/serving/docker-compose.yaml | 36 ++ apps/auth/src/main.ts | 2 +- .../.gitkeep => tokens.example/jwt.key} | 0 apps/auth/tokens.example/jwt.key.pub | 0 apps/user-data/prisma/.gitignore | 1 + apps/user-data/serving/.gitignore | 2 +- 15 files changed, 697 insertions(+), 2 deletions(-) create mode 100644 apps/auth/.ASC_MANIFEST create mode 100644 apps/auth/.env.example create mode 100644 apps/auth/.gitignore create mode 100644 apps/auth/Dockerfile create mode 100644 apps/auth/LICENSE create mode 100644 apps/auth/README.md create mode 100644 apps/auth/prisma/.gitignore create mode 100644 apps/auth/serving/.gitignore create mode 100644 apps/auth/serving/database.env.example create mode 100644 apps/auth/serving/docker-compose.yaml rename apps/auth/{src/assets/.gitkeep => tokens.example/jwt.key} (100%) create mode 100644 apps/auth/tokens.example/jwt.key.pub create mode 100644 apps/user-data/prisma/.gitignore diff --git a/apps/auth/.ASC_MANIFEST b/apps/auth/.ASC_MANIFEST new file mode 100644 index 0000000..0f5345b --- /dev/null +++ b/apps/auth/.ASC_MANIFEST @@ -0,0 +1,13 @@ +$$ +@version: 0.1.0; +@scuuid: fbc45229-30c1-4daf-8f28-063bf27ef7d3; +@type: service; +@platform: nestjs; +@license: BSD-3-Clause; +@owner: artem-darius weber; +@author: ; +@title: user-authentication; +@desc: ; +@rp: kubsu it lab; +@vr: 7093; +$$ diff --git a/apps/auth/.env.example b/apps/auth/.env.example new file mode 100644 index 0000000..fc84cb9 --- /dev/null +++ b/apps/auth/.env.example @@ -0,0 +1,6 @@ +PORT=3005 + +DATABASE_URL=postgresql://postgres:postgres@localhost:5433/user-authentication + +PUBLIC_KEY_PATH=tokens/jwt.key.pub +PRIVATE_KEY_PATH=tokens/jwt.key diff --git a/apps/auth/.gitignore b/apps/auth/.gitignore new file mode 100644 index 0000000..928a9a9 --- /dev/null +++ b/apps/auth/.gitignore @@ -0,0 +1,335 @@ +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# user-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Xcode template +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Gcc Patch +/*.gcno + +### Example user template template +### Example user template + +# IntelliJ project files +.idea +*.iml +out +gen +### Node template +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +#out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +### Windows template +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### macOS template +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### OpenSSL template +# OpenSSL-related files best not committed + +## Certificate Authority +*.ca + +## Certificate +*.crt + +## Certificate Sign Request +*.csr + +## Certificate +*.der + +## Key database file +*.kdb + +## OSCP request data +*.org + +## PKCS #12 +*.p12 + +## PEM-encoded certificate data +*.pem + +## Random number seed +*.rnd + +## SSLeay data +*.ssleay + +## S/MIME message +*.smime + + + + +*.env +*.env.backup + +*.save + +# compiled output +/dist +/node_modules + +# Tests +/coverage +/.nyc_output + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +tokens diff --git a/apps/auth/Dockerfile b/apps/auth/Dockerfile new file mode 100644 index 0000000..f0b43cf --- /dev/null +++ b/apps/auth/Dockerfile @@ -0,0 +1,32 @@ +# syntax=docker/dockerfile:1 +FROM node:18 + +WORKDIR /app + +COPY --chown=node:node . . + +RUN rm -f *.env *.env.* + +RUN apt-get update -y && apt-get install -y dumb-init + +RUN npm install + +ENV NODE_ENV=production + +RUN npm run prefullbuild && npm run prebuild && npm run build + +RUN mkdir temp temp/.prisma temp/@prisma temp/prisma && cp -r ./node_modules/.prisma/* ./temp/.prisma/ && cp -r ./node_modules/@prisma/* ./temp/@prisma/ && cp -r ./node_modules/prisma/* ./temp/prisma/ + +RUN rm -rdf node_modules + +RUN npm install --production + +RUN cp -r ./temp/* ./node_modules/ && rm -rdf temp + +RUN ls | grep -v node_modules | grep -v dist | xargs rm -rfv + +RUN cp -r ./dist/* ./ && rm -rdf dist + +USER node + +CMD ["dumb-init", "node", "./main.js"] diff --git a/apps/auth/LICENSE b/apps/auth/LICENSE new file mode 100644 index 0000000..d62cc9d --- /dev/null +++ b/apps/auth/LICENSE @@ -0,0 +1,11 @@ +Copyright 2023 SC (DJEEFT) © + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/apps/auth/README.md b/apps/auth/README.md new file mode 100644 index 0000000..68f67e3 --- /dev/null +++ b/apps/auth/README.md @@ -0,0 +1,32 @@ +
+ +

IT Lab Platform - Auth Service

+
+ +
+ + + Эта директория содержит исходный код системы аунтификации приложения "IT Lab Application". + +
+ +## Ports +- `8082` - pg Admin +- `3005` - app + +## API +- /user + - /devices + - POST + - parameters: + - uuid: string(UUID) + - select?: + - name?: boolean + - fingerprint?: boolean + - isBlocked?: boolean + - return: + - Array: + - name?: string + - fingerprint?: string + - isBlocked?: boolean + - The select statement needs at least one truthy value. diff --git a/apps/auth/prisma/.gitignore b/apps/auth/prisma/.gitignore new file mode 100644 index 0000000..24a8e4d --- /dev/null +++ b/apps/auth/prisma/.gitignore @@ -0,0 +1 @@ +migrations diff --git a/apps/auth/serving/.gitignore b/apps/auth/serving/.gitignore new file mode 100644 index 0000000..f78e42d --- /dev/null +++ b/apps/auth/serving/.gitignore @@ -0,0 +1,225 @@ +*.env +.idea + +### NotepadPP template +# Notepad++ backups # +*.bak + +### VisualStudioCode template +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# user-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Xcode template +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Gcc Patch +/*.gcno + +### Linux template +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Kate template +# Swap Files # +.*.kate-swp +.swp.* + +### Windows template +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +### macOS template +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### SublimeText template +# Cache files for Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# Workspace files are user-specific +*.sublime-workspace + +# Project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using Sublime Text +# *.sublime-project + +# SFTP configuration file +sftp-config.json +sftp-config-alt*.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings diff --git a/apps/auth/serving/database.env.example b/apps/auth/serving/database.env.example new file mode 100644 index 0000000..4cfdb1b --- /dev/null +++ b/apps/auth/serving/database.env.example @@ -0,0 +1,3 @@ +POSTGRES_DB=user-authentication +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres diff --git a/apps/auth/serving/docker-compose.yaml b/apps/auth/serving/docker-compose.yaml new file mode 100644 index 0000000..1c0a532 --- /dev/null +++ b/apps/auth/serving/docker-compose.yaml @@ -0,0 +1,36 @@ +version: "3.9" + +services: + user-authentication-database: + image: postgres:latest + container_name: user-authentication-database + restart: always + networks: + - user-authentication + volumes: + - user-authentication-database:/var/lib/postgresql + env_file: + - ./database.env + user-authentication-database-admin: + container_name: user-authentication-database-admin + image: bitnami/phppgadmin:latest + restart: always + networks: + - user-authentication + depends_on: + - user-authentication-database + environment: + - DATABASE_HOST=user-authentication-database + ports: + - "8083:8080" + +networks: + user-authentication: + name: user-authentication + driver: bridge + +volumes: + user-authentication-database: + driver: local + user-authentication-tokens: + driver: local diff --git a/apps/auth/src/main.ts b/apps/auth/src/main.ts index a124382..d267063 100644 --- a/apps/auth/src/main.ts +++ b/apps/auth/src/main.ts @@ -12,7 +12,7 @@ async function bootstrap() { const app = await NestFactory.create(AppModule); const globalPrefix = 'api'; app.setGlobalPrefix(globalPrefix); - const port = process.env.PORT || 3000; + const port = process.env.PORT || 3005; await app.listen(port); Logger.log( `🚀 Application is running on: http://localhost:${port}/${globalPrefix}` diff --git a/apps/auth/src/assets/.gitkeep b/apps/auth/tokens.example/jwt.key similarity index 100% rename from apps/auth/src/assets/.gitkeep rename to apps/auth/tokens.example/jwt.key diff --git a/apps/auth/tokens.example/jwt.key.pub b/apps/auth/tokens.example/jwt.key.pub new file mode 100644 index 0000000..e69de29 diff --git a/apps/user-data/prisma/.gitignore b/apps/user-data/prisma/.gitignore new file mode 100644 index 0000000..24a8e4d --- /dev/null +++ b/apps/user-data/prisma/.gitignore @@ -0,0 +1 @@ +migrations diff --git a/apps/user-data/serving/.gitignore b/apps/user-data/serving/.gitignore index 7278035..f78e42d 100644 --- a/apps/user-data/serving/.gitignore +++ b/apps/user-data/serving/.gitignore @@ -20,7 +20,7 @@ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 -# User-specific stuff +# user-specific stuff .idea/**/workspace.xml .idea/**/tasks.xml .idea/**/usage.statistics.xml