-
Notifications
You must be signed in to change notification settings - Fork 0
api: implement namer, generator, validator #17
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
base: master
Are you sure you want to change the base?
Conversation
e331f55 to
5eb96c6
Compare
Pull Request Test Coverage Report for Build 19822144009Details
💛 - Coveralls |
5eb96c6 to
9c15fdc
Compare
082bc61 to
5e8e064
Compare
5e8e064 to
a0bda45
Compare
Please, change the commit title and the PR title. |
a0bda45 to
a5ddaf9
Compare
a5ddaf9 to
955d2e8
Compare
955d2e8 to
48ffc1c
Compare
48ffc1c to
71fa8ac
Compare
namer/generatorvalidator.go
Outdated
| return nil, fmt.Errorf("failed to sign: %w", err) | ||
| } | ||
|
|
||
| names := gv.Namer.GenerateNames(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.
So we generate names and then parse them with another method of the same class. At the moment it looks like we decode what we have just encoded. If it is the only planned usage of such classes I'd suggest to have a kind of single GenerateKeys method that generates keys from name instead of 2-phase transformation name->names->keys.
|
Have a small discussion with @patapenka-alexey about how to reorganize package: type key struct {
name string // Object identifier
type KeyType // Type of object (hash/signature/value)
property string // Additional metadata (version/algorithm)
raw string // Raw key string
}type Key interface {
Name() string // Get object name
Type() KeyType // Get key type
Property() string // Get metadata (e.g., algorithm version)
Build() string // Reconstruct raw key string
}type DefaultNamer struct {
prefix string // Key prefix (e.g., "storage/")
}
// Constructor with hash/signature name configurations
func NewDefaultNamer(prefix string, hashNames, sigNames []string) *DefaultNamer
// Methods:
// - Generate all keys for an object name
func (n *DefaultNamer) GenerateNames(name string) []Key {}
// - Parse multiple raw keys into grouped results
func (n *DefaultNamer) ParseNamesMulti(names []string) ParseNamesResult {}type ParseNamesResult struct {
isSingle bool // True if result contains only one object name
isSingleName string // Cached name when isSingle=true
result map[string][]Key // Grouped keys: object name → key list
}
// Helper methods:
// - Get keys for single-name case (if applicable)
func (r *ParseNamesResult) SelectSingle() ([]Key, bool)
// - Iterate over all name→keys groups
func (r *ParseNamesResult) Iter() iter.Seq2[string, []Key]
// - Get keys for a specific object name
func (r *ParseNamesResult) Select(name string) ([]Key, bool)
// - Count unique object names
func (r *ParseNamesResult) Len() intSigning/Generation Workflow
Validation Workflow
This code decomposition and API will help us test code, will make clearer separation of "parsing/generation/validation" logic. Note 1
Note 2 Parsing logic centralized in
|
namer/namer.go
Outdated
| var key Key | ||
|
|
||
| // Remove prefix. | ||
| result := strings.ReplaceAll(name, n.prefix, "") |
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.
It will remove not only prefix, but all occurrences of n.prefix substring.
And what if name does not start with n.prefix?
| result := strings.ReplaceAll(name, n.prefix, "") | |
| result, found := strings.CutPrefix(name, n.prefix) | |
| if !found { | |
| continue // or something similar | |
| } |
Closes TNTP-4190
b982e1d to
1dc942d
Compare
05307e4 to
6f22bf6
Compare
Closes TNTP-4190