From cda6aeaeef4962e7f4a81d34f60d41622590d7a4 Mon Sep 17 00:00:00 2001 From: Konstantin Tsabolov <konstantin.tsabolov@spherity.com> Date: Mon, 27 Nov 2023 18:51:46 +0100 Subject: [PATCH] feat: create credential-manager service --- apps/credential-manager/.env.example | 7 + apps/credential-manager/LICENSE | 636 ++++++++++++++++++ apps/credential-manager/jest.config.js | 49 ++ apps/credential-manager/nest-cli.json | 14 + apps/credential-manager/package.json | 62 ++ apps/credential-manager/src/app.module.ts | 26 + .../src/common/constants.ts | 1 + .../src/config/http.config.ts | 6 + .../src/config/nats.config.ts | 6 + .../src/config/ssi.config.ts | 5 + .../src/config/validation.ts | 11 + .../src/health/health.controller.ts | 35 + .../src/health/health.module.ts | 34 + apps/credential-manager/src/main.ts | 45 ++ apps/credential-manager/tsconfig.build.json | 9 + apps/credential-manager/tsconfig.json | 3 + .../tsconfig.production.json | 9 + 17 files changed, 958 insertions(+) create mode 100644 apps/credential-manager/.env.example create mode 100644 apps/credential-manager/LICENSE create mode 100644 apps/credential-manager/jest.config.js create mode 100644 apps/credential-manager/nest-cli.json create mode 100644 apps/credential-manager/package.json create mode 100644 apps/credential-manager/src/app.module.ts create mode 100644 apps/credential-manager/src/common/constants.ts create mode 100644 apps/credential-manager/src/config/http.config.ts create mode 100644 apps/credential-manager/src/config/nats.config.ts create mode 100644 apps/credential-manager/src/config/ssi.config.ts create mode 100644 apps/credential-manager/src/config/validation.ts create mode 100644 apps/credential-manager/src/health/health.controller.ts create mode 100644 apps/credential-manager/src/health/health.module.ts create mode 100644 apps/credential-manager/src/main.ts create mode 100644 apps/credential-manager/tsconfig.build.json create mode 100644 apps/credential-manager/tsconfig.json create mode 100644 apps/credential-manager/tsconfig.production.json diff --git a/apps/credential-manager/.env.example b/apps/credential-manager/.env.example new file mode 100644 index 0000000..af5dfef --- /dev/null +++ b/apps/credential-manager/.env.example @@ -0,0 +1,7 @@ +HTTP_HOST=0.0.0.0 +HTTP_PORT=3011 + +NATS_URL=nats://nats:4222 +NATS_MONITORING_URL=nats://nats:8222 + +SSI_AGENT_URL=http://ssi:3010 diff --git a/apps/credential-manager/LICENSE b/apps/credential-manager/LICENSE new file mode 100644 index 0000000..6bc596c --- /dev/null +++ b/apps/credential-manager/LICENSE @@ -0,0 +1,636 @@ +GAIA-X "Attestation Manager" + +is the microservice which is responsible for handling the features +related to issuance of credentials of the GAIA-X project. It handles REST +endpoints for Schemas, Credential Definitions and Verifiable Credentials. + +Copyright 2022 Vereign AG + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +This Attestation Manager incorporates + +"elastic/ecs-winston-format", + +a Node.js package to provide a formatter for the winston logger compatible +with Elastic Common Schema (ECS) logging, which is covered by the following copyright +and permission notice: + +Copyright 2020 Elastic and contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +This Attestation Manager also incorporates + +"nestjs", + +a progressive Node.js framework for building efficient and scalable server-side applications, +which is covered by the following copyright and permission notice: + +Copyright (c) 2017-2022 Kamil Mysliwiec <https://kamilmysliwiec.com> + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"nestjs/terminus" + +, integrated healthchecks for Nest, which contains the +following copyright and permission notice: + +Copyright (c) 2018-2021 Livio Brunner, Kamil Myśliwiec + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"prisma client" + +,an auto-generated query builder that enables type-safe database access and reduces +boilerplate, which is covered by the following copyright and permission notice: + +Copyright 2019 Johannes Schickling + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +This Attestation Manager also incorporates + +"types/node" + +,type definitions for Node, which is covered by the following copyright and +permission notice: + +Copyright Microsoft TypeScript, DefinitelyTyped, Alberto Schiabel, +Alvis HT Tang, Andrew Makarov, Benjamin Toueg, Chigozirim C., David Junger, Deividas Bakanas, Eugene Y. Q. Shen, +Hannes Magnusson, Huw, Kelvin Jin, Klaus Meinhardt, Lishude, Mariusz Wiktorczyk, Mohsen Azimi, Nicolas Even, +Nikita Galkin, Parambir Singh, Sebastian Silbermann, Simon Schick, Thomas den Hollander, Wilco Bakker, wwwy3y3, +Samuel Ainsworth, Kyle Uehlein, Thanik Bhongbhibhat, Marcin Kopacz, Trivikram Kamat, Junxiao Shi, Ilia Baryshnikov, +ExE Boss, Piotr Błażejewicz, Anna Henningsen, Victor Perin, Yongsheng Zhang, NodeJS Contributors, +Linus Unnebäck, wafuwafu13, and Matteo Collina. + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"types/express" + +,type definitions for Express (http://expressjs.com), which is covered by the following +copyright and permission notice: + +Copyright Boris Yankov, China Medical University Hospital, Puneet Arora, and Dylan Frankland. + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"types/jest" + +type definitions for Jest, which is covered by the following copyright and permission notice: + +Copyright Asana (https://asana.com)// Ivo Stratev, jwbay, Alexey Svetliakov, Alex Jover Morales, Allan Lukwago, +Ika, Waseem Dahman, Jamie Mason, Douglas Duteil, Ahn, Jeff Lau, Andrew Makarov, Martin Hochel, Sebastian Sebald, +Andy, Antoine Brault, Gregor Stamać, ExE Boss, Alex Bolenok, Mario Beltrán Alarcón, Tony Hallett, Jason Yu, Pawel Fajfer, +Regev Brody, Alexandre Germain, and Adam Jones. + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"class-validator" + +, a tool to allow decorator and non-decorator based validation, + +and + +"class-transformer" + +,a tool to transform plain object to some instance of class and versa, also to serialize / +deserialize object based on criteria, both of which are covered by the following copyright +and permission notice: + +Copyright 2015-2020 TypeStack + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"express" + +,a fast, unopinionated, minimalist web framework for node, which is covered by the following copyright +and permission notice: + +Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca> +Copyright (c) 2013-2014 Roman Shtylman <shtylman+expressjs@gmail.com> +Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com> + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"husky" + +, modern native Git hooks made easy, which is covered by the following copyright and +permission notice: + +Copyright (c) 2021 typicode + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"joi" + +, the most powerful schema description language and data validator for JavaScript, which is +covered by the following copyright and permission notice: + +Copyright (c) 2012-2020, Sideway. Inc, and project contributors. +Copyright (c) 2012-2014, Walmart. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +- 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. +- The names of any contributors may not 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 HOLDERS AND 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. + + +This Attestation Manager also incorporates + +"liquibase" + +, liquibase is an open-source database-independent library for tracking, managing and applying database schema change, which is covered +by the following copyright and permission notice: + +Copyright (c) Taylor Buckner <taylora.buckner@gmail.com> + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"moment" + +, a JavaScript date library for parsing, validating, manipulating, and formatting dates, +which is covered by the following copyright and permission notice: + +Copyright (c) JS Foundation and other contributors + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"nats" + +, a Node.js client for the NATS messaging system, which is covered by +the following copyright and permission notice: + +Copyright 2013-2018 The NATS Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +This Attestation Manager also incorporates + +"pg - node postgres" + +, non-blocking PostgreSQL client for Node.js, which is covered by +the following copyright and permission notice: + +Copyright (c) 2010-2020 Brian Carlson (brian.m.carlson@gmail.com) + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"prisma" + +, next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, +SQLite, MongoDB and CockroachDB, which is covered by the following copyright and +permission notice: + +Copyright 2019 Johannes Schickling + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +This Attestation Manager also incorporates + +"reflect-metadata" + +, prototype for a Metadata Reflection API for ECMAScript, which is covered +by the following copyright and permission notice: + +Copyright 2019 Ron Buckton + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +This Attestation Manager also incorporates + +"rimraf" + +, a `rm -rf` util for nodejs, which is covered by the following copyright +and permission notice: + +Copyright (c) 2011-2022 Isaac Z. Schlueter and Contributors + +(The ISC License) +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR +IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +This Attestation Manager also incorporates + +"rxjs" + +, reactive extensions for JavaScript, which is covered by the following copyright +and permission notice: + +Copyright (c) 2015-2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + +This Attestation Manager also incorporates + +"Swagger UI Express" + +, allows to serve auto-generated swagger-ui generated API docs from express, +based on a swagger.json file, which is covered by the following copyright and +permission notice: + +Copyright (c) 2018 Scott IT London + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"winston" + +, a logger for just about everything, which is covered by the following copyright and +permission notice: + +Copyright (c) 2010 Charlie Robbins + +(The MIT License) +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. + + +This Attestation Manager also incorporates + +"winston-elasticsearch" + +, an elasticsearch transport for winston, which is covered by the following copyright and +permission notice: + +Copyright (c) 2015 - 2018 Thomas Hoppe. +Copyright (c) 2013 Jacques-Olivier D. Bernier. + +(The MIT License) +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. diff --git a/apps/credential-manager/jest.config.js b/apps/credential-manager/jest.config.js new file mode 100644 index 0000000..5ece9fc --- /dev/null +++ b/apps/credential-manager/jest.config.js @@ -0,0 +1,49 @@ +import { readFileSync } from 'node:fs'; + +const swcConfig = JSON.parse(readFileSync('../../.swcrc', 'utf8')); + +/** @type {import('jest').Config} */ +export default { + moduleFileExtensions: ['js', 'ts'], + testEnvironment: 'node', + transform: { + '^.+\\.(js|ts)$': [ + '@swc/jest', + { + ...swcConfig, + sourceMaps: false, + exclude: [], + swcrc: false, + }, + ], + }, + extensionsToTreatAsEsm: ['.ts'], + moduleNameMapper: { + // ESM modules require `.js` extension to be specified, but Jest doesn't work with them + // Removing `.js` extension from module imports + '^uuid$': 'uuid', + '^(.*)/(.*)\\.js$': '$1/$2', + }, + collectCoverageFrom: ['src/**/*.(t|j)s'], + coverageReporters: + process.env.CI === 'true' + ? ['text-summary', 'json-summary'] + : ['text-summary', 'html'], + coveragePathIgnorePatterns: [ + '<rootDir>/node_modules/', + '<rootDir>/test/', + '<rootDir>/coverage/', + '<rootDir>/dist/', + '<rootDir>/**/test', + '@types', + '.dto.(t|j)s', + '.enum.ts', + '.interface.ts', + '.type.ts', + '.spec.ts', + ], + coverageDirectory: './coverage', + // With v8 coverage provider it's much faster, but + // with this enabled it's not possible to ignore whole files' coverage + coverageProvider: 'v8', +}; diff --git a/apps/credential-manager/nest-cli.json b/apps/credential-manager/nest-cli.json new file mode 100644 index 0000000..b9af737 --- /dev/null +++ b/apps/credential-manager/nest-cli.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src", + "compilerOptions": { + "typeCheck": true, + "builder": { + "type": "swc", + "options": { + "swcrcPath": "../../.swcrc" + } + } + } +} diff --git a/apps/credential-manager/package.json b/apps/credential-manager/package.json new file mode 100644 index 0000000..35e5df5 --- /dev/null +++ b/apps/credential-manager/package.json @@ -0,0 +1,62 @@ +{ + "name": "@ocm/credential-manager", + "version": "1.0.0", + "description": "", + "author": "Konstantin Tsabolov <konstantin.tsabolov@spherity.com>", + "contributors": [ + "Konstantin Tsabolov <konstantin.tsabolov@spherity.com>" + ], + "private": true, + "license": "Apache-2.0", + "type": "module", + "scripts": { + "clean": "rimraf dist coverage *.tsbuildinfo", + "prebuild": "pnpm clean", + "build": "nest build", + "prebuild:production": "pnpm clean", + "build:production": "nest build -p tsconfig.production.json", + "start": "nest start", + "start:dev": "nest start --watch --preserveWatchOutput", + "test": "jest", + "test:watch": "jest --watch", + "test:cov": "jest --coverage", + "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", + "test:e2e": "jest --config ./test/jest.config.js" + }, + "dependencies": { + "@nestjs/axios": "^3.0.1", + "@nestjs/common": "^10.2.10", + "@nestjs/config": "^3.1.1", + "@nestjs/core": "^10.2.10", + "@nestjs/microservices": "^10.2.10", + "@nestjs/platform-express": "^10.2.8", + "@nestjs/swagger": "^7.1.16", + "@nestjs/terminus": "^10.1.1", + "axios": "^1.6.2", + "class-transformer": "^0.5.1", + "class-validator": "^0.14.0", + "express": "^4.17.3", + "joi": "^17.11.0", + "nats": "^2.18.0", + "reflect-metadata": "^0.1.13", + "rxjs": "^7.8.1" + }, + "devDependencies": { + "@nestjs/cli": "^10.2.1", + "@nestjs/schematics": "^10.0.3", + "@nestjs/testing": "^10.2.8", + "@swc/cli": "^0.1.62", + "@swc/core": "^1.3.96", + "@swc/jest": "^0.2.29", + "@types/express": "^4.17.21", + "@types/jest": "^29.5.8", + "@types/jsonwebtoken": "^9.0.5", + "@types/node": "^20.9.0", + "@types/supertest": "^2.0.16", + "dotenv-cli": "^7.3.0", + "eslint": "^8.53.0", + "jest": "^29.7.0", + "rimraf": "^5.0.5", + "typescript": "^5.3.2" + } +} diff --git a/apps/credential-manager/src/app.module.ts b/apps/credential-manager/src/app.module.ts new file mode 100644 index 0000000..2f9297a --- /dev/null +++ b/apps/credential-manager/src/app.module.ts @@ -0,0 +1,26 @@ +import { Module } from '@nestjs/common'; +import { ConfigModule } from '@nestjs/config'; + +import { httpConfig } from './config/http.config.js'; +import { natsConfig } from './config/nats.config.js'; +import { ssiConfig } from './config/ssi.config.js'; +import { validationSchema } from './config/validation.js'; +import { HealthModule } from './health/health.module.js'; + +@Module({ + imports: [ + ConfigModule.forRoot({ + isGlobal: true, + load: [httpConfig, natsConfig, ssiConfig], + cache: true, + expandVariables: true, + validationSchema, + validationOptions: { + allowUnknown: true, + abortEarly: true, + }, + }), + HealthModule, + ], +}) +export default class AppModule {} diff --git a/apps/credential-manager/src/common/constants.ts b/apps/credential-manager/src/common/constants.ts new file mode 100644 index 0000000..bad6a5f --- /dev/null +++ b/apps/credential-manager/src/common/constants.ts @@ -0,0 +1 @@ +export const SERVICE_NAME = 'CREDENTIAL_MANAGER_SERVICE'; diff --git a/apps/credential-manager/src/config/http.config.ts b/apps/credential-manager/src/config/http.config.ts new file mode 100644 index 0000000..0bb4d4c --- /dev/null +++ b/apps/credential-manager/src/config/http.config.ts @@ -0,0 +1,6 @@ +import { registerAs } from '@nestjs/config'; + +export const httpConfig = registerAs('http', () => ({ + host: process.env.HOST, + port: Number(process.env.PORT), +})); diff --git a/apps/credential-manager/src/config/nats.config.ts b/apps/credential-manager/src/config/nats.config.ts new file mode 100644 index 0000000..023e923 --- /dev/null +++ b/apps/credential-manager/src/config/nats.config.ts @@ -0,0 +1,6 @@ +import { registerAs } from '@nestjs/config'; + +export const natsConfig = registerAs('nats', () => ({ + url: process.env.NATS_URL, + monitoringUrl: process.env.NATS_MONITORING_URL, +})); diff --git a/apps/credential-manager/src/config/ssi.config.ts b/apps/credential-manager/src/config/ssi.config.ts new file mode 100644 index 0000000..1779919 --- /dev/null +++ b/apps/credential-manager/src/config/ssi.config.ts @@ -0,0 +1,5 @@ +import { registerAs } from '@nestjs/config'; + +export const ssiConfig = registerAs('ssi', () => ({ + agentUrl: process.env.SSI_AGENT_URL, +})); diff --git a/apps/credential-manager/src/config/validation.ts b/apps/credential-manager/src/config/validation.ts new file mode 100644 index 0000000..a7fe2f8 --- /dev/null +++ b/apps/credential-manager/src/config/validation.ts @@ -0,0 +1,11 @@ +import Joi from 'joi'; + +export const validationSchema = Joi.object({ + HTTP_HOST: Joi.string().default('0.0.0.0'), + HTTP_PORT: Joi.number().default(3000), + + NATS_URL: Joi.string().uri().default('nats://localhost:4222'), + NATS_MONITORING_URL: Joi.string().uri().default('http://localhost:8222'), + + SSI_AGENT_URL: Joi.string().default('http://localhost:3010'), +}); diff --git a/apps/credential-manager/src/health/health.controller.ts b/apps/credential-manager/src/health/health.controller.ts new file mode 100644 index 0000000..9f2454e --- /dev/null +++ b/apps/credential-manager/src/health/health.controller.ts @@ -0,0 +1,35 @@ +import type { HealthIndicatorFunction } from '@nestjs/terminus'; + +import { Controller, Get } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { + HealthCheck, + HealthCheckService, + HttpHealthIndicator, +} from '@nestjs/terminus'; + +@Controller('health') +export class HealthController { + public constructor( + private readonly config: ConfigService, + private readonly health: HealthCheckService, + private readonly http: HttpHealthIndicator, + ) {} + + @Get() + @HealthCheck() + public check() { + const healthIndicators: HealthIndicatorFunction[] = []; + + const natsMonitoringUrl = this.config.get('nats.monitoringUrl'); + if (typeof natsMonitoringUrl === 'string') { + healthIndicators.push(() => + this.http.pingCheck('nats', natsMonitoringUrl), + ); + } else { + healthIndicators.push(() => ({ nats: { status: 'down' } })); + } + + return this.health.check(healthIndicators); + } +} diff --git a/apps/credential-manager/src/health/health.module.ts b/apps/credential-manager/src/health/health.module.ts new file mode 100644 index 0000000..17ccd14 --- /dev/null +++ b/apps/credential-manager/src/health/health.module.ts @@ -0,0 +1,34 @@ +import type { ConfigType } from '@nestjs/config'; + +import { HttpModule } from '@nestjs/axios'; +import { Module } from '@nestjs/common'; +import { ClientsModule, Transport } from '@nestjs/microservices'; +import { TerminusModule } from '@nestjs/terminus'; + +import { SERVICE_NAME } from '../common/constants.js'; +import { natsConfig } from '../config/nats.config.js'; + +import { HealthController } from './health.controller.js'; + +@Module({ + imports: [ + TerminusModule, + HttpModule, + ClientsModule.registerAsync({ + clients: [ + { + name: SERVICE_NAME, + inject: [natsConfig.KEY], + useFactory: (config: ConfigType<typeof natsConfig>) => ({ + transport: Transport.NATS, + options: { + servers: [config.url as string], + }, + }), + }, + ], + }), + ], + controllers: [HealthController], +}) +export class HealthModule {} diff --git a/apps/credential-manager/src/main.ts b/apps/credential-manager/src/main.ts new file mode 100644 index 0000000..746af79 --- /dev/null +++ b/apps/credential-manager/src/main.ts @@ -0,0 +1,45 @@ +import type { MicroserviceOptions } from '@nestjs/microservices'; + +import { VersioningType } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { NestFactory } from '@nestjs/core'; +import { Transport } from '@nestjs/microservices'; +import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; + +import AppModule from './app.module.js'; +// import AllExceptionsFilter from './utils/exceptionsFilter.js'; +// import logger from './utils/logger.js'; + +const app = await NestFactory.create(AppModule); +const configService = app.get(ConfigService); +app.enableCors(); + +app.connectMicroservice<MicroserviceOptions>({ + transport: Transport.NATS, + options: { + servers: [configService.get('nats').url], + }, +}); + +app.enableVersioning({ + defaultVersion: ['1'], + type: VersioningType.URI, +}); + +const swaggerConfig = new DocumentBuilder() + .setTitle('Gaia-X OCM Credential Manager API') + .setDescription('API documentation for Gaia-X OCM Credential Manager') + .setVersion('1.0') + .build(); + +const document = SwaggerModule.createDocument(app, swaggerConfig); + +SwaggerModule.setup('/swagger', app, document); +await app.startAllMicroservices(); + +// const httpAdapter = app.get(HttpAdapterHost); +// app.useGlobalFilters(new AllExceptionsFilter(httpAdapter)); + +await app.listen(configService.get('PORT') || 3000, () => { + // logger.info(`Listening on Port:${configService.get('PORT')}` || 3000); +}); diff --git a/apps/credential-manager/tsconfig.build.json b/apps/credential-manager/tsconfig.build.json new file mode 100644 index 0000000..3e5ab43 --- /dev/null +++ b/apps/credential-manager/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.build.json", + "compilerOptions": { + "baseUrl": ".", + "outDir": "./dist", + "rootDir": "./src" + }, + "exclude": ["node_modules", "**/test", "**/dist", "**/*spec.ts"] +} diff --git a/apps/credential-manager/tsconfig.json b/apps/credential-manager/tsconfig.json new file mode 100644 index 0000000..4082f16 --- /dev/null +++ b/apps/credential-manager/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.json" +} diff --git a/apps/credential-manager/tsconfig.production.json b/apps/credential-manager/tsconfig.production.json new file mode 100644 index 0000000..45f85df --- /dev/null +++ b/apps/credential-manager/tsconfig.production.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.production.json", + "compilerOptions": { + "baseUrl": ".", + "outDir": "./dist", + "rootDir": "./src" + }, + "exclude": ["node_modules", "**/test", "**/dist", "**/*spec.ts"] +} -- GitLab