Skip to content

Commit 3edfeee

Browse files
committed
[Server] add code to generate multiple security keys in single request
1 parent 3362690 commit 3edfeee

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ In the future, we intend to enhance the Unitdb with the following features:
6969

7070
- Distributed design: We are working on building out the distributed design of Unitdb, including replication and sharding management to improve its scalability.
7171
- Developer support and tooling: We are working on building more intuitive tooling, refactoring code structures, and enriching documentation to improve the onboarding experience, enabling developers to quickly integrate Unitdb to their time-series database stack.
72-
- Expanding feature set: We also plan to expand our query feature set to include functionality such as window functions and nested loop joins.
73-
- Query engine optimization: We will also be looking into developing more advanced ways to optimize query performance such as GPU memory caching.
7472

7573
## Contributing
76-
As Unitdb is under active development and at this time Unitdb is not seeking major changes or new features from new contributors. However, small bugfixes are encouraged.
74+
As Unitdb is under active development and at this time Unitdb is not seeking major changes or new features; however, small bugfixes are encouraged. Unitdb is seeking contibution to improve test coverage and documentation.
7775

7876
## Licensing
7977
This project is licensed under [Apache-2.0 License](https://github.com/unit-io/unitdb/blob/master/LICENSE).

server/internal/hdl_conn.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -485,26 +485,32 @@ func (c *_Conn) onClientIDRequest() (interface{}, bool) {
485485
// onKeyGen processes a keygen request.
486486
func (c *_Conn) onKeyGen(payload []byte) (interface{}, bool) {
487487
// Deserialize the payload.
488-
msg := types.KeyGenRequest{}
489-
if err := json.Unmarshal(payload, &msg); err != nil {
488+
req := []types.KeyGenRequest{}
489+
if err := json.Unmarshal(payload, &req); err != nil {
490490
return types.ErrBadRequest, false
491491
}
492492

493+
var resp []*types.KeyGenResponse
493494
// Use the cipher to generate the key
494-
key, err := security.GenerateKey(c.clientID.Contract(), []byte(msg.Topic), msg.Access())
495-
if err != nil {
496-
switch err {
497-
case security.ErrTargetTooLong:
498-
return types.ErrTargetTooLong, false
499-
default:
500-
return types.ErrServerError, false
495+
for _, m := range req {
496+
key, err := security.GenerateKey(c.clientID.Contract(), []byte(m.Topic), m.Access())
497+
if err != nil {
498+
switch err {
499+
case security.ErrTargetTooLong:
500+
return types.ErrTargetTooLong, false
501+
default:
502+
return types.ErrServerError, false
503+
}
501504
}
505+
r := &types.KeyGenResponse{
506+
Status: 200,
507+
Key: key,
508+
Topic: m.Topic,
509+
}
510+
511+
resp = append(resp, r)
502512
}
503513

504514
// Success, return the response
505-
return &types.KeyGenResponse{
506-
Status: 200,
507-
Key: key,
508-
Topic: msg.Topic,
509-
}, true
515+
return resp, true
510516
}

server/internal/message/security/key.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ import (
2828
// Access types for a security key.
2929
const (
3030
AllowNone = uint32(0) // Key has no privileges.
31-
AllowRead = uint32(1 << 1) // Key should be allowed to subscribe to the topic.
32-
AllowWrite = uint32(1 << 2) // Key should be allowed to publish to the topic.
31+
AllowOwner = uint32(1 << 1) // Key should be allowed to generate other keys.
32+
AllowAdmin = uint32(1 << 2) // Key should be allowed to generate other keys.
33+
AllowRead = uint32(1 << 3) // Key should be allowed to subscribe to the topic.
34+
AllowWrite = uint32(1 << 4) // Key should be allowed to publish to the topic.
3335
AllowReadWrite = AllowRead | AllowWrite // Key should be allowed to read and write to the topic.
3436

3537
// Topic types

server/internal/types/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ func (m *KeyGenRequest) Access() uint32 {
6262

6363
for i := 0; i < len(m.Type); i++ {
6464
switch c := m.Type[i]; c {
65+
case 'o':
66+
required |= security.AllowOwner | security.AllowAdmin | security.AllowReadWrite
67+
case 'a':
68+
required |= security.AllowAdmin | security.AllowReadWrite
6569
case 'r':
6670
required |= security.AllowRead
6771
case 'w':

0 commit comments

Comments
 (0)