-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
070ea0f
commit c6ee763
Showing
12 changed files
with
185 additions
and
533 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
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,50 @@ | ||
package controllers | ||
|
||
import ( | ||
"github.com/nats-io/nkeys" | ||
"github.com/zeiss/typhoon/internal/api/models" | ||
"github.com/zeiss/typhoon/internal/api/ports" | ||
) | ||
|
||
// OperatorsController ... | ||
type OperatorsController struct { | ||
db ports.Operators | ||
} | ||
|
||
// NewOperatorsController ... | ||
func NewOperatorsController(db ports.Operators) *OperatorsController { | ||
return &OperatorsController{db} | ||
} | ||
|
||
// CreateOperator ... | ||
func (c *OperatorsController) CreateOperator(name string) (*models.Operator, error) { | ||
key, err := nkeys.CreateOperator() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
id, err := key.PublicKey() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
seed, err := key.Seed() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
op := &models.Operator{ | ||
ID: id, | ||
Key: models.NKey{ | ||
ID: id, | ||
Seed: seed, | ||
}, | ||
} | ||
|
||
err = c.db.CreateOperator(op) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return op, 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
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,11 @@ | ||
package ports | ||
|
||
import "github.com/zeiss/typhoon/internal/api/models" | ||
|
||
// Operators is the interface that wraps the methods to access data. | ||
type Operators interface { | ||
// GetOperator returns the operator with the given ID. | ||
GetOperator(id string) (*models.Operator, error) | ||
// CreateOperator creates a new operator. | ||
CreateOperator(operator *models.Operator) error | ||
} |
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
Oops, something went wrong.