-
Notifications
You must be signed in to change notification settings - Fork 62
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
feat: add keysize through an option to spawn #203
Changes from 2 commits
2595fc4
718e0ce
c9c25da
c3fca62
55142c5
17d578e
f5f400e
ee74427
b167a3c
ac70cda
6c7a028
2ca9aa1
1351dde
fb30e0e
174e9dc
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 |
---|---|---|
|
@@ -57,6 +57,14 @@ class Daemon { | |
this._gatewayAddr = null | ||
this._started = false | ||
this.api = null | ||
this.keySize = null | ||
|
||
this.keySize = process.env.IPFS_KEYSIZE | ||
|
||
// option takes precedence over env variable | ||
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. I don't think this is right. First it should use the default value. Second it should use the passed in value and lastly, if there is a environment variable, use that. This way we can override application configs when deploying etc. 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. 👍 for what @victorbjelkholm said. 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. Wait, what @victorbjelkholm said reads as - default take precedence over env, which takes precedence over option? Seems backwards, unless I'm reading it wrong. In any case, this is what I'm doing now - option takes precedence over ENV variable, which takes precedence over default. I think that is the canonical way of doing it and allows passing defaults with the ENV variable, but override them on a case by case basis in tests cases and elsewhere? 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.
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. @dryajov I believe you are using 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.
Which uses I think the contention is whether ENV take precedence over option or vice versa. The case I'm making is that an ENV variable will define a global that should be overridable through an option when calling 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. So in my case it is -
But I'm not dead set on it, but it feels more natural to me. It also follows well established scoping rules - IMO. Updated with last line 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. @dryajov use #203 (comment), which is pretty much how every system works. I wonder which system are you familiar with that uses it the other way around. 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. Any programming language with correct scoping rules :) |
||
if (typeof this.opts.init === 'object') { | ||
this.keySize = this.opts.init.keySize | ||
} | ||
|
||
if (this.opts.env) { | ||
Object.assign(this.env, this.opts.env) | ||
|
@@ -128,11 +136,19 @@ class Daemon { | |
this.path = initOpts.directory | ||
} | ||
|
||
const args = ['init', '-b', initOpts.keysize || 2048] | ||
const keySize = initOpts.keysize ? initOpts.keysize : this.keySize | ||
const args = ['init'] | ||
// do not just set a default keysize, | ||
// in case we decide to change it at | ||
// the daemon level in the future | ||
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. This sentence doesn't read right. Do you mean "Skip if default daemon keysize"? 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. Currently, ipfs daemons have a default keysize when using |
||
if (keySize) { | ||
args.concat(['-b', keySize]) | ||
} | ||
if (initOpts.pass) { | ||
args.push('--pass') | ||
args.push('"' + initOpts.pass + '"') | ||
} | ||
log(`initializing with keysize: ${keySize}`) | ||
run(this, args, { env: this.env }, (err, result) => { | ||
if (err) { | ||
return callback(err) | ||
|
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.
Not a fan of conditional types in a parameter. Either it's a
Boolean
or it's aObject
. Rather, we should add a new option. If we're only addingkeySize
, why not makekeySize
a key of theoptions
object?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.
I also think we call the option
bits
here, OR, change the option in go-ipfs as well. It'sbits
there currently, butkeySize
is probably a more descriptive name.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.
Thanks @victorbjelkholm, I thought about that too and you're right, I'll add another options
initOpts
and leaveinit
as a bool.For the second comment,
keysize
is used because historically that is whatipfsd-ctl
used and it's the same name we use when passing that flag toinit
, and yes I thinkkeysize
is more descriptive.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.
read: #188 (comment)
I'm fine with init being boolean or object, but I'm fine with
initOptions
(not initOpts) too.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.
README needs to be updated to include
initOptions