-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"secret":"encrypt","algorithm":"AES"} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
const Url = require('url-parse') | ||
const CryptoJS = require('crypto-js') | ||
const fs = require('fs') | ||
import { isUrl, isPatternUrl, isPatterObject, isPattern, isPath } from '../util' | ||
|
||
const configData = fs.readFileSync(__dirname + '/config.json', 'utf8') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be template literal like below.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it can be. Refer Comment |
||
const configObject = JSON.parse(configData) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure will work on it. |
||
|
||
const encrypt = (function () { | ||
const secret = 'Secret Passphrase' | ||
const secret = configObject.secret | ||
return { | ||
config: function (config = {}) { | ||
if (Object.keys(config).length === 0) | ||
throw new Error('options is missing') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move all error messages to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure will do that |
||
for (const [key, value] of Object.entries(config)) { | ||
configObject[key] = value | ||
} | ||
fs.writeFileSync(__dirname + '/config.json', JSON.stringify(configObject)) | ||
}, | ||
url: function (url, options = {}) { | ||
if (!url) throw new Error('url is missing') | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
algorithm value not used?
There was a problem hiding this comment.
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