Skip to content

Commit

Permalink
remove permission-search
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoRoessner committed Dec 13, 2024
1 parent a9f80bb commit f0b2b5a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 272 deletions.
1 change: 0 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"flow_engine_url": "",
"flow_parser_url": "",
"import_deploy_url": "",
"perm_search_url": "",
"device_repository_url": "",
"camunda_url": "",

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23
toolchain go1.23.3

require (
github.com/SENERGY-Platform/device-repository v0.1.50
github.com/SENERGY-Platform/smart-service-module-worker-lib v0.0.0-20241202070750-f1c57b1c4358
github.com/julienschmidt/httprouter v1.3.0
github.com/satori/go.uuid v1.2.0
Expand All @@ -17,9 +18,8 @@ require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/SENERGY-Platform/developer-notifications v0.0.4 // indirect
github.com/SENERGY-Platform/device-repository v0.1.36 // indirect
github.com/SENERGY-Platform/models/go v0.0.0-20241007061544-de7132ae94e4 // indirect
github.com/SENERGY-Platform/permissions-v2 v0.0.26 // indirect
github.com/SENERGY-Platform/permissions-v2 v0.0.27 // indirect
github.com/SENERGY-Platform/service-commons v0.0.0-20240813072046-91b3195dd8fc // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERo
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/SENERGY-Platform/developer-notifications v0.0.4 h1:SmblhfWavNhE1mDxzrkhmWl2AoPPqKD+7YcZCQ7a5Tg=
github.com/SENERGY-Platform/developer-notifications v0.0.4/go.mod h1:8yJrYnAYMtPEPy89ULw8ivgG8orVhSnaLgyfDt0bdgg=
github.com/SENERGY-Platform/device-repository v0.1.36 h1:2ayAxfzZQVPCctPV07wjJ9wKCRtWUn8joNsvuvIS2gk=
github.com/SENERGY-Platform/device-repository v0.1.36/go.mod h1:8yelMbJThqMs+BBIAwBEUOAcU9YoPREaDRNWYSrfMRA=
github.com/SENERGY-Platform/device-repository v0.1.50 h1:fL5mI5lQwTVhlSxrjWh+uX+UtnGT2tcMNflITDCqj4k=
github.com/SENERGY-Platform/device-repository v0.1.50/go.mod h1:8yelMbJThqMs+BBIAwBEUOAcU9YoPREaDRNWYSrfMRA=
github.com/SENERGY-Platform/models/go v0.0.0-20241007061544-de7132ae94e4 h1:zS65f1cmjAoBQUA432nmJl2TXAwqqqJMz7sp2DHLAGc=
github.com/SENERGY-Platform/models/go v0.0.0-20241007061544-de7132ae94e4/go.mod h1:bCREPNRN4P8oxLgpC3/ZKK4jXSy4MSPXoiomhohE+aw=
github.com/SENERGY-Platform/permissions-v2 v0.0.26 h1:q1q4KDRmYEKST4MLu1mrikbcNgK3QXA1w027RZNNYEc=
github.com/SENERGY-Platform/permissions-v2 v0.0.26/go.mod h1:w5AghpFIQ2Hi+HKfcuqXcizR4pCYuMLXcWAdAmOPAF4=
github.com/SENERGY-Platform/permissions-v2 v0.0.27 h1:4Sf5zNW0KMrSSJrv90MmyKD5RMnS8CT26yE7W9Za/x0=
github.com/SENERGY-Platform/permissions-v2 v0.0.27/go.mod h1:w5AghpFIQ2Hi+HKfcuqXcizR4pCYuMLXcWAdAmOPAF4=
github.com/SENERGY-Platform/service-commons v0.0.0-20240813072046-91b3195dd8fc h1:FbGDfHiDukp8wD1w4YNxjwiDpSNkRUG+Ymq9jjz3Auc=
github.com/SENERGY-Platform/service-commons v0.0.0-20240813072046-91b3195dd8fc/go.mod h1:1p2CQPNtler5leXqNgaOfr7DlgZUydrQlQYA97ycm4k=
github.com/SENERGY-Platform/smart-service-module-worker-lib v0.0.0-20241202070750-f1c57b1c4358 h1:KR107YeJ8fVnI918x6Kb2oJkGKWPCewhh/d/aeQa4P0=
Expand Down
1 change: 0 additions & 1 deletion pkg/analytics/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ type Config struct {
FlowEngineUrl string `json:"flow_engine_url"`
FlowParserUrl string `json:"flow_parser_url"`
ImportDeployUrl string `json:"import_deploy_url"`
PermSearchUrl string `json:"perm_search_url"`
DeviceRepositoryUrl string `json:"device_repository_url"`
Debug bool `json:"debug"`

Expand Down
61 changes: 26 additions & 35 deletions pkg/devices/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"encoding/json"
"errors"
"github.com/SENERGY-Platform/device-repository/lib/client"
"github.com/SENERGY-Platform/smart-service-module-worker-lib/pkg/auth"
"log"
"net/http"
Expand All @@ -30,11 +31,10 @@ import (

type Devices struct {
deviceRepositoryUrl string
permSearchUrl string
}

func New(deviceRepositoryUrl string, permSearchUrl string) *Devices {
return &Devices{deviceRepositoryUrl: deviceRepositoryUrl, permSearchUrl: permSearchUrl}
func New(deviceRepositoryUrl string) *Devices {
return &Devices{deviceRepositoryUrl: deviceRepositoryUrl}
}

func (this *Devices) GetDeviceInfosOfGroup(token auth.Token, groupId string) (devices []Device, deviceTypeIds []string, err error) {
Expand All @@ -61,44 +61,35 @@ func (this *Devices) GetDeviceInfosOfDevices(token auth.Token, deviceIds []strin
}

func (this *Devices) GetDeviceGroup(token auth.Token, groupId string) (result DeviceGroup, err error) {
groups := []DeviceGroup{}
err, _ = this.Search(token, QueryMessage{
Resource: "device-groups",
ListIds: &QueryListIds{
QueryListCommons: QueryListCommons{
Limit: 1,
Offset: 0,
Rights: "r",
SortBy: "name",
SortDesc: false,
},
Ids: []string{groupId},
},
}, &groups)
dg, err, _ := client.NewClient(this.deviceRepositoryUrl).ReadDeviceGroup(groupId, token.Jwt(), false)
if err != nil {
return result, err
}
if len(groups) == 0 {
return result, errors.New("not found")
}
return groups[0], nil
return DeviceGroup{
Id: dg.Id,
Name: dg.Name,
DeviceIds: dg.DeviceIds,
}, nil
}

func (this *Devices) GetDevicesWithIds(token auth.Token, ids []string) (result []Device, err error) {
err, _ = this.Search(token, QueryMessage{
Resource: "devices",
ListIds: &QueryListIds{
QueryListCommons: QueryListCommons{
Limit: len(ids),
Offset: 0,
Rights: "r",
SortBy: "name",
SortDesc: false,
},
Ids: ids,
},
}, &result)
return
device, err, _ := client.NewClient(this.deviceRepositoryUrl).ListDevices(token.Jwt(), client.DeviceListOptions{
Ids: ids,
Limit: int64(len(ids)),
Offset: 0,
SortBy: "name.asc",
})
if err != nil {
return result, err
}
for _, d := range device {
result = append(result, Device{
Id: d.Id,
Name: d.Name,
DeviceTypeId: d.DeviceTypeId,
})
}
return result, nil
}

func (this *Devices) GetDeviceTypeSelectables(token auth.Token, criteria []FilterCriteria, includeModified bool, servicesMustMatchAllCriteria bool) (result []DeviceTypeSelectable, err error) {
Expand Down
115 changes: 0 additions & 115 deletions pkg/devices/permsearch.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func Start(ctx context.Context, wg *sync.WaitGroup, config analytics.Config, lib
auth,
smartServiceRepo,
imports.New(config.ImportDeployUrl),
devices.New(config.DeviceRepositoryUrl, config.PermSearchUrl),
devices.New(config.DeviceRepositoryUrl),
), nil
}
return lib.Start(ctx, wg, libConfig, handlerFactory)
Expand Down
35 changes: 28 additions & 7 deletions tests/mocks/devicerepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ import (
)

type DeviceRepo struct {
requestsLog []Request
mux sync.Mutex
Response []devices.DeviceTypeSelectable
SecondResponse []devices.DeviceTypeSelectable
called bool
requestsLog []Request
mux sync.Mutex
Response []devices.DeviceTypeSelectable
SecondResponse []devices.DeviceTypeSelectable
legacyResponses map[string]interface{}
called bool
}

func (this *DeviceRepo) SetResponse(value []devices.DeviceTypeSelectable) {
func (this *DeviceRepo) SetDeviceTypeSelectablesResponse(value []devices.DeviceTypeSelectable) {
this.mux.Lock()
defer this.mux.Unlock()
this.Response = value
Expand Down Expand Up @@ -81,6 +82,9 @@ func (this *DeviceRepo) logRequestWithMessage(request *http.Request, m interface
}

func (this *DeviceRepo) Start(ctx context.Context, wg *sync.WaitGroup) (url string) {
if this.legacyResponses == nil {
this.legacyResponses = map[string]interface{}{}
}
server := httptest.NewServer(this.getRouter())
wg.Add(1)
go func() {
Expand All @@ -103,6 +107,23 @@ func (this *DeviceRepo) getRouter() http.Handler {
this.called = true
return
}
http.Error(writer, "unknown path", 500)
if resp, ok := this.legacyResponses[request.URL.Path]; ok {
json.NewEncoder(writer).Encode(resp)
return
}
http.Error(writer, "unknown path "+request.URL.Path, 500)
})
}

func (this *DeviceRepo) SetLegacyPermissionsResponses(responses map[string][]map[string]interface{}) {
this.legacyResponses = map[string]interface{}{}
for k, v := range responses {
this.legacyResponses["/"+k] = v
for _, e := range v {
id, ok := e["id"].(string)
if ok {
this.legacyResponses["/"+k+"/"+id] = e
}
}
}
}
Loading

0 comments on commit f0b2b5a

Please sign in to comment.