Skip to content

Commit

Permalink
load the proposalTypes.json using the existing functionality and add …
Browse files Browse the repository at this point in the history
…PROPOSAL_TYPES_FILE env variable
  • Loading branch information
martin-trajanovski committed Nov 18, 2024
1 parent 76117e9 commit 8752f52
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ ES_PASSWORD="duo-password"
ES_REFRESH=<"wait_for"|"false">

LOGGERS_CONFIG_FILE="loggers.json"
PROPOSAL_TYPES_FILE="proposalTypes.json"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Valid environment variables for the .env file. See [.env.example](/.env.example)
| `ES_FIELDS_LIMIT` | number | | The total number of fields in an index. | 1000 |
| `ES_REFRESH` | string | | If set to `wait_for`, Elasticsearch will wait till data is inserted into the specified index before returning a response. | false |
| `LOGGERS_CONFIG_FILE` | string | | The file name for loggers configuration, located in the project root directory. | "loggers.json" |
| `PROPOSAL_TYPES_FILE` | string | | The file name for proposal types configuration, located in the project root directory. | "proposalTypes.json" |
| `SWAGGER_PATH` | string | Yes | swaggerPath is the path where the swagger UI will be available| "explorer"|
| `MAX_FILE_UPLOAD_SIZE` | string | Yes | Maximum allowed file upload size | "16mb"|

Expand Down
28 changes: 8 additions & 20 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ const configuration = () => {
modulePath: "./loggingProviders/defaultLogger",
config: {},
};
const jsonConfigMap: { [key: string]: object[] | boolean } = {};
const jsonConfigMap: { [key: string]: object | object[] | boolean } = {
proposalTypes: {},
};
const jsonConfigFileList: { [key: string]: string } = {
loggers: process.env.LOGGERS_CONFIG_FILE || "loggers.json",
proposalTypes: process.env.PROPOSAL_TYPES_FILE || "proposalTypes.json",
};
Object.keys(jsonConfigFileList).forEach((key) => {
const filePath = jsonConfigFileList[key];
Expand All @@ -58,25 +61,10 @@ const configuration = () => {
}
});

let proposalTypesData;

try {
proposalTypesData = fs.readFileSync("proposalTypes.json", "utf8");
} catch (error) {
// NOTE: If there is no proposalTypes.json file provided we just use the DEFAULT_PROPOSAL_TYPE type
console.warn(error);
}

if (!proposalTypesData) {
console.warn(
`Proposal types configuration file not provided. The "${DEFAULT_PROPOSAL_TYPE}" type will be used`,
);
}

const proposalTypes: Record<string, string> = {
...JSON.parse(proposalTypesData || "{}"),
// NOTE: Add the default proposal type here
Object.assign(jsonConfigMap.proposalTypes, {
DefaultProposal: DEFAULT_PROPOSAL_TYPE,
};
});

const config = {
maxFileUploadSizeInMb: process.env.MAX_FILE_UPLOAD_SIZE || "16mb", // 16MB by default
Expand Down Expand Up @@ -224,7 +212,7 @@ const configuration = () => {
policyPublicationShiftInYears: process.env.POLICY_PUBLICATION_SHIFT ?? 3,
policyRetentionShiftInYears: process.env.POLICY_RETENTION_SHIFT ?? -1,
},
proposalTypes: proposalTypes,
proposalTypes: jsonConfigMap.proposalTypes,
};
return merge(config, localconfiguration);
};
Expand Down

0 comments on commit 8752f52

Please sign in to comment.