Skip to content

Commit 6f3547f

Browse files
authored
Merge pull request #167 from azaurus1/165-improve-users-to-allow-acl-in-body
added permissions and tables as optional fields in user struct
2 parents 36feb5b + 5655508 commit 6f3547f

File tree

4 files changed

+90
-13
lines changed

4 files changed

+90
-13
lines changed

example/main.go

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ func main() {
7676
// demoGetSegmentTiers(client)
7777
// demoGetSegmentCRC(client)
7878
// demoGetSegmentMetadata(client)
79-
demoGetSegmentZKMetadata(client)
79+
// demoGetSegmentZKMetadata(client)
80+
// demoUpdateSegmentZKTimeInterval(client)
81+
demoCreateUserWithACL(client)
8082

8183
}
8284

@@ -1262,6 +1264,18 @@ func demoGetSegmentZKMetadata(client *pinot.PinotAPIClient) {
12621264

12631265
}
12641266

1267+
func demoUpdateSegmentZKTimeInterval(client *pinot.PinotAPIClient) {
1268+
1269+
updateSegmentZKTimeIntervalResp, err := client.UpdateSegmentZKTimeInterval("airlineStats_OFFLINE")
1270+
if err != nil {
1271+
log.Panic(err)
1272+
}
1273+
1274+
fmt.Println("Updating Segment ZK Interval Time:")
1275+
fmt.Println(updateSegmentZKTimeIntervalResp.Status)
1276+
1277+
}
1278+
12651279
func getOrDefault(defaultOption string, envKeys ...string) string {
12661280

12671281
for _, envKey := range envKeys {
@@ -1273,3 +1287,47 @@ func getOrDefault(defaultOption string, envKeys ...string) string {
12731287
return defaultOption
12741288

12751289
}
1290+
1291+
func demoCreateUserWithACL(client *pinot.PinotAPIClient) {
1292+
1293+
user := pinotModel.User{
1294+
Username: "liam_with_permissions",
1295+
Password: "password",
1296+
Component: "BROKER",
1297+
Role: "admin",
1298+
Permissions: &[]string{"READ"},
1299+
Tables: &[]string{"my_table_Offline"},
1300+
}
1301+
1302+
userBytes, err := json.Marshal(user)
1303+
if err != nil {
1304+
log.Panic(err)
1305+
}
1306+
1307+
// Create User
1308+
createResp, err := client.CreateUser(userBytes)
1309+
if err != nil {
1310+
fmt.Println(err)
1311+
}
1312+
1313+
fmt.Println(createResp.Status)
1314+
1315+
// Read User
1316+
getUserResp, err := client.GetUser(user.Username, user.Component)
1317+
if err != nil {
1318+
log.Panic(err)
1319+
}
1320+
1321+
fmt.Println("Reading User:")
1322+
fmt.Println(getUserResp.Permissions)
1323+
1324+
// Read User
1325+
getUserResp, err = client.GetUser("liam_with_admin", "BROKER")
1326+
if err != nil {
1327+
log.Panic(err)
1328+
}
1329+
1330+
fmt.Println("Reading User:")
1331+
fmt.Println(getUserResp.Permissions)
1332+
1333+
}

go-pinot-api.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,22 @@ func (c *PinotAPIClient) CreateObject(endpoint string, body []byte, result any)
129129

130130
fullURL := prepareRequestURL(c, endpoint)
131131

132-
req, err := http.NewRequest(http.MethodPost, fullURL.String(), bytes.NewBuffer(body))
132+
var req *http.Request
133+
var err error
134+
135+
if body == nil {
136+
c.log.Debug("body is nil")
137+
req, err = http.NewRequest(http.MethodPost, fullURL.String(), nil)
138+
req.Header.Set("Content-Type", "application/json")
139+
} else {
140+
req, err = http.NewRequest(http.MethodPost, fullURL.String(), bytes.NewBuffer(body))
141+
req.Header.Set("Content-Type", "application/json")
142+
}
143+
133144
if err != nil {
134145
return fmt.Errorf("client: could not create request: %w", err)
135146
}
136147

137-
req.Header.Set("Content-Type", "application/json")
138-
139148
c.log.Debug(fmt.Sprintf("attempting POST %s", fullURL))
140149

141150
res, err := c.pinotHttp.Do(req)
@@ -782,6 +791,12 @@ func (c *PinotAPIClient) GetSegmentZKMetadata(tableName string) (*model.GetSegme
782791
return &result, err
783792
}
784793

794+
func (c *PinotAPIClient) UpdateSegmentZKTimeInterval(tableNameWithType string) (*model.UserActionResponse, error) {
795+
var result model.UserActionResponse
796+
err := c.CreateObject(fmt.Sprintf("/segments/%s/updateZkTimeInterval", tableNameWithType), nil, &result)
797+
return &result, err
798+
}
799+
785800
// Cluster
786801

787802
func (c *PinotAPIClient) GetClusterInfo() (*model.GetClusterResponse, error) {

go-pinot-api_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,10 +3938,12 @@ func TestCreateUser(t *testing.T) {
39383938
client := createPinotClient(server)
39393939

39403940
user := model.User{
3941-
Username: "testUser",
3942-
Password: "test",
3943-
Component: "BROKER",
3944-
Role: "ADMIN",
3941+
Username: "testUser",
3942+
Password: "test",
3943+
Component: "BROKER",
3944+
Role: "ADMIN",
3945+
Permissions: &[]string{"READ"},
3946+
Tables: &[]string{"my_table_OFFLINE"},
39453947
}
39463948

39473949
userBytes, err := json.Marshal(user)

model/User.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package model
22

33
type User struct {
4-
Username string `json:"username"`
5-
Password string `json:"password"`
6-
Component string `json:"component"`
7-
Role string `json:"role"`
8-
UsernameWithComponent string `json:"usernameWithComponent"`
4+
Username string `json:"username"`
5+
Password string `json:"password"`
6+
Component string `json:"component"`
7+
Role string `json:"role"`
8+
UsernameWithComponent string `json:"usernameWithComponent"`
9+
Permissions *[]string `json:"permissions,omitempty"` // optional for adding permissions etc
10+
Tables *[]string `json:"tables,omitempty"`
911
}

0 commit comments

Comments
 (0)