mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-01 12:18:15 +00:00
Compare commits
44
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10c4ed179b | ||
|
|
e55a1cb657 | ||
|
|
3850d4b8ae | ||
|
|
2a6677e4d9 | ||
|
|
74e62c001d | ||
|
|
8237160c6d | ||
|
|
41bf9d4856 | ||
|
|
44dcf1b281 | ||
|
|
104787bce8 | ||
|
|
38a330e578 | ||
|
|
7d0b8755c9 | ||
|
|
7aadf4d9d1 | ||
|
|
af8fa72377 | ||
|
|
c51f262474 | ||
|
|
54d19a78ab | ||
|
|
66f33a2246 | ||
|
|
55d9441d10 | ||
|
|
8b7342652e | ||
|
|
118c2653a5 | ||
|
|
f7d0128d99 | ||
|
|
12cc555491 | ||
|
|
cf5e36db00 | ||
|
|
7c0b87ffc3 | ||
|
|
beb086ad3c | ||
|
|
8c12291096 | ||
|
|
56a063b644 | ||
|
|
3a6054c1c6 | ||
|
|
3a696ecb0e | ||
|
|
1166073b1c | ||
|
|
3026cd0748 | ||
|
|
b48d3ae667 | ||
|
|
5868f21f22 | ||
|
|
873f7ea314 | ||
|
|
2b01b340e4 | ||
|
|
5888088486 | ||
|
|
9e2de28032 | ||
|
|
db2ea09d25 | ||
|
|
8c6b514b7b | ||
|
|
ad03d663bb | ||
|
|
48d4cbc41a | ||
|
|
ae81816aa7 | ||
|
|
ccdff58056 | ||
|
|
c10f85950a | ||
|
|
7d69220461 |
@@ -3,6 +3,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
- beta
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
environment:
|
environment:
|
||||||
@@ -11,7 +12,6 @@ on:
|
|||||||
type: choice
|
type: choice
|
||||||
options:
|
options:
|
||||||
- stg
|
- stg
|
||||||
- stg2
|
|
||||||
- prd
|
- prd
|
||||||
push_to_dockerhub:
|
push_to_dockerhub:
|
||||||
description: "Push image to Dockerhub?"
|
description: "Push image to Dockerhub?"
|
||||||
@@ -34,6 +34,8 @@ jobs:
|
|||||||
echo "environment=${DEPLOY_ENV}" >> $GITHUB_OUTPUT
|
echo "environment=${DEPLOY_ENV}" >> $GITHUB_OUTPUT
|
||||||
elif [ ${GITHUB_REF} == "refs/heads/main" ]; then
|
elif [ ${GITHUB_REF} == "refs/heads/main" ]; then
|
||||||
echo "environment=prd" >> $GITHUB_OUTPUT
|
echo "environment=prd" >> $GITHUB_OUTPUT
|
||||||
|
elif [ ${GITHUB_REF} == "refs/heads/beta" ]; then
|
||||||
|
echo "environment=stg" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
id: extract_environment
|
id: extract_environment
|
||||||
|
|
||||||
@@ -48,38 +50,40 @@ jobs:
|
|||||||
|
|
||||||
- if: github.event_name != 'workflow_dispatch'
|
- if: github.event_name != 'workflow_dispatch'
|
||||||
name: Semantic Release
|
name: Semantic Release
|
||||||
uses: cycjimmy/semantic-release-action@v4
|
uses: cycjimmy/semantic-release-action@v3
|
||||||
id: semantic
|
id: semantic
|
||||||
with:
|
with:
|
||||||
extra_plugins: |
|
extra_plugins: |
|
||||||
conventional-changelog-eslint@4
|
conventional-changelog-eslint@4.0.0
|
||||||
branches: |
|
branches: |
|
||||||
[
|
[
|
||||||
'main'
|
'main',
|
||||||
|
{
|
||||||
|
name: 'alpha',
|
||||||
|
prerelease: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'beta',
|
||||||
|
prerelease: true
|
||||||
|
}
|
||||||
]
|
]
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
deploy-info:
|
build_ecr_image:
|
||||||
if: ${{ github.event_name == 'workflow_dispatch'}}
|
if: ${{ github.event_name == 'workflow_dispatch' || needs.semantic_release.outputs.new_release_published == 'true' }}
|
||||||
needs: [extract_environment, semantic_release]
|
needs: [extract_environment, semantic_release]
|
||||||
runs-on: ubuntu-latest
|
runs-on:
|
||||||
|
[self-hosted, "prd"]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Create summary
|
- name: Printing stats
|
||||||
env:
|
env:
|
||||||
EVENT: ${{ github.event_name }}
|
EVENT: ${{ github.event_name }}
|
||||||
IMAGE_TAG: ${{ needs.semantic_release.outputs.new_release_version }}
|
IMAGE_TAG: ${{ needs.semantic_release.outputs.new_release_version }}
|
||||||
ENV: ${{ needs.extract_environment.outputs.environment }}
|
ENV: ${{ needs.extract_environment.outputs.environment }}
|
||||||
run: echo "### Deploy da branch \`$GITHUB_REF_NAME\` no ambiente **$ENV** :rocket:" >> $GITHUB_STEP_SUMMARY
|
run: echo ${GITHUB_REF#refs/heads/}
|
||||||
|
|
||||||
deploy:
|
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' || needs.semantic_release.outputs.new_release_published == 'true' }}
|
|
||||||
needs: [extract_environment, semantic_release]
|
|
||||||
runs-on:
|
|
||||||
[self-hosted, "${{ needs.extract_environment.outputs.environment }}"]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -131,94 +135,83 @@ jobs:
|
|||||||
docker compose -f build.docker-compose.dockerhub.yml build
|
docker compose -f build.docker-compose.dockerhub.yml build
|
||||||
docker compose -f build.docker-compose.dockerhub.yml push
|
docker compose -f build.docker-compose.dockerhub.yml push
|
||||||
|
|
||||||
- name: Create ZIP file to Deploy AWS Beanstalk
|
# - name: Create ZIP file to Deploy AWS Beanstalk
|
||||||
env:
|
# env:
|
||||||
ENV: ${{ needs.extract_environment.outputs.environment }}
|
# ENV: ${{ needs.extract_environment.outputs.environment }}
|
||||||
IMAGE_TAG: ${{ needs.semantic_release.outputs.new_release_version }}
|
# IMAGE_TAG: ${{ needs.semantic_release.outputs.new_release_version }}
|
||||||
ACCOUNT_ID: ${{ steps.aws.outputs.aws-account-id }}
|
# ACCOUNT_ID: ${{ steps.aws.outputs.aws-account-id }}
|
||||||
NODE_EXPORTER_URL: ${{format('{0}.dkr.ecr.us-east-1.amazonaws.com\/monitoring\/node_exporter:latest', steps.aws.outputs.aws-account-id)}} # ${{needs.extract_environment.outputs.environment == 'prd' && '611330257153.dkr.ecr.us-east-1.amazonaws.com\/monitoring\/node_exporter:latest' || '468720548566.dkr.ecr.us-east-1.amazonaws.com\/monitoring\/node_exporter:latest'}}
|
# NODE_EXPORTER_URL: ${{needs.extract_environment.outputs.environment == 'prd' && '611330257153.dkr.ecr.us-east-1.amazonaws.com\/monitoring\/node_exporter:latest' || '468720548566.dkr.ecr.us-east-1.amazonaws.com\/monitoring\/node_exporter:latest'}}
|
||||||
run: |
|
# run: |
|
||||||
sed -i -e "s/\${ENV}/$ENV/g" docker-compose.yml
|
# sed -i -e "s/\${ENV}/$ENV/g" docker-compose.yml
|
||||||
sed -i -e "s/\${IMAGE_TAG}/$IMAGE_TAG/g" docker-compose.yml
|
# sed -i -e "s/\${IMAGE_TAG}/$IMAGE_TAG/g" docker-compose.yml
|
||||||
sed -i -e "s/\${ACCOUNT_ID}/$ACCOUNT_ID/g" docker-compose.yml
|
# sed -i -e "s/\${ACCOUNT_ID}/$ACCOUNT_ID/g" docker-compose.yml
|
||||||
sed -i -e "s/\${NODE_EXPORTER_URL}/$NODE_EXPORTER_URL/g" docker-compose.yml
|
# sed -i -e "s/\${NODE_EXPORTER_URL}/$NODE_EXPORTER_URL/g" docker-compose.yml
|
||||||
zip deploy.zip docker-compose.yml -r .ebextensions
|
# zip deploy.zip docker-compose.yml -r .ebextensions
|
||||||
|
|
||||||
- name: Deploy AWS Beanstalk
|
# - name: Deploy AWS Beanstalk
|
||||||
env:
|
# env:
|
||||||
ENV: ${{ needs.extract_environment.outputs.environment }}
|
# ENV: ${{ needs.extract_environment.outputs.environment }}
|
||||||
AWS_REGION: us-east-1
|
# AWS_REGION: us-east-1
|
||||||
APP_NAME: ${{ github.event.repository.name }}
|
# APP_NAME: ${{ github.event.repository.name }}
|
||||||
run: |
|
# run: |
|
||||||
eb use $APP_NAME-$ENV
|
# eb use $APP_NAME-$ENV
|
||||||
echo -e "deploy:\n artifact: deploy.zip" >> .elasticbeanstalk/config.yml
|
# echo -e "deploy:\n artifact: deploy.zip" >> .elasticbeanstalk/config.yml
|
||||||
eb deploy
|
# eb deploy
|
||||||
|
|
||||||
- name: Remove Docker's Trash
|
- name: Remove Docker's Trash
|
||||||
if: always()
|
if: always()
|
||||||
run: |
|
run: |
|
||||||
docker system prune --volumes -a -f
|
docker system prune --volumes -a -f
|
||||||
docker system df
|
docker system df
|
||||||
api_docs:
|
|
||||||
needs: [extract_environment, semantic_release, deploy]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Extract Docs BlockId and PageId
|
helmfile-deploy:
|
||||||
|
needs: [extract_environment, semantic_release, build_ecr_image]
|
||||||
|
runs-on: [self-hosted, "prd-azure"]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Helm
|
||||||
|
uses: azure/setup-helm@v1
|
||||||
|
with:
|
||||||
|
version: 'v3.9.0'
|
||||||
|
|
||||||
|
- name: Install Azure ClI
|
||||||
|
run: |
|
||||||
|
curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
||||||
|
|
||||||
|
- uses: azure/login@v2
|
||||||
|
with:
|
||||||
|
creds: '{"clientId":"${{ secrets.ARM_CLIENT_ID }}","clientSecret":"${{ secrets.ARM_CLIENT_SECRET }}","subscriptionId":"${{ secrets.ARM_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.ARM_TENANT_ID }}"}'
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.8'
|
||||||
|
|
||||||
|
- name: Install Helmfile
|
||||||
|
run: |
|
||||||
|
wget https://github.com/helmfile/helmfile/releases/download/v0.148.0/helmfile_0.148.0_linux_amd64.tar.gz
|
||||||
|
tar -xzf helmfile_0.148.0_linux_amd64.tar.gz
|
||||||
|
mv helmfile /usr/local/bin/
|
||||||
|
helmfile --version
|
||||||
|
|
||||||
|
- name: Install Helm Diff Plugin
|
||||||
|
run: helm plugin install https://github.com/databus23/helm-diff || true
|
||||||
|
|
||||||
|
- name: Setup kubectl
|
||||||
|
uses: azure/setup-kubectl@v1
|
||||||
|
with:
|
||||||
|
version: 'v1.30.1'
|
||||||
|
|
||||||
|
- name: Authenticate with cluster
|
||||||
|
env:
|
||||||
|
CLUSTER_NAME: platform-${{ needs.extract_environment.outputs.environment }}
|
||||||
|
run: az aks get-credentials --resource-group dadosfera-prd --name ${CLUSTER_NAME} --overwrite-existing
|
||||||
|
|
||||||
|
- name: Run Helmfile Apply
|
||||||
env:
|
env:
|
||||||
ENV: ${{ needs.extract_environment.outputs.environment }}
|
ENV: ${{ needs.extract_environment.outputs.environment }}
|
||||||
STG2_DOCS_BLOCK_ID: ${{ secrets.DEV_DOCS_BLOCK_ID }}
|
IMAGE_TAG: ${{ needs.semantic_release.outputs.new_release_version }}
|
||||||
STG2_DOCS_PAGE_ID: ${{ secrets.DEV_DOCS_PAGE_ID }}
|
run: helmfile -f helmfiles/${ENV}.yaml sync --set image.tag=$IMAGE_TAG
|
||||||
STG_DOCS_BLOCK_ID: ${{ secrets.STG_DOCS_BLOCK_ID }}
|
|
||||||
STG_DOCS_PAGE_ID: ${{ secrets.STG_DOCS_PAGE_ID }}
|
|
||||||
PRD_DOCS_BLOCK_ID: ${{ secrets.PRD_DOCS_BLOCK_ID }}
|
|
||||||
PRD_DOCS_PAGE_ID: ${{ secrets.PRD_DOCS_PAGE_ID }}
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
if [ $ENV == "stg2" ]; then
|
|
||||||
echo "block_id=$STG2_DOCS_BLOCK_ID" >> $GITHUB_OUTPUT
|
|
||||||
echo "page_id=$STG2_DOCS_PAGE_ID" >> $GITHUB_OUTPUT
|
|
||||||
elif [ $ENV == "stg" ]; then
|
|
||||||
echo "block_id=$STG_DOCS_BLOCK_ID" >> $GITHUB_OUTPUT
|
|
||||||
echo "page_id=$STG_DOCS_PAGE_ID" >> $GITHUB_OUTPUT
|
|
||||||
elif [ $ENV == "prd" ]; then
|
|
||||||
echo "block_id=$PRD_DOCS_BLOCK_ID" >> $GITHUB_OUTPUT
|
|
||||||
echo "page_id=$PRD_DOCS_PAGE_ID" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
id: extract_docs_info
|
|
||||||
|
|
||||||
- name: Generate API docs
|
|
||||||
env:
|
|
||||||
DOCS_URL: ${{ secrets.DOCS_URL }}
|
|
||||||
DOCS_API_TOKEN: ${{ secrets.DOCS_API_TOKEN }}
|
|
||||||
DOCS_PAGE_ID: ${{ steps.extract_docs_info.outputs.page_id }}
|
|
||||||
DOCS_BLOCK_ID: ${{ steps.extract_docs_info.outputs.block_id }}
|
|
||||||
EVENT: ${{ github.event_name }}
|
|
||||||
RELEASE_VERSION: ${{ needs.semantic_release.outputs.new_release_version }}
|
|
||||||
run: |
|
|
||||||
if [ ${EVENT} != "workflow_dispatch" ]; then
|
|
||||||
sed -i -E "s/(\"title\": )\"Maestro.+\"/\1\"Maestro - $RELEASE_VERSION\"/g" docsfera.json
|
|
||||||
fi
|
|
||||||
sed -i -e "s/\${DOCS_API_TOKEN}/$DOCS_API_TOKEN/g" docsfera.json
|
|
||||||
sed -i -e "s/\${DOCS_PAGE_ID}/$DOCS_PAGE_ID/g" docsfera.json
|
|
||||||
sed -i -e "s/\${DOCS_BLOCK_ID}/$DOCS_BLOCK_ID/g" docsfera.json
|
|
||||||
curl -X POST -H 'Content-Type: application/json' -d @docsfera.json $DOCS_URL
|
|
||||||
|
|
||||||
- name: Generate External API docs
|
|
||||||
env:
|
|
||||||
DOCS_URL: ${{ secrets.DOCS_URL }}
|
|
||||||
DOCS_API_TOKEN: ${{ secrets.DOCS_API_TOKEN }}
|
|
||||||
DOCS_PAGE_ID: ${{secrets.EXTERNAL_DOCS_PAGE_ID}}
|
|
||||||
DOCS_BLOCK_ID: ${{secrets.EXTERNAL_DOCS_BLOCK_ID}}
|
|
||||||
EVENT: ${{ github.event_name }}
|
|
||||||
RELEASE_VERSION: ${{ needs.semantic_release.outputs.new_release_version }}
|
|
||||||
run: |
|
|
||||||
if [ ${EVENT} != "workflow_dispatch" ]; then
|
|
||||||
sed -i -E "s/(\"title\": )\"Maestro.+\"/\1\"Maestro - $RELEASE_VERSION\"/g" docsfera.external.json
|
|
||||||
fi
|
|
||||||
sed -i -e "s/\${DOCS_API_TOKEN}/$DOCS_API_TOKEN/g" docsfera.external.json
|
|
||||||
sed -i -e "s/\${DOCS_PAGE_ID}/$DOCS_PAGE_ID/g" docsfera.external.json
|
|
||||||
sed -i -e "s/\${DOCS_BLOCK_ID}/$DOCS_BLOCK_ID/g" docsfera.external.json
|
|
||||||
curl -X POST -H 'Content-Type: application/json' -d @docsfera.external.json $DOCS_URL
|
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
name: Validate K8S Modifications
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- stg
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
extract_environment:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
outputs:
|
||||||
|
environment: ${{ steps.extract_environment.outputs.environment }}
|
||||||
|
steps:
|
||||||
|
- name: Extract Environment
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.event.pull_request.base.ref }}" == "main" ]; then
|
||||||
|
echo "environment=prd" >> $GITHUB_OUTPUT
|
||||||
|
elif [ "${{ github.event.pull_request.base.ref }}" == "beta" ]; then
|
||||||
|
echo "environment=stg" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
id: extract_environment
|
||||||
|
|
||||||
|
helmfile-deploy:
|
||||||
|
needs: [extract_environment]
|
||||||
|
runs-on: [self-hosted, "prd-azure"]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Summary
|
||||||
|
env:
|
||||||
|
ENV: ${{ needs.extract_environment.outputs.environment }}
|
||||||
|
run: |
|
||||||
|
echo "### :rocket: Deploy da branch \`$GITHUB_REF_NAME\` para o environment ($ENV)" >> $GITHUB_STEP_SUMMARY
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Helm
|
||||||
|
uses: azure/setup-helm@v1
|
||||||
|
with:
|
||||||
|
version: 'v3.9.0'
|
||||||
|
|
||||||
|
- name: Install Azure ClI
|
||||||
|
run: |
|
||||||
|
curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
||||||
|
|
||||||
|
- uses: azure/login@v2
|
||||||
|
with:
|
||||||
|
creds: '{"clientId":"${{ secrets.ARM_CLIENT_ID }}","clientSecret":"${{ secrets.ARM_CLIENT_SECRET }}","subscriptionId":"${{ secrets.ARM_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.ARM_TENANT_ID }}"}'
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.8'
|
||||||
|
|
||||||
|
- name: Install Helmfile
|
||||||
|
run: |
|
||||||
|
wget https://github.com/helmfile/helmfile/releases/download/v0.148.0/helmfile_0.148.0_linux_amd64.tar.gz
|
||||||
|
tar -xzf helmfile_0.148.0_linux_amd64.tar.gz
|
||||||
|
mv helmfile /usr/local/bin/
|
||||||
|
helmfile --version
|
||||||
|
|
||||||
|
- name: Install Helm Diff Plugin
|
||||||
|
run: helm plugin install https://github.com/databus23/helm-diff || true
|
||||||
|
|
||||||
|
- name: Setup kubectl
|
||||||
|
uses: azure/setup-kubectl@v1
|
||||||
|
with:
|
||||||
|
version: 'v1.30.1'
|
||||||
|
|
||||||
|
- name: Authenticate with cluster
|
||||||
|
env:
|
||||||
|
CLUSTER_NAME: platform-${{ needs.extract_environment.outputs.environment }}
|
||||||
|
run: az aks get-credentials --resource-group dadosfera-prd --name ${CLUSTER_NAME} --overwrite-existing
|
||||||
|
|
||||||
|
- name: Run Helmfile Diff
|
||||||
|
env:
|
||||||
|
ENV: ${{ needs.extract_environment.outputs.environment }}
|
||||||
|
run: helmfile -f helmfiles/${ENV}.yaml diff
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
<image src="./assets/maestro.svg" style="width:10rem">
|
<image src="./assets/maestro.svg" style="width:10rem">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
# Maestro
|
# Maestro
|
||||||
|
|
||||||
Maestro é a API principal da Dadosfera. É responsável pela comunicação do Frontend com nossos microsserviços.
|
Maestro é a API principal da Dadosfera. É responsável pela comunicação do Frontend com nossos microsserviços.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
services:
|
services:
|
||||||
maestro:
|
maestro:
|
||||||
build: .
|
build: .
|
||||||
image: ${ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/microservices/maestro_${ENV}:${IMAGE_TAG}
|
image: ${ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/microservices/maestro_prd:${IMAGE_TAG}
|
||||||
|
|||||||
+164
@@ -5431,6 +5431,117 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/open-data/sharing-ocean-data": {
|
||||||
|
"post": {
|
||||||
|
"operationId": "OpenDataController_createUser",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "dadosfera-lang",
|
||||||
|
"in": "header",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"enum": [
|
||||||
|
"pt-br",
|
||||||
|
"en-us"
|
||||||
|
],
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "language",
|
||||||
|
"required": true,
|
||||||
|
"in": "query",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"OpenData"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/customers/{id}/theme": {
|
||||||
|
"post": {
|
||||||
|
"operationId": "ThemeController_saveCustomertheme",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"required": true,
|
||||||
|
"in": "path",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"requestBody": {
|
||||||
|
"required": true,
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/CustomerThemeRequest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/CustomerThemeResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Theme"
|
||||||
|
],
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"get": {
|
||||||
|
"operationId": "ThemeController_getCustomerTheme",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"required": true,
|
||||||
|
"in": "path",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/CustomerThemeResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Theme"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"/health": {
|
"/health": {
|
||||||
"get": {
|
"get": {
|
||||||
"operationId": "HealthController_check",
|
"operationId": "HealthController_check",
|
||||||
@@ -8234,6 +8345,59 @@
|
|||||||
"required": [
|
"required": [
|
||||||
"links"
|
"links"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"CustomerThemeRequest": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"displayName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"backgroundColor": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"textColor": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"displayName",
|
||||||
|
"backgroundColor",
|
||||||
|
"textColor"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"CustomerTheme": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"backgroundColor": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"textColor": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"logoWhite": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"logoBlack": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"backgroundColor",
|
||||||
|
"textColor",
|
||||||
|
"logoWhite",
|
||||||
|
"logoBlack"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"CustomerThemeResponse": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"theme": {
|
||||||
|
"$ref": "#/components/schemas/CustomerTheme"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"theme"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
@@ -12,6 +12,8 @@ declare global {
|
|||||||
INTERNAL_SWAGGER: 'true' | 'false';
|
INTERNAL_SWAGGER: 'true' | 'false';
|
||||||
|
|
||||||
AWS_REGION: string;
|
AWS_REGION: string;
|
||||||
|
OPEN_GROUP_ID: string;
|
||||||
|
OPEN_CUSTOMER_ID: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
charts:
|
||||||
|
- name: maestro
|
||||||
|
chart: ../maestro
|
||||||
|
values:
|
||||||
|
- ../maestro/values.yaml
|
||||||
|
set:
|
||||||
|
- name: maestro.duc_url
|
||||||
|
value: duc.dadosfera.ai
|
||||||
|
- name: hostname
|
||||||
|
value: maestro.dadosfera.ai
|
||||||
|
- name: maestro.pi_factory_url
|
||||||
|
value: pi-factory.dadosfera.ai
|
||||||
|
- name: maestro.in_factory_url
|
||||||
|
value: in-factory.dadosfera.ai
|
||||||
|
- name: maestro.tr_factory_url
|
||||||
|
value: in-factory.dadosfera.ai
|
||||||
|
- name: maestro.open_customer_id
|
||||||
|
value: f239718a-a271-4ef9-ae7e-02a2f0f3aa6e
|
||||||
|
- name: maestro.open_group_id
|
||||||
|
value: 401573bb-334f-44b2-b30e-88d4cea31ae9
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
charts:
|
||||||
|
- name: maestro
|
||||||
|
chart: ../maestro
|
||||||
|
values:
|
||||||
|
- ../maestro/values.yaml
|
||||||
|
set:
|
||||||
|
- name: maestro.duc_url
|
||||||
|
value: duc.stg.dadosfera.ai
|
||||||
|
- name: hostname
|
||||||
|
value: maestro.stg.dadosfera.ai
|
||||||
|
- name: maestro.pi_factory_url
|
||||||
|
value: pi-factory.dadosfera.ai
|
||||||
|
- name: maestro.in_factory_url
|
||||||
|
value: in-factory.dadosfera.ai
|
||||||
|
- name: maestro.tr_factory_url
|
||||||
|
value: in-factory.dadosfera.ai
|
||||||
|
- name: maestro.open_customer_id
|
||||||
|
value: b3e3dfe5-b992-4586-a73c-c0b0c00f615d
|
||||||
|
- name: maestro.open_group_id
|
||||||
|
value: e3f98a2f-7748-4981-8505-7695c8ca8218
|
||||||
|
- name: replicaCount
|
||||||
|
value: 1
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# Patterns to ignore when building packages.
|
||||||
|
# This supports shell glob matching, relative path matching, and
|
||||||
|
# negation (prefixed with !). Only one pattern per line.
|
||||||
|
.DS_Store
|
||||||
|
# Common VCS dirs
|
||||||
|
.git/
|
||||||
|
.gitignore
|
||||||
|
.bzr/
|
||||||
|
.bzrignore
|
||||||
|
.hg/
|
||||||
|
.hgignore
|
||||||
|
.svn/
|
||||||
|
# Common backup files
|
||||||
|
*.swp
|
||||||
|
*.bak
|
||||||
|
*.tmp
|
||||||
|
*.orig
|
||||||
|
*~
|
||||||
|
# Various IDEs
|
||||||
|
.project
|
||||||
|
.idea/
|
||||||
|
*.tmproj
|
||||||
|
.vscode/
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
apiVersion: v2
|
||||||
|
name: maestro
|
||||||
|
description: A Helm chart for Kubernetes
|
||||||
|
|
||||||
|
# A chart can be either an 'application' or a 'library' chart.
|
||||||
|
#
|
||||||
|
# Application charts are a collection of templates that can be packaged into versioned archives
|
||||||
|
# to be deployed.
|
||||||
|
#
|
||||||
|
# Library charts provide useful utilities or functions for the chart developer. They're included as
|
||||||
|
# a dependency of application charts to inject those utilities and functions into the rendering
|
||||||
|
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
|
||||||
|
type: application
|
||||||
|
|
||||||
|
# This is the chart version. This version number should be incremented each time you make changes
|
||||||
|
# to the chart and its templates, including the app version.
|
||||||
|
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
||||||
|
version: 0.1.0
|
||||||
|
|
||||||
|
# This is the version number of the application being deployed. This version number should be
|
||||||
|
# incremented each time you make changes to the application. Versions are not expected to
|
||||||
|
# follow Semantic Versioning. They should reflect the version the application is using.
|
||||||
|
# It is recommended to use it with quotes.
|
||||||
|
appVersion: "1.16.0"
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: maestro
|
||||||
|
namespace: applications
|
||||||
|
labels:
|
||||||
|
app: maestro
|
||||||
|
|
||||||
|
spec:
|
||||||
|
replicas: {{ .Values.replicaCount }}
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: maestro
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
rollingUpdate:
|
||||||
|
maxSurge: 25%
|
||||||
|
maxUnavailable: 25%
|
||||||
|
type: RollingUpdate
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: maestro
|
||||||
|
|
||||||
|
spec:
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: {{ .Values.imagePullSecrets }}
|
||||||
|
nodeSelector:
|
||||||
|
"beta.kubernetes.io/os": linux
|
||||||
|
affinity:
|
||||||
|
nodeAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
nodeSelectorTerms:
|
||||||
|
- matchExpressions:
|
||||||
|
- key: application
|
||||||
|
operator: In
|
||||||
|
values:
|
||||||
|
- backend
|
||||||
|
tolerations:
|
||||||
|
- key: "kubernetes.azure.com/scalesetpriority"
|
||||||
|
operator: "Equal"
|
||||||
|
value: "spot"
|
||||||
|
effect: "NoSchedule"
|
||||||
|
|
||||||
|
containers:
|
||||||
|
- name: maestro
|
||||||
|
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
|
||||||
|
ports:
|
||||||
|
- containerPort: {{ .Values.containerPort }}
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: {{ .Values.resources.requests.cpu }}
|
||||||
|
memory: {{ .Values.resources.requests.memory }}
|
||||||
|
limits:
|
||||||
|
cpu: {{ .Values.resources.limits.cpu }}
|
||||||
|
memory: {{ .Values.resources.limits.memory }}
|
||||||
|
env:
|
||||||
|
- name: AWS_IDENTITY_POOL_ID
|
||||||
|
value: {{ .Values.maestro.aws_identity_pool_id }}
|
||||||
|
- name: AWS_REGION
|
||||||
|
value: "us-east-1"
|
||||||
|
- name: BASE_HOST
|
||||||
|
value: "maestro_prd"
|
||||||
|
- name: BUCKET_CUSTOMER_CSV_ASSETS
|
||||||
|
value: {{ .Values.maestro.bucket_customer_csv_assets }}
|
||||||
|
- name: CONNECTORS_INDEX
|
||||||
|
value: "connectors"
|
||||||
|
- name: DUC_URL
|
||||||
|
value: {{ .Values.maestro.duc_url }}
|
||||||
|
- name: ELASTIC_APM_ENVIRONMENT
|
||||||
|
value: {{ .Values.maestro.env }}
|
||||||
|
- name: ELASTIC_APM_SERVER_URL
|
||||||
|
value: "https://apm-server.dadosfera.ai"
|
||||||
|
- name: ELASTIC_APM_SERVICE_NAME
|
||||||
|
value: {{ .Values.maestro.apm_service }}
|
||||||
|
- name: ENV
|
||||||
|
value: {{ .Values.maestro.env }}
|
||||||
|
- name: INFACTORY_URL
|
||||||
|
value: {{ .Values.maestro.in_factory_url }}
|
||||||
|
- name: LOGGER_GELF_HOST
|
||||||
|
value: "logstash-pipelines.dadosfera.ai"
|
||||||
|
- name: LOGGER_GELF_PORT
|
||||||
|
value: "{{ .Values.maestro.logger_gelf_port }}"
|
||||||
|
- name: NIMBUS_BASE_URL
|
||||||
|
value: "http://nimbus-api"
|
||||||
|
- name: NPM_TOKEN
|
||||||
|
value: {{ .Values.maestro.npm_token }}
|
||||||
|
- name: PB_TOKEN_PATH
|
||||||
|
value: {{ .Values.maestro.pb_token_path }}
|
||||||
|
- name: PIFACTORY_URL
|
||||||
|
value: {{ .Values.maestro.pi_factory_url }}
|
||||||
|
- name: SM_OAUTH_PATH
|
||||||
|
value: {{ .Values.maestro.sm_oauth_path }}
|
||||||
|
- name: TRFACTORY_URL
|
||||||
|
value: {{ .Values.maestro.tr_factory_url }}
|
||||||
|
- name: UPLOAD_FILE_AGENT_CONNECTION
|
||||||
|
value: {{ .Values.maestro.upload_file_agent_connection }}
|
||||||
|
- name: JWT_PRIVATE_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: prd-duc
|
||||||
|
key: jwt_token
|
||||||
|
- name: AWS_ACCESS_KEY_ID
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: prd-maestro
|
||||||
|
key: AWS_ACCESS_KEY_ID
|
||||||
|
- name: AWS_SECRET_ACCESS_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: prd-maestro
|
||||||
|
key: AWS_SECRET_ACCESS_KEY
|
||||||
|
- name: AWS_DEFAULT_REGION
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: prd-maestro
|
||||||
|
key: AWS_DEFAULT_REGION
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
nginx.ingress.kubernetes.io/proxy-body-size: "0"
|
||||||
|
nginx.ingress.kubernetes.io/server-snippet: |
|
||||||
|
underscores_in_headers on;
|
||||||
|
ignore_invalid_headers on;
|
||||||
|
|
||||||
|
generation: 1
|
||||||
|
labels:
|
||||||
|
app: maestro
|
||||||
|
name: maestro
|
||||||
|
namespace: applications
|
||||||
|
spec:
|
||||||
|
ingressClassName: nginx
|
||||||
|
rules:
|
||||||
|
- host: {{ .Values.hostname }}
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- backend:
|
||||||
|
service:
|
||||||
|
name: maestro
|
||||||
|
port:
|
||||||
|
number: {{ .Values.ingress.port }}
|
||||||
|
path: /
|
||||||
|
pathType: Prefix
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
apiVersion: external-secrets.io/v1beta1
|
||||||
|
kind: ExternalSecret
|
||||||
|
metadata:
|
||||||
|
name: prd-maestro
|
||||||
|
namespace: applications
|
||||||
|
labels:
|
||||||
|
app: maestro
|
||||||
|
spec:
|
||||||
|
refreshInterval: 1h
|
||||||
|
secretStoreRef:
|
||||||
|
name: secretsmanager-prd
|
||||||
|
kind: SecretStore
|
||||||
|
target:
|
||||||
|
name: prd-maestro
|
||||||
|
creationPolicy: Owner
|
||||||
|
data:
|
||||||
|
- secretKey: AWS_ACCESS_KEY_ID
|
||||||
|
remoteRef:
|
||||||
|
key: prd/microservices/aws_credentials/maestro
|
||||||
|
version: "AWSCURRENT"
|
||||||
|
property: AWS_ACCESS_KEY_ID
|
||||||
|
|
||||||
|
- secretKey: AWS_SECRET_ACCESS_KEY
|
||||||
|
remoteRef:
|
||||||
|
key: prd/microservices/aws_credentials/maestro
|
||||||
|
version: "AWSCURRENT"
|
||||||
|
property: AWS_SECRET_ACCESS_KEY
|
||||||
|
|
||||||
|
- secretKey: AWS_DEFAULT_REGION
|
||||||
|
remoteRef:
|
||||||
|
key: prd/microservices/aws_credentials/maestro
|
||||||
|
version: "AWSCURRENT"
|
||||||
|
property: AWS_DEFAULT_REGION
|
||||||
|
|
||||||
|
- secretKey: jwt_token
|
||||||
|
remoteRef:
|
||||||
|
key: {{ .Values.maestro.jwt_token_secret_id }}
|
||||||
|
version: "AWSCURRENT"
|
||||||
|
property: token
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: maestro
|
||||||
|
namespace: applications
|
||||||
|
labels:
|
||||||
|
app: maestro
|
||||||
|
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- name: maestro
|
||||||
|
protocol: TCP
|
||||||
|
port: {{ .Values.service.port }}
|
||||||
|
targetPort: {{ .Values.service.targetPort }}
|
||||||
|
selector:
|
||||||
|
app: maestro
|
||||||
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
# Default values for metabase.
|
||||||
|
# This is a YAML-formatted file.
|
||||||
|
# Declare variables to be passed into your templates.
|
||||||
|
|
||||||
|
replicaCount: 3
|
||||||
|
hostname: maestro-temp.dadosfera.ai
|
||||||
|
image:
|
||||||
|
repository: 611330257153.dkr.ecr.us-east-1.amazonaws.com/microservices/maestro_prd
|
||||||
|
pullPolicy: IfNotPresent
|
||||||
|
# Overrides the image tag whose default is the chart appVersion.
|
||||||
|
tag: 1.56.0
|
||||||
|
containerPort: 3333
|
||||||
|
imagePullSecrets: "applications-secrets-ecr-auth-token-external-secret"
|
||||||
|
service:
|
||||||
|
type: ClusterIP
|
||||||
|
port: 3333
|
||||||
|
targetPort: 3333
|
||||||
|
ingress:
|
||||||
|
enabled: false
|
||||||
|
port: 3333
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 1500Mi
|
||||||
|
limits:
|
||||||
|
cpu: 2000m
|
||||||
|
memory: 2Gi
|
||||||
|
maestro:
|
||||||
|
aws_identity_pool_id: "us-east-1_Mrezsw9Sn"
|
||||||
|
duc_url: duc.dadosfera.ai
|
||||||
|
in_factory_url: in-factory.dadosfera.ai
|
||||||
|
bucket_customer_csv_assets: "customers-csv-assets-prd-611330257153"
|
||||||
|
env: prd
|
||||||
|
apm_service: maestro
|
||||||
|
jwt_token_secret_id: prd/root/jwt_token
|
||||||
|
logger_gelf_port: "1026"
|
||||||
|
npm_token: npm_Xp17h3daMkORcZ55NY95Ez4gRfdzsQ3UvINP
|
||||||
|
pb_token_path: prd/root/productboard_token
|
||||||
|
pi_factory_url: pi-factory.dadosfera.ai
|
||||||
|
sm_oauth_path: prd/root/oauth_applications
|
||||||
|
tr_factory_url: in-factory.dadosfera.ai
|
||||||
|
upload_file_agent_connection: cbc2f881-58c4-4d60-8003-0979b0b5b911
|
||||||
|
open_customer_id: f239718a-a271-4ef9-ae7e-02a2f0f3aa6e
|
||||||
|
open_group_id: 401573bb-334f-44b2-b30e-88d4cea31ae9
|
||||||
|
autoscaling:
|
||||||
|
enabled: false
|
||||||
|
minReplicas: 1
|
||||||
|
maxReplicas: 100
|
||||||
|
targetCPUUtilizationPercentage: 80
|
||||||
|
targetMemoryUtilizationPercentage: 80
|
||||||
Generated
+10
-8
@@ -12,7 +12,7 @@
|
|||||||
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack": "2.5.3",
|
"@dadosfera/protospack": "2.5.3",
|
||||||
"@dadosfera/protospack-v2": "3.34.0",
|
"@dadosfera/protospack-v2": "3.37.0-beta.3",
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
"@grpc/proto-loader": "^0.7.9",
|
"@grpc/proto-loader": "^0.7.9",
|
||||||
"@nestjs/cli": "^9.5.0",
|
"@nestjs/cli": "^9.5.0",
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
"@types/jest": "27.0.2",
|
"@types/jest": "27.0.2",
|
||||||
"@types/jsonwebtoken": "^8.5.9",
|
"@types/jsonwebtoken": "^8.5.9",
|
||||||
"@types/jwk-to-pem": "^2.0.1",
|
"@types/jwk-to-pem": "^2.0.1",
|
||||||
"@types/multer": "^1.4.7",
|
"@types/multer": "^1.4.12",
|
||||||
"@types/node": "^16.18.52",
|
"@types/node": "^16.18.52",
|
||||||
"@types/passport-facebook": "^2.1.11",
|
"@types/passport-facebook": "^2.1.11",
|
||||||
"@types/passport-google-oauth20": "^2.0.11",
|
"@types/passport-google-oauth20": "^2.0.11",
|
||||||
@@ -1403,9 +1403,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@dadosfera/protospack-v2": {
|
"node_modules/@dadosfera/protospack-v2": {
|
||||||
"version": "3.34.0",
|
"version": "3.37.0-beta.3",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.34.0.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.37.0-beta.3.tgz",
|
||||||
"integrity": "sha512-VUjpoHg5/uNNkg1cTxWbUv+20t5CTAf1tB4dhBmGSYjgb+Efo5gi3aO/p3ajYuzOOMOxF+EhjQVouU6BD3E+Xg==",
|
"integrity": "sha512-9YSgzkXVqe9QsBxJjfxYxttAiyCXxgq49Xjs3OvnTLCXRDn3XtTlPaC+yHrTEUgCkQyhlDZuswe6f6oBImqIRQ==",
|
||||||
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
"rxjs": "^7.5.5"
|
"rxjs": "^7.5.5"
|
||||||
@@ -3526,10 +3527,11 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/multer": {
|
"node_modules/@types/multer": {
|
||||||
"version": "1.4.11",
|
"version": "1.4.12",
|
||||||
"resolved": "https://registry.npmjs.org/@types/multer/-/multer-1.4.11.tgz",
|
"resolved": "https://registry.npmjs.org/@types/multer/-/multer-1.4.12.tgz",
|
||||||
"integrity": "sha512-svK240gr6LVWvv3YGyhLlA+6LRRWA4mnGIU7RcNmgjBYFl6665wcXrRfxGp5tEPVHUNm5FMcmq7too9bxCwX/w==",
|
"integrity": "sha512-pQ2hoqvXiJt2FP9WQVLPRO+AmiIm/ZYkavPlIQnx282u4ZrVdztx0pkh3jjpQt0Kz+YI0YhSG264y08UJKoUQg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/express": "*"
|
"@types/express": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -30,7 +30,7 @@
|
|||||||
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack": "2.5.3",
|
"@dadosfera/protospack": "2.5.3",
|
||||||
"@dadosfera/protospack-v2": "3.34.0",
|
"@dadosfera/protospack-v2": "3.37.0-beta.3",
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
"@grpc/proto-loader": "^0.7.9",
|
"@grpc/proto-loader": "^0.7.9",
|
||||||
"@nestjs/cli": "^9.5.0",
|
"@nestjs/cli": "^9.5.0",
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
"@types/jest": "27.0.2",
|
"@types/jest": "27.0.2",
|
||||||
"@types/jsonwebtoken": "^8.5.9",
|
"@types/jsonwebtoken": "^8.5.9",
|
||||||
"@types/jwk-to-pem": "^2.0.1",
|
"@types/jwk-to-pem": "^2.0.1",
|
||||||
"@types/multer": "^1.4.7",
|
"@types/multer": "^1.4.12",
|
||||||
"@types/node": "^16.18.52",
|
"@types/node": "^16.18.52",
|
||||||
"@types/passport-facebook": "^2.1.11",
|
"@types/passport-facebook": "^2.1.11",
|
||||||
"@types/passport-google-oauth20": "^2.0.11",
|
"@types/passport-google-oauth20": "^2.0.11",
|
||||||
|
|||||||
+5
-2
@@ -26,9 +26,10 @@ import { PipelinesV2Module } from './modules/pipelinesV2/pipelines.module';
|
|||||||
import { ProductboardModule } from './modules/productboard/productboard.module';
|
import { ProductboardModule } from './modules/productboard/productboard.module';
|
||||||
import { MixpanelModule } from './modules/mixpanel/mixpanel.module';
|
import { MixpanelModule } from './modules/mixpanel/mixpanel.module';
|
||||||
import { CustomersModule } from './modules/customers/customers.module';
|
import { CustomersModule } from './modules/customers/customers.module';
|
||||||
|
import { OpenDataModule } from './modules/open-data/open-data.module';
|
||||||
|
import { ThemeModule } from './modules/theme/theme.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
controllers: [],
|
|
||||||
providers: [
|
providers: [
|
||||||
DadosferaLogger,
|
DadosferaLogger,
|
||||||
{
|
{
|
||||||
@@ -58,8 +59,10 @@ import { CustomersModule } from './modules/customers/customers.module';
|
|||||||
ProductboardModule,
|
ProductboardModule,
|
||||||
MixpanelModule,
|
MixpanelModule,
|
||||||
CustomersModule,
|
CustomersModule,
|
||||||
|
OpenDataModule,
|
||||||
|
ThemeModule,
|
||||||
//Always leave HealthModule last, so it is on the bottom of swagger
|
//Always leave HealthModule last, so it is on the bottom of swagger
|
||||||
HealthModule,
|
HealthModule
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { Injectable, CanActivate, ExecutionContext, ForbiddenException } from '@nestjs/common';
|
||||||
|
import { Reflector } from '@nestjs/core';
|
||||||
|
import { SetMetadata } from '@nestjs/common';
|
||||||
|
|
||||||
|
export const SetOrigin = (origin: string) => SetMetadata('allowedOrigin', origin);
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CORSGuard implements CanActivate {
|
||||||
|
constructor(private reflector: Reflector) {}
|
||||||
|
|
||||||
|
canActivate(context: ExecutionContext): boolean {
|
||||||
|
const response = context.switchToHttp().getResponse();
|
||||||
|
const request = context.switchToHttp().getRequest();
|
||||||
|
const origin = request.headers.origin;
|
||||||
|
|
||||||
|
// Obter a origem permitida através do decorador
|
||||||
|
const allowedOrigin = this.reflector.get<string>('allowedOrigin', context.getHandler());
|
||||||
|
if (process.env.ENV === "local") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verifica se a origem da requisição é permitida
|
||||||
|
if (allowedOrigin && origin !== allowedOrigin) {
|
||||||
|
throw new ForbiddenException('Acesso não permitido pela política CORS');
|
||||||
|
}
|
||||||
|
|
||||||
|
response.setHeader('Access-Control-Allow-Origin', allowedOrigin);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { IdResponse } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
|
||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
@@ -18,7 +17,6 @@ import {
|
|||||||
Authenticated,
|
Authenticated,
|
||||||
RequireAllPermissions,
|
RequireAllPermissions,
|
||||||
} from 'src/decorators/authentication.decorator';
|
} from 'src/decorators/authentication.decorator';
|
||||||
import { ApiInternalOnlyEndpoint } from 'src/decorators/swagger.decorator';
|
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
import { CustomersService } from './customers.service';
|
import { CustomersService } from './customers.service';
|
||||||
import { CustomerLinkRequest, CustomerLinksResponse } from './dtos/customers';
|
import { CustomerLinkRequest, CustomerLinksResponse } from './dtos/customers';
|
||||||
@@ -28,7 +26,6 @@ import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
|||||||
|
|
||||||
@ApiTags('Customers')
|
@ApiTags('Customers')
|
||||||
@Controller('customers')
|
@Controller('customers')
|
||||||
@Authenticated()
|
|
||||||
@UseFilters(GrpcToHttpExceptionFilter)
|
@UseFilters(GrpcToHttpExceptionFilter)
|
||||||
export class CustomersController {
|
export class CustomersController {
|
||||||
logger: DadosferaLogger;
|
logger: DadosferaLogger;
|
||||||
@@ -42,6 +39,7 @@ export class CustomersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id/links')
|
@Get(':id/links')
|
||||||
|
@Authenticated()
|
||||||
@ApiOkResponse({ type: CustomerLinksResponse })
|
@ApiOkResponse({ type: CustomerLinksResponse })
|
||||||
async getCustomerLinks(@Param('id') id: string) {
|
async getCustomerLinks(@Param('id') id: string) {
|
||||||
this.logger.info('getCustomerLinks', { id });
|
this.logger.info('getCustomerLinks', { id });
|
||||||
@@ -50,6 +48,7 @@ export class CustomersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id/links')
|
@Put(':id/links')
|
||||||
|
@Authenticated()
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
@ApiOkResponse()
|
@ApiOkResponse()
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
@@ -63,6 +62,7 @@ export class CustomersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('token')
|
@Get('token')
|
||||||
|
@Authenticated()
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.AUTH.permissions.GENERATE_TOKEN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.AUTH.permissions.GENERATE_TOKEN)
|
||||||
@ApiProduces('text/plain')
|
@ApiProduces('text/plain')
|
||||||
async getCustomerToken(
|
async getCustomerToken(
|
||||||
@@ -79,6 +79,7 @@ export class CustomersController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get('monitoring-dashboard')
|
@Get('monitoring-dashboard')
|
||||||
|
@Authenticated()
|
||||||
@RequireAllPermissions(
|
@RequireAllPermissions(
|
||||||
PERMISSIONS_GROUPS.CUSTOMER.permissions.MONITORING_DASHBOARD,
|
PERMISSIONS_GROUPS.CUSTOMER.permissions.MONITORING_DASHBOARD,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -28,19 +28,24 @@ import {
|
|||||||
} from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
} from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
import { PipelinesClientConfiguration } from '../pipelinesV2/pipelines-client';
|
import { PipelinesClientConfiguration } from '../pipelinesV2/pipelines-client';
|
||||||
|
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
||||||
|
|
||||||
// This function will accept any string, which may result in a bug.
|
// This function will accept any string, which may result in a bug.
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CustomersService implements OnModuleInit {
|
export class CustomersService implements OnModuleInit {
|
||||||
private customerService: CustomersProtoService;
|
private customerService: CustomersProtoService;
|
||||||
|
private logger: DadosferaLogger;
|
||||||
private pipelineReadService: ReadService.PipelineV2ReadService;
|
private pipelineReadService: ReadService.PipelineV2ReadService;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DucClient.name) private readonly grpcClient: ClientGrpc,
|
@Inject(DucClient.name) private readonly grpcClient: ClientGrpc,
|
||||||
@Inject(PipelinesClientConfiguration.name)
|
@Inject(PipelinesClientConfiguration.name)
|
||||||
private readonly pipelinesGrpcClient: ClientGrpc,
|
private readonly pipelinesGrpcClient: ClientGrpc,
|
||||||
) {}
|
@Inject(DadosferaLogger)
|
||||||
|
dadosferaLogger: DadosferaLogger,
|
||||||
|
) {
|
||||||
|
this.logger = dadosferaLogger.logger;
|
||||||
|
}
|
||||||
|
|
||||||
onModuleInit() {
|
onModuleInit() {
|
||||||
this.customerService = this.grpcClient.getService<CustomersProtoService>(
|
this.customerService = this.grpcClient.getService<CustomersProtoService>(
|
||||||
|
|||||||
@@ -20,3 +20,4 @@ export class CustomerLinksResponse {
|
|||||||
@ApiProperty({ type: [CustomerLink] })
|
@ApiProperty({ type: [CustomerLink] })
|
||||||
links: CustomerLink[];
|
links: CustomerLink[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ export class DucClient {
|
|||||||
objects: true,
|
objects: true,
|
||||||
arrays: true,
|
arrays: true,
|
||||||
},
|
},
|
||||||
|
maxSendMessageLength: 15 * 1024 * 1024, // 15 MB por mensagem
|
||||||
|
maxReceiveMessageLength: 15 * 1024 * 1024,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { ApiProperty } from "@nestjs/swagger";
|
||||||
|
|
||||||
|
export class CreateUserOpenDataDTO {
|
||||||
|
@ApiProperty()
|
||||||
|
firstName: string;
|
||||||
|
@ApiProperty()
|
||||||
|
lastName: string;
|
||||||
|
@ApiProperty()
|
||||||
|
email: string;
|
||||||
|
@ApiProperty()
|
||||||
|
organization: string;
|
||||||
|
@ApiProperty()
|
||||||
|
enquiryType: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type FormField = {
|
||||||
|
id: string;
|
||||||
|
type: string;
|
||||||
|
title: string;
|
||||||
|
value: string;
|
||||||
|
raw_value: string;
|
||||||
|
required: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type MetaData = {
|
||||||
|
title: string;
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type WordpressForm = {
|
||||||
|
form: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
fields: {
|
||||||
|
[key: string]: FormField;
|
||||||
|
};
|
||||||
|
meta: {
|
||||||
|
date: MetaData;
|
||||||
|
time: MetaData;
|
||||||
|
page_url: MetaData;
|
||||||
|
user_agent: MetaData;
|
||||||
|
remote_ip: MetaData;
|
||||||
|
credit: MetaData;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
||||||
|
import { Body, Controller, Header, HttpCode, Inject, Param, Post, Query, Req, UseFilters, UseGuards } from '@nestjs/common';
|
||||||
|
import { ApiCreatedResponse, ApiHeaders, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
||||||
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
|
import { LanguageEnum } from 'src/utils/languages.enum';
|
||||||
|
import { UsersService } from '../users/users.service';
|
||||||
|
import { Language } from 'src/decorators/language.decorator';
|
||||||
|
import { OpenDataService } from './open-data.service';
|
||||||
|
import { CreateUserOpenDataDTO, WordpressForm } from './dto/wordpres-form';
|
||||||
|
import { CORSGuard, SetOrigin } from 'src/decorators/set-origin.decorator';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
|
import { request } from 'http';
|
||||||
|
import { Request } from 'express';
|
||||||
|
|
||||||
|
@Controller('open-data')
|
||||||
|
@ApiInternalOnlyController()
|
||||||
|
@ApiTags('OpenData')
|
||||||
|
@ApiHeaders([{ name: 'dadosfera-lang', enum: LanguageEnum, required: false }])
|
||||||
|
@UseFilters(GrpcToHttpExceptionFilter)
|
||||||
|
export class OpenDataController {
|
||||||
|
logger: DadosferaLogger;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@Inject(DadosferaLogger)
|
||||||
|
dadosferaLogger: DadosferaLogger,
|
||||||
|
private openDataService: OpenDataService,
|
||||||
|
) {
|
||||||
|
this.logger = dadosferaLogger.logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post("/sharing-ocean-data")
|
||||||
|
// @SetOrigin('devsbm.dadosfera.io')
|
||||||
|
// @UseGuards(CORSGuard)
|
||||||
|
@HttpCode(200)
|
||||||
|
@Header('content-type', 'application/json')
|
||||||
|
@ApiOkResponse()
|
||||||
|
async createUser(
|
||||||
|
@Body()
|
||||||
|
body: WordpressForm,
|
||||||
|
@Query('language')
|
||||||
|
language: string,
|
||||||
|
@Req()
|
||||||
|
request: Request,
|
||||||
|
) {
|
||||||
|
this.logger.info('createUser for open data'
|
||||||
|
+ JSON.stringify({
|
||||||
|
origin: request.headers.origin,
|
||||||
|
language,
|
||||||
|
body
|
||||||
|
}));
|
||||||
|
|
||||||
|
// "401573bb-334f-44b2-b30e-88d4cea31ae9"
|
||||||
|
// const OPENDATA_PUBLIC_USERS_GROUP_ID = process.env.OPEN_GROUP_ID;
|
||||||
|
// ""f239718a-a271-4ef9-ae7e-02a2f0f3aa6e""
|
||||||
|
// const OPENDATA_CUSTOMER_ID = process.env.OPEN_CUSTOMER_ID;
|
||||||
|
const OPENDATA_CUSTOMER_ID = "b3e3dfe5-b992-4586-a73c-c0b0c00f615d";
|
||||||
|
|
||||||
|
this.logger.info("OPENDATA_CUSTOMER_ID: " + process.env.OPEN_CUSTOMER_ID)
|
||||||
|
this.logger.info("OPEN_GROUP_ID: " + process.env.OPEN_GROUP_ID)
|
||||||
|
const roles = ["e3f98a2f-7748-4981-8505-7695c8ca8218"];
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
language: language || 'en-us'
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Object.keys(body.fields)
|
||||||
|
.filter(key => body.fields[key].required === "1")
|
||||||
|
.forEach(key => {
|
||||||
|
const field = body.fields[key]
|
||||||
|
data[field.id] = field.value
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.error('user data ' + e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const user: CreateUserOpenDataDTO = {
|
||||||
|
email: data["email"],
|
||||||
|
enquiryType: data["enquiry_type"],
|
||||||
|
firstName: data["first_name"],
|
||||||
|
lastName: data["last_name"],
|
||||||
|
organization: data["organization"]
|
||||||
|
}
|
||||||
|
this.logger.info('user request' + JSON.stringify({ user, roles, customer: OPENDATA_CUSTOMER_ID }));
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles, metadata);
|
||||||
|
this.logger.info('user created with sucessfull data');
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
status: 'success',
|
||||||
|
message: 'user created with succesfull'
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.error('failed with exception: ' + e.message);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
status: 'failed',
|
||||||
|
message: e.message
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { OpenDataController } from './open-data.controller';
|
||||||
|
import { UsersService } from '../users/users.service';
|
||||||
|
import { ClientsModule } from '@nestjs/microservices'
|
||||||
|
import { DucClient } from '../duc/client.config';
|
||||||
|
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
||||||
|
import { RolesModule } from '../roles/roles.module';
|
||||||
|
import { PermissionsModule } from '../permissions/permissions.module';
|
||||||
|
import { OpenDataService } from './open-data.service';
|
||||||
|
|
||||||
|
const client = new DucClient();
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [OpenDataController],
|
||||||
|
imports: [
|
||||||
|
ClientsModule.register([client.providerOptions]),
|
||||||
|
RolesModule,
|
||||||
|
// PermissionsModule,
|
||||||
|
],
|
||||||
|
providers: [DadosferaLogger, UsersService, OpenDataService]
|
||||||
|
})
|
||||||
|
export class OpenDataModule {}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
|
||||||
|
import { lastValueFrom } from 'rxjs';
|
||||||
|
import { CreateUserOpenDataDTO } from './dto/wordpres-form';
|
||||||
|
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
||||||
|
import { UsersProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
||||||
|
import { DucClient } from '../duc/client.config';
|
||||||
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
|
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class OpenDataService implements OnModuleInit {
|
||||||
|
logger: DadosferaLogger;
|
||||||
|
|
||||||
|
private usersClientService: UsersProtoService;
|
||||||
|
constructor(
|
||||||
|
@Inject(DadosferaLogger)
|
||||||
|
private dadosferaLogger: DadosferaLogger,
|
||||||
|
@Inject(DucClient.name)
|
||||||
|
private readonly grpcClient: ClientGrpc,
|
||||||
|
) {
|
||||||
|
this.logger = dadosferaLogger.logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
onModuleInit() {
|
||||||
|
this.usersClientService = this.grpcClient.getService(
|
||||||
|
ProtoServices.UsersProtoService,
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async createUser(customerId: string, data: CreateUserOpenDataDTO, roleIds: string[], metadata: Metadata) {
|
||||||
|
const body = {
|
||||||
|
email: data.email,
|
||||||
|
name: data.firstName + " " + data.lastName,
|
||||||
|
department: data.organization,
|
||||||
|
jobTitle: data.enquiryType,
|
||||||
|
customerId: customerId,
|
||||||
|
roleIds: roleIds
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await lastValueFrom(
|
||||||
|
this.usersClientService.SimpleUserCreate(body, metadata),
|
||||||
|
);
|
||||||
|
return "User created";
|
||||||
|
} catch(err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { Link, Theme } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities';
|
||||||
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
export class CustomerLink implements Link {
|
||||||
|
@ApiProperty()
|
||||||
|
href: string;
|
||||||
|
@ApiProperty()
|
||||||
|
name: string;
|
||||||
|
@ApiProperty()
|
||||||
|
description: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
iconSrc: string;
|
||||||
|
}
|
||||||
|
export class CustomerLinkRequest {
|
||||||
|
@ApiProperty({ type: [CustomerLink] })
|
||||||
|
links: CustomerLink[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CustomerLinksResponse {
|
||||||
|
@ApiProperty({ type: [CustomerLink] })
|
||||||
|
links: CustomerLink[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CustomerTheme implements Theme {
|
||||||
|
@ApiProperty()
|
||||||
|
backgroundColor: string;
|
||||||
|
@ApiProperty()
|
||||||
|
textColor: string;
|
||||||
|
@ApiProperty()
|
||||||
|
logoWhite: string;
|
||||||
|
@ApiProperty()
|
||||||
|
logoBlack: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CustomerThemeResponse {
|
||||||
|
@ApiProperty()
|
||||||
|
theme: CustomerTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CustomerThemeRequest {
|
||||||
|
@ApiProperty()
|
||||||
|
displayName: string;
|
||||||
|
@ApiProperty()
|
||||||
|
backgroundColor: string;
|
||||||
|
@ApiProperty()
|
||||||
|
textColor: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
Inject,
|
||||||
|
Param,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Query,
|
||||||
|
UploadedFiles,
|
||||||
|
UseFilters,
|
||||||
|
UseInterceptors,
|
||||||
|
HttpCode
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
|
import {
|
||||||
|
Authenticated,
|
||||||
|
RequireAllPermissions,
|
||||||
|
} from 'src/decorators/authentication.decorator';
|
||||||
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
|
import { CustomerThemeRequest, CustomerThemeResponse } from './dtos/customers';
|
||||||
|
|
||||||
|
import ErrorCodes from 'src/utils/errorCodes';
|
||||||
|
import { AnyFilesInterceptor } from '@nestjs/platform-express';
|
||||||
|
import { ThemeService } from './theme.service';
|
||||||
|
|
||||||
|
@ApiTags('Theme')
|
||||||
|
@Controller('customers')
|
||||||
|
@UseFilters(GrpcToHttpExceptionFilter)
|
||||||
|
export class ThemeController {
|
||||||
|
logger: DadosferaLogger;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@Inject(DadosferaLogger)
|
||||||
|
dadosferaLogger: DadosferaLogger,
|
||||||
|
private themeService: ThemeService,
|
||||||
|
) {
|
||||||
|
this.logger = dadosferaLogger.logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Post('/:id/theme')
|
||||||
|
@Authenticated()
|
||||||
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
|
@ApiOkResponse({ type: CustomerThemeResponse })
|
||||||
|
@UseInterceptors(AnyFilesInterceptor())
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
async saveCustomertheme(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@Body() data: CustomerThemeRequest,
|
||||||
|
@UploadedFiles() files: Array<Express.Multer.File>
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.logger.info('saveCustomertheme' + JSON.stringify({
|
||||||
|
id,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const logoWhite = files.find(file => file.fieldname === 'logoWhite');
|
||||||
|
const logoBlack = files.find(file => file.fieldname === 'logoBlack');
|
||||||
|
|
||||||
|
this.validFileSize(logoWhite);
|
||||||
|
this.validFileSize(logoBlack);
|
||||||
|
this.validMimeType(logoWhite);
|
||||||
|
this.validMimeType(logoBlack);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const theme = await this.themeService.createThemeByCustomer(id, {
|
||||||
|
...data,
|
||||||
|
logoWhite,
|
||||||
|
logoBlack
|
||||||
|
});
|
||||||
|
this.logger.info('saveCustomertheme' + JSON.stringify(theme));
|
||||||
|
return { theme: theme };
|
||||||
|
} catch (err) {
|
||||||
|
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
||||||
|
this.logger.error('Error - saveCustomertheme - Expect CUSTOMER.NOT_FOUND');
|
||||||
|
throw new HttpException(err.details, HttpStatus.NOT_FOUND);
|
||||||
|
} else {
|
||||||
|
this.logger.error('Error - saveCustomertheme Unknown Error:' + err?.message);
|
||||||
|
return { theme: null };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private validFileSize(file: Express.Multer.File) {
|
||||||
|
const maxFileSize = 10 * 1024 * 1024; // 10MB
|
||||||
|
|
||||||
|
if (file && file.size > maxFileSize) {
|
||||||
|
throw new HttpException(`O Arquivo ${file.filename} possui mais de 10MB`, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private validMimeType(file: Express.Multer.File) {
|
||||||
|
const mimeTypesValid = ['image/jpeg', 'image/jpg', 'image/png'];
|
||||||
|
|
||||||
|
if (file && !mimeTypesValid.includes(file.mimetype)) {
|
||||||
|
throw new HttpException(`O Arquivo ${file.fieldname} deve ser jpeg, jpg ou png`, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('/:id/theme')
|
||||||
|
@ApiOkResponse({ type: CustomerThemeResponse })
|
||||||
|
async getCustomerTheme(@Param('id') id: string) {
|
||||||
|
this.logger.info('getCustomerTheme with id' + id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await this.themeService.getThemeByCustomer(id);
|
||||||
|
this.logger.info('Success - getCustomerTheme with id'+ id);
|
||||||
|
return data;
|
||||||
|
}catch (err) {
|
||||||
|
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
||||||
|
this.logger.error('Error - getCustomerTheme - Expect CUSTOMER.NOT_FOUND');
|
||||||
|
throw new HttpException(err.details, HttpStatus.NOT_FOUND);
|
||||||
|
} else {
|
||||||
|
this.logger.error('Error - getCustomerTheme Unknown Error:' + err?.message);
|
||||||
|
return { theme: null };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
import { ClientsModule } from '@nestjs/microservices';
|
||||||
|
import { ThemeController } from './theme.controller';
|
||||||
|
import { ThemeService } from './theme.service';
|
||||||
|
import { DucClient } from '../duc/client.config';
|
||||||
|
|
||||||
|
const ducClient = new DucClient();
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ClientsModule.register([
|
||||||
|
ducClient.providerOptions,
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
controllers: [ThemeController],
|
||||||
|
providers: [ThemeService, DadosferaLogger],
|
||||||
|
exports: [ThemeService],
|
||||||
|
})
|
||||||
|
export class ThemeModule {}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
import {
|
||||||
|
OnModuleInit,
|
||||||
|
Inject,
|
||||||
|
Injectable,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
InternalServerErrorException,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
|
||||||
|
import { firstValueFrom, lastValueFrom, ReplaySubject } from 'rxjs';
|
||||||
|
import { Link } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities';
|
||||||
|
import { DucClient } from '../duc/client.config';
|
||||||
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
|
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
||||||
|
import { CustomerUpdateRequest } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||||
|
import { ThemeProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
||||||
|
import { ThemeRequest } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||||
|
import { CustomerThemeRequest, CustomerThemeResponse } from './dtos/customers';
|
||||||
|
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
import { Readable } from 'stream';
|
||||||
|
|
||||||
|
type Files = {
|
||||||
|
logoWhite: Express.Multer.File,
|
||||||
|
logoBlack: Express.Multer.File,
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function will accept any string, which may result in a bug.
|
||||||
|
@Injectable()
|
||||||
|
export class ThemeService implements OnModuleInit {
|
||||||
|
private themeService: ThemeProtoService;
|
||||||
|
private logger: DadosferaLogger;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@Inject(DucClient.name) private readonly grpcClient: ClientGrpc,
|
||||||
|
@Inject(DadosferaLogger)
|
||||||
|
dadosferaLogger: DadosferaLogger,
|
||||||
|
) {
|
||||||
|
this.logger = dadosferaLogger.logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
onModuleInit() {
|
||||||
|
this.themeService = this.grpcClient.getService<ThemeProtoService>(
|
||||||
|
ProtoServices.ThemeProtoService,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createThemeByCustomer(id: string, theme: CustomerThemeRequest & Files) {
|
||||||
|
if (!id) {
|
||||||
|
this.logger.error('Error - saveCustomertheme - not found id:' + id);
|
||||||
|
throw new HttpException(null, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
const customerThemeRequest$ = new ReplaySubject<ThemeRequest>();
|
||||||
|
|
||||||
|
customerThemeRequest$.next({
|
||||||
|
customerId: id,
|
||||||
|
displayName: theme.displayName,
|
||||||
|
backgroundColor: theme.backgroundColor,
|
||||||
|
textColor: theme.textColor,
|
||||||
|
isMetadata: true,
|
||||||
|
filename: '',
|
||||||
|
chunk: Buffer.alloc(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
if(theme.logoBlack) {
|
||||||
|
await this.sendFile(theme.logoBlack, customerThemeRequest$);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(theme.logoWhite) {
|
||||||
|
await this.sendFile(theme.logoWhite, customerThemeRequest$);
|
||||||
|
}
|
||||||
|
customerThemeRequest$.complete();
|
||||||
|
|
||||||
|
const stream = this.themeService.CustomerCreateTheme(customerThemeRequest$);
|
||||||
|
|
||||||
|
return lastValueFrom(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getThemeByCustomer(id: string): Promise<CustomerThemeResponse> {
|
||||||
|
if (!id) {
|
||||||
|
this.logger.error('Error - getCustomerTheme - not found id:' + id);
|
||||||
|
throw new HttpException(null, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { theme } = await firstValueFrom(
|
||||||
|
this.themeService.CustomerGetTheme({
|
||||||
|
id
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
theme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async sendFile(file: Express.Multer.File, stream$: ReplaySubject<ThemeRequest>) {
|
||||||
|
const bufferStream = new Readable({
|
||||||
|
highWaterMark: 1024 * 1024, // 1 MB por chunk
|
||||||
|
read() {}
|
||||||
|
});
|
||||||
|
bufferStream.push(file.buffer);
|
||||||
|
bufferStream.push(null);
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
bufferStream.on('data', (chunk) => {
|
||||||
|
console.log('enviando chunk', file.fieldname)
|
||||||
|
const mimetype = file.mimetype.split('/')[1]; // example image/jpeg
|
||||||
|
const filename = file.fieldname.concat(".", mimetype);
|
||||||
|
stream$.next({
|
||||||
|
customerId: '',
|
||||||
|
displayName: '',
|
||||||
|
backgroundColor: '',
|
||||||
|
textColor: '',
|
||||||
|
isMetadata: false,
|
||||||
|
filename: filename,
|
||||||
|
chunk: chunk
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
bufferStream.on('end', () => {
|
||||||
|
console.log('terminou de enviar')
|
||||||
|
resolve(file.filename)
|
||||||
|
});
|
||||||
|
|
||||||
|
bufferStream.on('error', (err) => {
|
||||||
|
console.error('Erro no stream:', err);
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user