-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
RFC: coreapi.Name,Key #4477
Merged
Merged
RFC: coreapi.Name,Key #4477
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
027f498
coreapi: Name API proposal
magik6k 1b5fbb0
coreapi: Keystore API proposal
magik6k 1c73d48
coreapi: name/key functional options
magik6k 587dc18
coreapi: Documentation for Name/Key
magik6k 8df2d1a
coreapi: name/key review suggestions
magik6k 396c34b
coreapi: key tests
magik6k 2109cbc
coreapi: Name tests
magik6k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,72 @@ | ||
package options | ||
|
||
const ( | ||
RSAKey = "rsa" | ||
Ed25519Key = "ed25519" | ||
|
||
DefaultRSALen = 2048 | ||
) | ||
|
||
type KeyGenerateSettings struct { | ||
Algorithm string | ||
Size int | ||
} | ||
|
||
type KeyRenameSettings struct { | ||
Force bool | ||
} | ||
|
||
type KeyGenerateOption func(*KeyGenerateSettings) error | ||
type KeyRenameOption func(*KeyRenameSettings) error | ||
|
||
func KeyGenerateOptions(opts ...KeyGenerateOption) (*KeyGenerateSettings, error) { | ||
options := &KeyGenerateSettings{ | ||
Algorithm: RSAKey, | ||
Size: -1, | ||
} | ||
|
||
for _, opt := range opts { | ||
err := opt(options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return options, nil | ||
} | ||
|
||
func KeyRenameOptions(opts ...KeyRenameOption) (*KeyRenameSettings, error) { | ||
options := &KeyRenameSettings{ | ||
Force: false, | ||
} | ||
|
||
for _, opt := range opts { | ||
err := opt(options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return options, nil | ||
} | ||
|
||
type KeyOptions struct{} | ||
|
||
func (api *KeyOptions) WithType(algorithm string) KeyGenerateOption { | ||
return func(settings *KeyGenerateSettings) error { | ||
settings.Algorithm = algorithm | ||
return nil | ||
} | ||
} | ||
|
||
func (api *KeyOptions) WithSize(size int) KeyGenerateOption { | ||
return func(settings *KeyGenerateSettings) error { | ||
settings.Size = size | ||
return nil | ||
} | ||
} | ||
|
||
func (api *KeyOptions) WithForce(force bool) KeyRenameOption { | ||
return func(settings *KeyRenameSettings) error { | ||
settings.Force = force | ||
return nil | ||
} | ||
} |
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,93 @@ | ||
package options | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
const ( | ||
DefaultNameValidTime = 24 * time.Hour | ||
) | ||
|
||
type NamePublishSettings struct { | ||
ValidTime time.Duration | ||
Key string | ||
} | ||
|
||
type NameResolveSettings struct { | ||
Recursive bool | ||
Local bool | ||
Cache bool | ||
} | ||
|
||
type NamePublishOption func(*NamePublishSettings) error | ||
type NameResolveOption func(*NameResolveSettings) error | ||
|
||
func NamePublishOptions(opts ...NamePublishOption) (*NamePublishSettings, error) { | ||
options := &NamePublishSettings{ | ||
ValidTime: DefaultNameValidTime, | ||
Key: "self", | ||
} | ||
|
||
for _, opt := range opts { | ||
err := opt(options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return options, nil | ||
} | ||
|
||
func NameResolveOptions(opts ...NameResolveOption) (*NameResolveSettings, error) { | ||
options := &NameResolveSettings{ | ||
Recursive: false, | ||
Local: false, | ||
Cache: true, | ||
} | ||
|
||
for _, opt := range opts { | ||
err := opt(options) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return options, nil | ||
} | ||
|
||
type NameOptions struct{} | ||
|
||
func (api *NameOptions) WithValidTime(validTime time.Duration) NamePublishOption { | ||
return func(settings *NamePublishSettings) error { | ||
settings.ValidTime = validTime | ||
return nil | ||
} | ||
} | ||
|
||
func (api *NameOptions) WithKey(key string) NamePublishOption { | ||
return func(settings *NamePublishSettings) error { | ||
settings.Key = key | ||
return nil | ||
} | ||
} | ||
|
||
func (api *NameOptions) WithRecursive(recursive bool) NameResolveOption { | ||
return func(settings *NameResolveSettings) error { | ||
settings.Recursive = recursive | ||
return nil | ||
} | ||
} | ||
|
||
func (api *NameOptions) WithLocal(local bool) NameResolveOption { | ||
return func(settings *NameResolveSettings) error { | ||
settings.Local = local | ||
return nil | ||
} | ||
} | ||
|
||
func (api *NameOptions) WithCache(cache bool) NameResolveOption { | ||
return func(settings *NameResolveSettings) error { | ||
settings.Cache = cache | ||
return nil | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 noticed
key
can be both a key name and peerID (seekeylookup()
) -- cool! Let's make sure to document that :)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.
Done