Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tech(config): set and get config from json #50

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shangan23
Copy link
Collaborator

Get and Set JSON using a key from a file.

Fixes #47

@@ -0,0 +1 @@
{"secret":"encrypt","algorithm":"AES"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

algorithm value not used?

Copy link
Collaborator Author

@shangan23 shangan23 Apr 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. For now, created the config method and just used the secret. But this solution may not work. Since the config is based on a file on each config set the file will get overridden. So need to think of some alternate solution to maintain the config object instead of keeping the values in a file.

CONVERTED TO DRAFT PR

@shangan23 shangan23 marked this pull request as draft April 22, 2021 05:48
@shangan23
Copy link
Collaborator Author

Converted the PR to draft since there is some more work to be done.

import { isUrl, isPatternUrl, isPatterObject, isPattern, isPath } from '../util'

const configData = fs.readFileSync(__dirname + '/config.json', 'utf8')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be template literal like below.

const configFile = 'config.json'
fs.readFileSync(`${__dirname}/${configFile}`, 'utf8')

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it can be. Refer Comment

import { isUrl, isPatternUrl, isPatterObject, isPattern, isPath } from '../util'

const configData = fs.readFileSync(__dirname + '/config.json', 'utf8')
const configObject = JSON.parse(configData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.parse should be inside try / catch block. there is possibility of circular exception error. can be like below.

let moduleConfig = {}
try {
moduleConfig = JSON.parse(configData)
} catch (e) {
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will work on it.

return {
config: function (config = {}) {
if (Object.keys(config).length === 0)
throw new Error('options is missing')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move all error messages to errorMessages.js

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure will do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a config method to set the default encryption algorithm(AES) and secret key
3 participants