-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5764 from oasisprotocol/kostko/feature/entity-id
go/worker/registration: Support specifying only entity ID
- Loading branch information
Showing
8 changed files
with
74 additions
and
25 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Support only `entity_id` to be specified in configuration | ||
|
||
Instead of the need to specify the path to the entire entity descriptor, the | ||
node configuration can now specify only `registration.entity_id`, the entity | ||
public key. |
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 |
---|---|---|
@@ -1,12 +1,21 @@ | ||
package common | ||
|
||
// ExactlyOneTrue returns true iff exactly one of the passed conditions is true. | ||
func ExactlyOneTrue(conds ...bool) bool { | ||
func countTrue(conds ...bool) int { | ||
total := 0 | ||
for _, c := range conds { | ||
if c { | ||
total++ | ||
} | ||
} | ||
return total == 1 | ||
return total | ||
} | ||
|
||
// ExactlyOneTrue returns true iff exactly one of the passed conditions is true. | ||
func ExactlyOneTrue(conds ...bool) bool { | ||
return countTrue(conds...) == 1 | ||
} | ||
|
||
// AtMostOneTrue returns true iff at most one of the passed conditions is true. | ||
func AtMostOneTrue(conds ...bool) bool { | ||
return countTrue(conds...) <= 1 | ||
} |
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
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 |
---|---|---|
@@ -1,20 +1,46 @@ | ||
// Package config implements global configuration options. | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/oasisprotocol/oasis-core/go/common" | ||
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature" | ||
) | ||
|
||
// Config is the registration worker configuration structure. | ||
type Config struct { | ||
// Entity to use as the node owner in registrations (path to the JSON file). | ||
Entity string `yaml:"entity"` | ||
|
||
// EntityID to use as the node owner in registrations (public key). | ||
EntityID string `yaml:"entity_id"` | ||
} | ||
|
||
// Validate validates the configuration settings. | ||
func (c *Config) Validate() error { | ||
// Ensure only one of Entity/EntityID is set. | ||
if !common.AtMostOneTrue( | ||
c.Entity != "", | ||
c.EntityID != "", | ||
) { | ||
return fmt.Errorf("only one of `entity` and `entity_id` must be set") | ||
} | ||
|
||
// Ensure the entity ID is valid if passed. | ||
if c.EntityID != "" { | ||
var id signature.PublicKey | ||
if err := id.UnmarshalText([]byte(c.EntityID)); err != nil { | ||
return fmt.Errorf("malformed entity ID: %w", err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// DefaultConfig returns the default configuration settings. | ||
func DefaultConfig() Config { | ||
return Config{ | ||
Entity: "", | ||
Entity: "", | ||
EntityID: "", | ||
} | ||
} |
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