This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new 7fa8e2d519 add userApi (#2701)
7fa8e2d519 is described below

commit 7fa8e2d519401e89075e8bd96af4644a734fa755
Author: wyyolo <[email protected]>
AuthorDate: Tue Apr 16 23:44:19 2024 +0800

    add userApi (#2701)
---
 .../internal/serializer/deserializer.go            |  31 ++++++
 .../streampipes/model/streampipes_user/user.go     |  50 +++++++++
 .../streampipes/streampipes_client.go              |   5 +
 streampipes-client-go/streampipes/user_api.go      | 120 +++++++++++++++++++++
 4 files changed, 206 insertions(+)

diff --git 
a/streampipes-client-go/streampipes/internal/serializer/deserializer.go 
b/streampipes-client-go/streampipes/internal/serializer/deserializer.go
index d331bc01ef..1ef7f7d1dd 100644
--- a/streampipes-client-go/streampipes/internal/serializer/deserializer.go
+++ b/streampipes-client-go/streampipes/internal/serializer/deserializer.go
@@ -20,6 +20,7 @@ package serializer
 import (
        "encoding/json"
        
"github.com/apache/streampipes/streampipes-client-go/streampipes/model/data_lake"
+       
"github.com/apache/streampipes/streampipes-client-go/streampipes/model/streampipes_user"
        
"github.com/apache/streampipes/streampipes-client-go/streampipes/model/streampipes_version"
 )
 
@@ -90,3 +91,33 @@ func (d *StreamPipesVersionDeserializer) Unmarshal(data 
[]byte) (interface{}, er
        }
        return dataSeries, nil
 }
+
+type ShortUserInfosDeserializer struct{}
+
+func NewShortUserInfosDeserializer() *ShortUserInfosDeserializer {
+       return &ShortUserInfosDeserializer{}
+}
+
+func (s *ShortUserInfosDeserializer) Unmarshal(data []byte) (interface{}, 
error) {
+       var shortUserInfo []streampipes_user.ShortUserInfo
+       err := json.Unmarshal(data, &shortUserInfo)
+       if err != nil {
+               return nil, err
+       }
+       return shortUserInfo, nil
+}
+
+type UserAccountDeserializer struct{}
+
+func NewUserAccountDeserializer() *UserAccountDeserializer {
+       return &UserAccountDeserializer{}
+}
+
+func (p *UserAccountDeserializer) Unmarshal(data []byte) (interface{}, error) {
+       var userAccount streampipes_user.UserAccount
+       err := json.Unmarshal(data, &userAccount)
+       if err != nil {
+               return nil, err
+       }
+       return userAccount, nil
+}
diff --git a/streampipes-client-go/streampipes/model/streampipes_user/user.go 
b/streampipes-client-go/streampipes/model/streampipes_user/user.go
new file mode 100644
index 0000000000..d3d87f69b1
--- /dev/null
+++ b/streampipes-client-go/streampipes/model/streampipes_user/user.go
@@ -0,0 +1,50 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package streampipes_user
+
+type ShortUserInfo struct {
+       PrincipalID string `json:"principalId"`
+       Email       string `json:"email"`
+       DisplayName string `json:"displayName"`
+}
+
+type UserAccount struct {
+       PrincipalID             string         `json:"principalId"`
+       Rev                     string         `json:"rev"`
+       Username                string         `json:"username"`
+       ObjectPermissions       []string       `json:"objectPermissions"`
+       Roles                   []string       `json:"roles"`
+       Groups                  []string       `json:"groups"`
+       AccountEnabled          bool           `json:"accountEnabled"`
+       AccountLocked           bool           `json:"accountLocked"`
+       AccountExpired          bool           `json:"accountExpired"`
+       PrincipalType           string         `json:"principalType"`
+       FullName                string         `json:"fullName"`
+       Password                string         `json:"password"`
+       PreferredDataStreams    []string       `json:"preferredDataStreams"`
+       PreferredDataProcessors []string       `json:"preferredDataProcessors"`
+       PreferredDataSinks      []string       `json:"preferredDataSinks"`
+       UserApiTokens           []UserApiToken `json:"userApiTokens"`
+       HideTutorial            bool           `json:"hideTutorial"`
+       DarkMode                bool           `json:"darkMode"`
+}
+
+type UserApiToken struct {
+       TokenID   string `json:"tokenId"`
+       TokenName string `json:"tokenName"`
+}
diff --git a/streampipes-client-go/streampipes/streampipes_client.go 
b/streampipes-client-go/streampipes/streampipes_client.go
index 557b2f95cf..c968a4ee4f 100644
--- a/streampipes-client-go/streampipes/streampipes_client.go
+++ b/streampipes-client-go/streampipes/streampipes_client.go
@@ -71,3 +71,8 @@ func (s *StreamPipesClient) StreamPipesVersion() *Versions {
 
        return NewVersions(s.config)
 }
+
+func (s *StreamPipesClient) UserInfo() *StreamPipesUserInfo {
+
+       return NewStreamPipesUserInfo(s.config)
+}
diff --git a/streampipes-client-go/streampipes/user_api.go 
b/streampipes-client-go/streampipes/user_api.go
new file mode 100644
index 0000000000..40a9a4ee65
--- /dev/null
+++ b/streampipes-client-go/streampipes/user_api.go
@@ -0,0 +1,120 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package streampipes
+
+import (
+       "github.com/apache/streampipes/streampipes-client-go/streampipes/config"
+       
"github.com/apache/streampipes/streampipes-client-go/streampipes/internal/serializer"
+       
"github.com/apache/streampipes/streampipes-client-go/streampipes/internal/util"
+       
"github.com/apache/streampipes/streampipes-client-go/streampipes/model/streampipes_user"
+       "io"
+       "log"
+       "net/http"
+)
+
+type StreamPipesUserInfo struct {
+       endpoint
+}
+
+func NewStreamPipesUserInfo(clientConfig config.StreamPipesClientConfig) 
*StreamPipesUserInfo {
+
+       return &StreamPipesUserInfo{
+               endpoint{config: clientConfig},
+       }
+}
+
+func (s *StreamPipesUserInfo) GetSingleStreamPipesUserAccountInfo(principalId 
string) (streampipes_user.UserAccount, error) {
+
+       endPointUrl := util.NewStreamPipesApiPath(s.config.Url, 
"streampipes-backend/api/v2/users", []string{principalId})
+       log.Printf("Get data from: %s", endPointUrl)
+
+       response, err := s.executeRequest("GET", endPointUrl)
+       if err != nil {
+               return streampipes_user.UserAccount{}, err
+       }
+
+       if response.StatusCode != http.StatusOK {
+               err = s.handleStatusCode(response)
+               if err != nil {
+                       return streampipes_user.UserAccount{}, err
+               }
+       }
+
+       body, err := io.ReadAll(response.Body)
+       if err != nil {
+               return streampipes_user.UserAccount{}, err
+       }
+
+       unmarshalData, err := 
serializer.NewUserAccountDeserializer().Unmarshal(body)
+       if err != nil {
+               return streampipes_user.UserAccount{}, err
+       }
+       userAccount := unmarshalData.(streampipes_user.UserAccount)
+
+       return userAccount, nil
+}
+
+func (s *StreamPipesUserInfo) GetAllStreamPipesShortUserInfo() 
([]streampipes_user.ShortUserInfo, error) {
+
+       endPointUrl := util.NewStreamPipesApiPath(s.config.Url, 
"streampipes-backend/api/v2/users", nil)
+       log.Printf("Get data from: %s", endPointUrl)
+
+       response, err := s.executeRequest("GET", endPointUrl)
+       if err != nil {
+               return nil, err
+       }
+
+       if response.StatusCode != http.StatusOK {
+               err = s.handleStatusCode(response)
+               if err != nil {
+                       return nil, err
+               }
+       }
+
+       body, err := io.ReadAll(response.Body)
+       if err != nil {
+               return nil, err
+       }
+
+       unmarshalData, err := 
serializer.NewShortUserInfosDeserializer().Unmarshal(body)
+       if err != nil {
+               return nil, err
+       }
+       dataLakeWidget := unmarshalData.([]streampipes_user.ShortUserInfo)
+
+       return dataLakeWidget, nil
+}
+
+func (s *StreamPipesUserInfo) DeleteSingleStreamPipesShortUserInfo(principalId 
string) error {
+       endPointUrl := util.NewStreamPipesApiPath(s.config.Url, 
"streampipes-backend/api/v2/users", []string{principalId})
+       log.Printf("Delete data from: %s", endPointUrl)
+
+       response, err := s.executeRequest("DELETE", endPointUrl)
+       if err != nil {
+               return err
+       }
+
+       if response.StatusCode != http.StatusOK {
+               err = s.handleStatusCode(response)
+               if err != nil {
+                       return err
+               }
+       }
+
+       return nil
+}

Reply via email to