-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from BugBusterSWE/activity#2
Activity#2
- Loading branch information
Showing
42 changed files
with
4,495 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,12 @@ | |
"author": "BugBusters [email protected]", | ||
"license": "MIT", | ||
"dependencies": { | ||
"express": "^4.13.1" | ||
"express": "^4.13.1", | ||
"mongoose": "^4.4.14", | ||
"promise": "^7.1.1", | ||
"body-parser": "^1.15.1", | ||
"helmet": "^2.0.0" | ||
|
||
}, | ||
"devDependencies": { | ||
"apidoc": "^0.15.1", | ||
|
@@ -50,8 +55,8 @@ | |
"mocha": "^2.4.5", | ||
"rimraf": "^2.5.2", | ||
"tslint": "^3.5.0", | ||
"typedoc": "^0.3.12", | ||
"typedoc": "latest", | ||
"typescript": "^1.8.7", | ||
"typings": "^0.7.9" | ||
"typings": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "example", | ||
"name": "MaaS", | ||
"version": "0.1.0", | ||
"description": "apiDoc basic example", | ||
"title": "Custom apiDoc browser title", | ||
"url" : "https://api.github.com/v1" | ||
"description": "API for MaaS", | ||
"title": "MaaS: MongoDB as a Service API documentation", | ||
"url" : "http://bugbusterswe.github.io/MaaS/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import MongoConnection from "./mongoConnection"; | ||
|
||
/** | ||
* This is the base class for the configuration hierarchy. This class | ||
* contains some useful information about the configuration of the | ||
* environment. | ||
* @history | ||
* | Author | Action Performed | Data | | ||
* | --- | --- | --- | | ||
* | Matteo Di Pirro | Create class | 04/05/2016 | | ||
* | ||
* @author Matteo Di Pirro | ||
* @license MIT | ||
*/ | ||
abstract class Configuration { | ||
/** | ||
* @description String which represents the name of the environment. | ||
*/ | ||
private envName : string; | ||
|
||
/** | ||
* @description Parameters used for the connection with the MongoDB | ||
* database. | ||
*/ | ||
private mongoConnection : MongoConnection; | ||
|
||
/** | ||
* @description String which is used for the JWT token encryption. | ||
*/ | ||
private serverSecret : string; | ||
|
||
/** | ||
* @description Configuration constructor. | ||
* @param envName The name of the environment | ||
* @param connection The parameters of the MongoDB connection | ||
* @param serverSecret The string for the JWT token encryption. | ||
*/ | ||
constructor(envName : string, | ||
connection : MongoConnection, | ||
serverSecret : string) { | ||
this.envName = envName; | ||
this.mongoConnection = connection; | ||
this.serverSecret = serverSecret; | ||
} | ||
|
||
/** | ||
* @description Getter for the environment name | ||
* @returns {string} The environment name | ||
*/ | ||
public getEnvName() : string { | ||
return this.envName; | ||
} | ||
|
||
/** | ||
* @description Getter for the MongoDB connection's parameters | ||
* @returns {MongoConnection} The parameters of the MongoDB connection | ||
*/ | ||
public getMongoConnection() : MongoConnection { | ||
return this.mongoConnection; | ||
} | ||
|
||
/** | ||
* @description Getter for the JWT token encryption string | ||
* @returns {string} The the JWT token encryption string | ||
*/ | ||
public getServerSecret() : string { | ||
return this.serverSecret; | ||
} | ||
} | ||
|
||
export default Configuration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Configuration from "./configuration"; | ||
import MongoConnection from "./mongoConnection"; | ||
/** | ||
* Development configuration. | ||
* @history | ||
* | Author | Action Performed | Data | | ||
* | --- | --- | --- | | ||
* | Matteo Di Pirro | Create class | 04/05/2016 | | ||
* | ||
* @author Matteo Di Pirro | ||
* @license MIT | ||
*/ | ||
class DevConfiguration extends Configuration { | ||
/** | ||
* @description Complete constructor of the development configuration | ||
* @param connection The parameters for the connection to the database | ||
* @param serverSecret The JWT token's encryption string | ||
*/ | ||
constructor(connection : MongoConnection, serverSecret : string) { | ||
super("development", connection, serverSecret); | ||
} | ||
} | ||
|
||
export default DevConfiguration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import MongoConnection from "./mongoConnection"; | ||
import Configuration from "./configuration"; | ||
import DevConfiguration from "./devConfiguration"; | ||
import TestConfiguration from "./testConfiguration"; | ||
import ProdConfiguration from "./prodConfiguration"; | ||
import {readFileSync} from "fs"; | ||
|
||
/** | ||
* Class used for get the necessary configuration. | ||
* @history | ||
* | Author | Action Performed | Data | | ||
* | --- | --- | --- | | ||
* | Matteo Di Pirro | Create class | 04/05/2016 | | ||
* | ||
* @author Matteo Di Pirro | ||
* @license MIT | ||
*/ | ||
class ChooseConfiguration { | ||
|
||
/** | ||
* @description Return the right configuration according to the Node.js | ||
* environment variable. It may be: 'development', 'test' or 'production'. | ||
* The default configuration is the 'production' one. | ||
* The connection's parameters are read fro an external json file named | ||
* mongoParameters.json. | ||
* @returns {Configuration} The configuration. | ||
*/ | ||
public static getConfig() : Configuration { | ||
let params : MongoConnection = JSON.parse(readFileSync( | ||
"src/config/mongoParameters.json", | ||
"utf-8" | ||
)); | ||
let connection : MongoConnection = new MongoConnection( | ||
params["user"], | ||
params["password"], | ||
params["host"], | ||
params["port"], | ||
params["dbName"] | ||
); | ||
let serverSecret : string = "serverSecret"; | ||
let config : Configuration; | ||
|
||
// Export the right configurations according to the NODE_ENV variable | ||
switch (process.env.NODE_ENV) { | ||
case "development": | ||
config = new DevConfiguration(connection, serverSecret); | ||
break; | ||
case "test": | ||
config = new TestConfiguration(connection, serverSecret); | ||
break; | ||
case "production": | ||
config = new ProdConfiguration(connection, serverSecret); | ||
break; | ||
default: | ||
config = new ProdConfiguration(connection, serverSecret); | ||
break; | ||
} | ||
return config; | ||
} | ||
} | ||
|
||
export default ChooseConfiguration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* This class stores the parameters for the MondoDB connection. | ||
* @history | ||
* | Author | Action Performed | Data | | ||
* | --- | --- | --- | | ||
* | Matteo Di Pirro | Create class | 04/05/2016 | | ||
* | ||
* @author Matteo Di Pirro | ||
* @license MIT | ||
*/ | ||
class MongoConnection { | ||
/** | ||
* @description The username of the user used for read data from the | ||
* database. | ||
*/ | ||
private user : string; | ||
|
||
/** | ||
* @description The password of the user used for read data from the | ||
* database. | ||
*/ | ||
private password : string; | ||
|
||
/** | ||
* @description The host of the database. | ||
*/ | ||
private host : string; | ||
|
||
/** | ||
* @description The port of the database. | ||
*/ | ||
private port : number; | ||
|
||
/** | ||
* @description The name of the database. | ||
*/ | ||
private dbName : string; | ||
|
||
/** | ||
* @description Complete constructor | ||
* @param user Username of the user used for read data from the database | ||
* @param password Password of the user used for read data from the | ||
* database. | ||
* @param host Database's host. | ||
* @param port database's port. | ||
* @param db Database's name. | ||
*/ | ||
constructor(user : string, password : string, host : string, port : number, | ||
db : string) { | ||
this.user = user; | ||
this.password = password; | ||
this.host = host; | ||
this.port = port; | ||
this.dbName = db; | ||
} | ||
|
||
/** | ||
* @description Getter for the username of the user used for read data from | ||
* the database. | ||
* @returns {string} The username of the user used for read data from the | ||
* database. | ||
*/ | ||
public getUser() : string { | ||
return this.user; | ||
} | ||
|
||
/** | ||
* @description Getter for the password of the user used for read data from | ||
* the database. | ||
* @returns {string} The password of the user used for read data from the | ||
* database. | ||
*/ | ||
public getPassword() : string { | ||
return this.password; | ||
} | ||
|
||
/** | ||
* @description Getter for the database's host. | ||
* @returns {string} The host of the database. | ||
*/ | ||
public getHost() : string { | ||
return this.host; | ||
} | ||
|
||
/** | ||
* @description Getter for database's port. | ||
* @returns {string} The name of the database. | ||
*/ | ||
public getDatabasePort() : number { | ||
return this.port; | ||
} | ||
|
||
/** | ||
* @description Getter for database's name. | ||
* @returns {string} The name of the database. | ||
*/ | ||
public getDatabaseName() : string { | ||
return this.dbName; | ||
} | ||
} | ||
|
||
export default MongoConnection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"user" : "admin", | ||
"password" : "admin", | ||
"host" : "ds013250.mlab.com", | ||
"port" : 13250, | ||
"dbName" : "mongocbtest" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Configuration from "./configuration"; | ||
import MongoConnection from "./mongoConnection"; | ||
|
||
/** | ||
* Production configuration. | ||
* @history | ||
* | Author | Action Performed | Data | | ||
* | --- | --- | --- | | ||
* | Matteo Di Pirro | Create class | 04/05/2016 | | ||
* | ||
* @author Matteo Di Pirro | ||
* @license MIT | ||
*/ | ||
class ProdConfiguration extends Configuration { | ||
/** | ||
* @description Complete constructor of the development configuration | ||
* @param connection The parameters for the connection to the database | ||
* @param serverSecret The JWT token's encryption string | ||
*/ | ||
constructor(connection : MongoConnection, serverSecret : string) { | ||
super("production", connection, serverSecret); | ||
} | ||
} | ||
|
||
export default ProdConfiguration; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Configuration from "./configuration"; | ||
import MongoConnection from "./mongoConnection"; | ||
|
||
/** | ||
* @description Test configuration. | ||
* @history | ||
* | Author | Action Performed | Data | | ||
* | --- | --- | --- | | ||
* | Matteo Di Pirro | Create class | 04/05/2016 | | ||
* | ||
* @author Matteo Di Pirro | ||
* @license MIT | ||
*/ | ||
class TestConfiguration extends Configuration { | ||
/** | ||
* @description Complete constructor of the development configuration | ||
* @param connection The parameters for the connection to the database | ||
* @param serverSecret The JWT token's encryption string | ||
*/ | ||
constructor(connection : MongoConnection, serverSecret : string) { | ||
super("test", connection, serverSecret); | ||
} | ||
} | ||
|
||
export default TestConfiguration; |
Oops, something went wrong.