Skip to content

Commit

Permalink
Merge pull request #35 from Accenture/release/3.7
Browse files Browse the repository at this point in the history
Release/3.7
  • Loading branch information
sboudaya authored Sep 20, 2024
2 parents 0f9378d + c631875 commit e7c36b4
Show file tree
Hide file tree
Showing 51 changed files with 1,158 additions and 358 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: type=raw,value=3.6
tags: type=raw,value=3.7
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).


## Version 3.7 , 12/09/2024

### Added

- Added a new api to view application logs from swagger directly
- Added authentication for swagger
- Added a button to launch analysis from sonarqube
- Added configuration table to change param dynamically
- Encryption of password in database for new userflow

### Changed

- Updated ecocode plugins (except C#)
- Swagger.js : Documentation updated
---

## Version 3.6 , 04/06/2024

### Changed
Expand Down
21 changes: 21 additions & 0 deletions EcoSonar-API/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Then, the API can allow you to retrieve pre-formatted audit results using json f
- [CORS Setup](#cors)
- [Enable W3C validator Analysis](#w3c-validator)
- [Setup User flow](#user-flow)
- [Password encryption](#encryption)
- [Swagger Authentication](#authentication)
- [API: option 1 - Node.js](#nodejs)
- [Prerequisites](#prerequisites-node)
- [Installation](#installation-node)
Expand Down Expand Up @@ -222,7 +224,26 @@ If your projects require to set up a user flow to access some of your web pages,
```
ECOSONAR_ENV_USER_JOURNEY_ENABLED = `true`or `false`
```
<a name="encryption"></a>

### Setup User flow

The back end now requires additional settings for the ecryption of the passwords for the user-flow. However, if you do not add any settings for the password, it will still encrypt the password but with a default encryption key. Please note that the encryption Key must be 256 bits (32 characters) e.g xfn9P8L9rIpKtWKj68IZ3G865WfdYXNX

```
ENCRYPTION_KEY = `xfn9P8L9rIpKtWKj68IZ3G865WfdYXNX`
```

<a name="authentication"></a>

### Swagger Authentication

To set up the authentication settings for the swagger of ecosonar the following settings need to be added in the .env file.

```
ECOSONAR_USER_USERNAME = 'XXXXX'
ECOSONAR_USER_PASSWORD = 'XXXXX'
```

<a name="nodejs"></a>

Expand Down
15 changes: 8 additions & 7 deletions EcoSonar-API/configuration/database.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mongoose from 'mongoose'
import retrievePassword from './retrieveDatabasePasswordFromCloudProvider.js'
import loggerService from '../loggers/traces.js'

mongoose.set('strictQuery', false)

Expand All @@ -19,8 +20,8 @@ Database.prototype.connection = async function () {
dbName = process.env.ECOSONAR_ENV_DB_NAME || ''
connectionString = `mongodb://${cluster}:${port}/${dbName}`
mongoose.connect(connectionString)
.then(() => console.log('Connection to MongoDB successful'))
.catch((reason) => console.error('\x1b[31m%s\x1b[0m', 'Unable to connect to the mongodb instance. Error: ', reason))
.then(() => loggerService.info('Connection to MongoDB successful'))
.catch((reason) => loggerService.error('\x1b[31m%s\x1b[0m', 'Unable to connect to the mongodb instance. Error: ', reason))
} else if (mongoDBType === 'MongoDB_Atlas') {
// connection to dataBase MongoDB Atlas for MongoDB API
user = process.env.ECOSONAR_ENV_USER || ''
Expand All @@ -29,8 +30,8 @@ Database.prototype.connection = async function () {
dbName = process.env.ECOSONAR_ENV_DB_NAME || ''
connectionString = `mongodb+srv://${user}:${password}@${cluster}/${dbName}?retryWrites=true&w=majority`
mongoose.connect(connectionString)
.then(() => console.log('Connection to MongoDB Atlas successful'))
.catch((reason) => console.error('\x1b[31m%s\x1b[0m', 'Unable to connect to the mongodb instance. Error: ', reason))
.then(() => loggerService.info('Connection to MongoDB Atlas successful'))
.catch((reason) => loggerService.error('\x1b[31m%s\x1b[0m', 'Unable to connect to the mongodb instance. Error: ', reason))
} else if (mongoDBType === 'CosmosDB') {
// connection to dataBase Azure CosmosDB for MongoDB API
cluster = process.env.ECOSONAR_ENV_CLUSTER || ''
Expand All @@ -46,10 +47,10 @@ Database.prototype.connection = async function () {
},
retryWrites: false
})
.then(() => console.log('Connection to CosmosDB successful'))
.catch((err) => console.error('\x1b[31m%s\x1b[0m', err))
.then(() => loggerService.info('Connection to CosmosDB successful'))
.catch((err) => loggerService.error('\x1b[31m%s\x1b[0m', err))
} else {
console.log('Could not connect to any database')
loggerService.info('Could not connect to any database')
}
}

Expand Down
19 changes: 10 additions & 9 deletions EcoSonar-API/dataBase/bestPracticesRepository.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import bestpractices from './models/bestpractices.js'
import SystemError from '../utils/SystemError.js'
import loggerService from '../loggers/traces.js'

const BestPracticesRepository = function () {
/**
Expand All @@ -20,11 +21,11 @@ const BestPracticesRepository = function () {
resolve()
})
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
reject(new SystemError())
})
} else {
console.log('None of the urls analyzed could be inserted')
loggerService.info('None of the urls analyzed could be inserted')
reject(new Error('None of the urls analyzed could be inserted'))
}
})
Expand All @@ -38,11 +39,11 @@ const BestPracticesRepository = function () {
return new Promise((resolve, reject) => {
bestpractices.deleteMany({ idUrl: url[0].idKey })
.then((result) => {
console.log(`DELETE URL - On best practices ${result.deletedCount} objects removed`)
loggerService.info(`DELETE URL - On best practices ${result.deletedCount} objects removed`)
resolve()
})
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
reject(new SystemError())
})
})
Expand All @@ -60,7 +61,7 @@ const BestPracticesRepository = function () {
.sort({ dateAnalysisBestPractices: 1 })
.then((result) => resolve(result))
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
reject(new SystemError())
})
})
Expand All @@ -79,7 +80,7 @@ const BestPracticesRepository = function () {
.limit(1)
.then((result) => resolve(result))
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
reject(new SystemError())
})
})
Expand All @@ -93,11 +94,11 @@ const BestPracticesRepository = function () {
return new Promise((resolve, reject) => {
bestpractices.deleteMany({ idUrl: { $in: urlIdKeyList } })
.then((result) => {
console.log(`DELETE URLS PROJECT - On best practices ${result.deletedCount} objects removed`)
loggerService.info(`DELETE URLS PROJECT - On best practices ${result.deletedCount} objects removed`)
resolve()
})
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
reject(new SystemError())
})
})
Expand All @@ -118,7 +119,7 @@ function checkValues (arrayToInsert) {
if (analysis.bestPractices) {
arrayToInsertSanitized.push(analysis)
} else {
console.warn(`BEST PRACTICES INSERT - Best practices for url ${analysis.url} cannot be inserted due to presence of NaN or undefined values`)
loggerService.warn(`BEST PRACTICES INSERT - Best practices for url ${analysis.url} cannot be inserted due to presence of NaN or undefined values`)
}
}
return arrayToInsertSanitized
Expand Down
65 changes: 65 additions & 0 deletions EcoSonar-API/dataBase/configurationRepository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import configurations from './models/configurations.js'
import SystemError from '../utils/SystemError.js'
import loggerService from '../loggers/traces.js'

const ConfigurationRepository = function () {
/**
* add a new new configuration for a project
* @param {JSON} configuration the configuration to save
*/
this.insertConfiguration = function (idProject, W3C, carbon) {
return new Promise((resolve, reject) => {
configurations.create({ idProject, W3C, carbon })
.then(() => { resolve() })
.catch((error) => {
console.log(error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
if (error._message === 'configuration validation failed') {
reject(new Error(error.message))
}
reject(new SystemError())
})
})
}

/**
* update an existing configuration of a project
* @param {JSON} configuration the configuration to save
*/
this.updateConfiguration = async function (idProject, W3C, carbon) {
return new Promise((resolve, reject) => {
configurations.updateOne({ idProject, W3C, carbon })
.then(() => {
resolve()
})
.catch((error) => {
loggerService.error('\x1b[31m%s\x1b[0m', error)
if (error._message === 'configuration validation failed') {
reject(new Error(error.message))
}
reject(new SystemError())
})
})
}

/**
* find an existing configuration of a project
* @param {String} id of the project
*/
this.findConfiguration = async function (idProject) {
return new Promise((resolve, reject) => {
configurations.findOne({ idProject: { $eq: idProject } }, { W3C: 1, carbon: 1})
.then((result) => { resolve(result) })
.catch((error) => {
loggerService.error('\x1b[31m%s\x1b[0m', error)
if (error._message === 'configuration validation failed') {
reject(new Error(error.message))
}
reject(new SystemError())
})
})
}
}

const configurationRepository = new ConfigurationRepository()
export default configurationRepository
27 changes: 14 additions & 13 deletions EcoSonar-API/dataBase/greenItRepository.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import greenits from './models/greenits.js'
import urlsprojects from './models/urlsprojects.js'
import SystemError from '../utils/SystemError.js'
import loggerService from '../loggers/traces.js'

const GreenItRepository = function () {
/**
Expand All @@ -18,13 +19,13 @@ const GreenItRepository = function () {
resolve()
})
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
console.log('GREENIT - error during insertion of analysis')
loggerService.error('\x1b[31m%s\x1b[0m', error)
loggerService.info('GREENIT - error during insertion of analysis')
const systemError = new SystemError()
reject(systemError)
})
} else {
console.log('GREENIT - None of the urls analysed could be inserted')
loggerService.info('GREENIT - None of the urls analysed could be inserted')
reject(new Error('GREENIT - None of the urls analysed could be inserted'))
}
})
Expand All @@ -41,7 +42,7 @@ const GreenItRepository = function () {
resolve(res)
})
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
reject(new SystemError())
})
})
Expand All @@ -61,7 +62,7 @@ const GreenItRepository = function () {
resolve(result)
})
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
reject(new SystemError())
})
})
Expand All @@ -78,7 +79,7 @@ const GreenItRepository = function () {
.sort({ dateGreenAnalysis: 1 })
.then((result) => { resolve(result) })
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
reject(new SystemError())
})
})
Expand All @@ -95,7 +96,7 @@ const GreenItRepository = function () {
.sort({ dateGreenAnalysis: 1 })
.then((result) => { resolve(result) })
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
reject(new SystemError())
})
})
Expand All @@ -109,11 +110,11 @@ const GreenItRepository = function () {
return new Promise((resolve, reject) => {
greenits.deleteMany({ idUrlGreen: url[0].idKey })
.then((result) => {
console.log(`DELETE URL - On GreenIt ${result.deletedCount} objects removed`)
loggerService.info(`DELETE URL - On GreenIt ${result.deletedCount} objects removed`)
resolve()
})
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
reject(new SystemError())
})
})
Expand All @@ -127,11 +128,11 @@ const GreenItRepository = function () {
return new Promise((resolve, reject) => {
greenits.deleteMany({ idUrlGreen: { $in: urlIdKeyList } })
.then((result) => {
console.log(`DELETE URLS PROJECT - On GreenIt ${result.deletedCount} objects removed`)
loggerService.info(`DELETE URLS PROJECT - On GreenIt ${result.deletedCount} objects removed`)
resolve()
})
.catch((error) => {
console.error('\x1b[31m%s\x1b[0m', error)
loggerService.error('\x1b[31m%s\x1b[0m', error)
reject(new SystemError())
})
})
Expand All @@ -151,10 +152,10 @@ async function checkValues (arrayToInsert) {
} else {
await urlsprojects.find({ idKey: analysis.idUrlGreen })
.then((result) => {
console.warn(`GREENIT INSERT - Url ${result[0].urlName} cannot be inserted due to presence of NaN or undefined values`)
loggerService.warn(`GREENIT INSERT - Url ${result[0].urlName} cannot be inserted due to presence of NaN or undefined values`)
})
.catch((error) => {
console.error(error)
loggerService.error(error)
})
}
}
Expand Down
Loading

0 comments on commit e7c36b4

Please sign in to comment.