Skip to content

Commit

Permalink
feat: add protocol schemes to index and filtering by protocols to TM …
Browse files Browse the repository at this point in the history
…list
  • Loading branch information
alexbrdn committed Nov 5, 2024
1 parent 505996d commit 684e485
Show file tree
Hide file tree
Showing 27 changed files with 496 additions and 35 deletions.
60 changes: 60 additions & 0 deletions api/tm-catalog.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ paths:
schema:
type: string
example: 'BazLamp,POC1000'
- name: 'filter.protocol'
in: query
description: |
Filters the inventory by one ore more URL protocol schemes having exact match.
The filter works additive to other filters.
schema:
type: string
example: 'http,https'
- name: 'filter.name'
in: query
description: |
Expand Down Expand Up @@ -689,6 +697,15 @@ paths:
schema:
type: string
example: 'BazLamp,POC1000'
- name: 'filter.protocol'
in: query
description: |
Filters the authors according to whether they have inventory entries
which support at least one of the given URL protocol schemes with an exact match.
The filter works additive to other filters.
schema:
type: string
example: 'http,https'
- name: 'search'
in: query
description: |
Expand Down Expand Up @@ -747,6 +764,15 @@ paths:
schema:
type: string
example: 'BazLamp,POC1000'
- name: 'filter.protocol'
in: query
description: |
Filters the manufacturers according to whether they have inventory entries
which support at least one of the given URL protocol schemes with an exact match.
The filter works additive to other filters.
schema:
type: string
example: 'http,https'
- name: 'search'
in: query
description: |
Expand Down Expand Up @@ -804,6 +830,15 @@ paths:
schema:
type: string
example: 'BarTech,siemens'
- name: 'filter.protocol'
in: query
description: |
Filters the mpns according to whether they have inventory entries
which support at least one of the given URL protocol schemes with an exact match.
The filter works additive to other filters.
schema:
type: string
example: 'http,https'
- name: 'search'
in: query
description: |
Expand Down Expand Up @@ -1102,6 +1137,13 @@ components:
$ref: '#/components/schemas/InventoryEntryVersionLinks'
attachments:
$ref: "#/components/schemas/AttachmentsList"
protocols:
type: array
items:
type: string
example:
- "https"
- "modbus+tcp"
InventoryEntryLinks:
type: object
required:
Expand Down Expand Up @@ -1400,6 +1442,8 @@ components:
'content': './thing-models/siemens/siemens/poc1000/v1.0.0-20240108112117-2cd14601ef09.tm.json'
'timestamp': '20240108112117'
'tmID': 'siemens/siemens/poc1000/v1.0.0-20240108112117-2cd14601ef09.tm.json'
'protocols':
- "modbus+tcp"
'version':
'model': '1.0.0'
- 'description': 'The Powercenter 1000 is a data transceiver for SENTRON circuit protection devices.'
Expand All @@ -1410,6 +1454,8 @@ components:
'content': './thing-models/siemens/siemens/poc1000/v0.0.0-20231217140234-f4184d08a02c.tm.json'
'timestamp': '20231217140234'
'tmID': 'siemens/siemens/poc1000/v0.0.0-20231217140234-f4184d08a02c.tm.json'
'protocols':
- "modbus+tcp"
'version':
'model': '0.0.0'
- 'description': ''
Expand All @@ -1420,6 +1466,8 @@ components:
'content': './thing-models/siemens/siemens/poc1000/v0.0.0-20231201133246-e1594d08a01b.tm.json'
'timestamp': '20231201133246'
'tmID': 'siemens/siemens/poc1000/v0.0.0-20231201133246-e1594d08a01b.tm.json'
'protocols':
- "modbus+tcp"
'version':
'model': '0.0.0'
attachments:
Expand All @@ -1442,6 +1490,9 @@ components:
'content': './thing-models/siemens/siemens/poc1000/v1.0.0-20240108112117-2cd14601ef09.tm.json'
'timestamp': '20240108112117'
'tmID': 'siemens/siemens/poc1000/v1.0.0-20240108112117-2cd14601ef09.tm.json'
'protocols':
- "https"
- "modbus+tcp"
'version':
'model': '1.0.0'
InventoryEntryVersionsResponseExample:
Expand All @@ -1455,6 +1506,9 @@ components:
'content': './thing-models/siemens/siemens/poc1000/v1.0.0-20240108112117-2cd14601ef09.tm.json'
'timestamp': '20240108112117'
'tmID': 'siemens/siemens/poc1000/v1.0.0-20240108112117-2cd14601ef09.tm.json'
'protocols':
- "https"
- "modbus+tcp"
'version':
'model': '1.0.0'
InventoryResponseExample:
Expand All @@ -1480,6 +1534,8 @@ components:
'content': './thing-models/siemens/siemens/poc1000/v1.0.0-20240108112117-2cd14601ef09.tm.json'
'timestamp': '20240108112117'
'tmID': 'siemens/siemens/poc1000/v1.0.0-20240108112117-2cd14601ef09.tm.json'
'protocols':
- "modbus+tcp"
'version':
'model': '1.0.0'
- 'description': 'The Powercenter 1000 is a data transceiver for SENTRON circuit protection devices.'
Expand All @@ -1490,6 +1546,8 @@ components:
'content': './thing-models/siemens/siemens/poc1000/v0.0.0-20231217140234-f4184d08a02c.tm.json'
'timestamp': '20231217140234'
'tmID': 'siemens/siemens/poc1000/v0.0.0-20231217140234-f4184d08a02c.tm.json'
'protocols':
- "modbus+tcp"
'version':
'model': '0.0.0'
- 'description': ''
Expand All @@ -1500,6 +1558,8 @@ components:
'content': './thing-models/siemens/siemens/poc1000/v0.0.0-20231201133246-e1594d08a01b.tm.json'
'timestamp': '20231201133246'
'tmID': 'siemens/siemens/poc1000/v0.0.0-20231201133246-e1594d08a01b.tm.json'
'protocols':
- "modbus+tcp"
'version':
'model': '0.0.0'
- 'links':
Expand Down
2 changes: 1 addition & 1 deletion cmd/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ var digestCmd = &cobra.Command{

func init() {
// uncomment the next line if necessary for testing. Never commit it uncommented
//RootCmd.AddCommand(digestCmd)
RootCmd.AddCommand(digestCmd)
}
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ type FilterFlags struct {
FilterAuthor string
FilterManufacturer string
FilterMpn string
FilterProtocol string
Search string
}

func CreateSearchParamsFromCLI(flags FilterFlags, name string) *model.SearchParams {
return model.ToSearchParams(&flags.FilterAuthor, &flags.FilterManufacturer, &flags.FilterMpn, &name, &flags.Search,
return model.ToSearchParams(&flags.FilterAuthor, &flags.FilterManufacturer, &flags.FilterMpn, &flags.FilterProtocol, &name, &flags.Search,
&model.SearchOptions{NameFilterType: model.PrefixMatch})
}

Expand All @@ -104,6 +105,7 @@ func AddTMFilterFlags(cmd *cobra.Command, flags *FilterFlags) {
cmd.Flags().StringVar(&flags.FilterAuthor, "filter.author", "", "filter TMs by one or more comma-separated authors")
cmd.Flags().StringVar(&flags.FilterManufacturer, "filter.manufacturer", "", "filter TMs by one or more comma-separated manufacturers")
cmd.Flags().StringVar(&flags.FilterMpn, "filter.mpn", "", "filter TMs by one or more comma-separated mpn (manufacturer part number)")
cmd.Flags().StringVar(&flags.FilterProtocol, "filter.protocol", "", "filter TMs by one or more comma-separated supported protocol schemes")
cmd.Flags().StringVarP(&flags.Search, "search", "s", "", "search TMs by their content matching the search term")

}
24 changes: 12 additions & 12 deletions internal/app/cli/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ func TestCopy(t *testing.T) {
tmID_1 := copyListRes.Entries[0].Versions[0].TMID
tmID_2 := copyListRes.Entries[0].Versions[1].TMID
tmID_3 := copyListRes.Entries[0].Versions[2].TMID
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
_, tmContent2, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v3.2.1-20240409155220-3f779458e453.tm.json")
_, tmContent3, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v3.11.1-20240409155220-da7dbd7ed830.tm.json")
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
_, tmContent2, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v3.2.1-20240409155220-3f779458e453.tm.json")
_, tmContent3, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v3.11.1-20240409155220-da7dbd7ed830.tm.json")
readmeContent := []byte("# Read This First")
changelogContent := []byte("# CHANGELOG")
var sp *model.SearchParams
Expand Down Expand Up @@ -161,9 +161,9 @@ func TestCopy(t *testing.T) {
tmID_1 := copyListRes.Entries[0].Versions[0].TMID
tmID_2 := copyListRes.Entries[0].Versions[1].TMID
tmID_3 := copyListRes.Entries[0].Versions[2].TMID
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
_, tmContent2, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v3.2.1-20240409155220-3f779458e453.tm.json")
_, tmContent3, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v3.11.1-20240409155220-da7dbd7ed830.tm.json")
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
_, tmContent2, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v3.2.1-20240409155220-3f779458e453.tm.json")
_, tmContent3, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v3.11.1-20240409155220-da7dbd7ed830.tm.json")
readmeContent := []byte("# Read This First")
changelogContent := []byte("# CHANGELOG")
var sp *model.SearchParams
Expand Down Expand Up @@ -202,9 +202,9 @@ func TestCopy(t *testing.T) {
tmID_1 := copyListRes.Entries[0].Versions[0].TMID
tmID_2 := copyListRes.Entries[0].Versions[1].TMID
tmID_3 := copyListRes.Entries[0].Versions[2].TMID
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
_, tmContent2, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v3.2.1-20240409155220-3f779458e453.tm.json")
_, tmContent3, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v3.11.1-20240409155220-da7dbd7ed830.tm.json")
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
_, tmContent2, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v3.2.1-20240409155220-3f779458e453.tm.json")
_, tmContent3, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v3.11.1-20240409155220-da7dbd7ed830.tm.json")
readmeContent := []byte("# Read This First")
changelogContent := []byte("# CHANGELOG")
var sp *model.SearchParams
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestCopy(t *testing.T) {
rMocks.MockReposGet(t, rMocks.CreateMockGetFunctionFromList(t, []model.RepoSpec{sourceSpec, targetSpec}, []repos.Repo{source, target}, []error{nil, nil}))

tmid := copySingleListRes.Entries[0].Versions[0].TMID
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
var sp *model.SearchParams
source.On("List", mock.Anything, sp).Return(copySingleListRes, nil).Once()
source.On("Fetch", mock.Anything, tmid).Return(tmid, tmContent1, nil).Once()
Expand All @@ -304,7 +304,7 @@ func TestCopy(t *testing.T) {
rMocks.MockReposGet(t, rMocks.CreateMockGetFunctionFromList(t, []model.RepoSpec{sourceSpec, targetSpec}, []repos.Repo{source, target}, []error{nil, nil}))

tmid := copySingleListRes.Entries[0].Versions[0].TMID
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
var sp *model.SearchParams
source.On("List", mock.Anything, sp).Return(copySingleListRes, nil).Once()
source.On("Fetch", mock.Anything, tmid).Return(tmid, tmContent1, nil).Once()
Expand All @@ -329,7 +329,7 @@ func TestCopy(t *testing.T) {
rMocks.MockReposGet(t, rMocks.CreateMockGetFunctionFromList(t, []model.RepoSpec{sourceSpec, targetSpec}, []repos.Repo{source, target}, []error{nil, nil}))

tmid := copySingleListRes.Entries[0].Versions[0].TMID
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/index/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
_, tmContent1, _ := utils.ReadRequiredFile("../../../test/data/copy/omnicorp-tm-department/omnicorp/omnilamp/v0.0.0-20240409155220-80424c65e4e6.tm.json")
readmeContent := []byte("# Read This First")
var sp *model.SearchParams
source.On("List", mock.Anything, sp).Return(copySingleListRes, nil).Once()
Expand Down
7 changes: 6 additions & 1 deletion internal/app/http/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,30 +228,35 @@ func convertParams(params any) *model.SearchParams {
var filterAuthor *string
var filterManufacturer *string
var filterMpn *string
var filterProtocol *string
var filterName *string
var search *string

if invParams, ok := params.(server.GetInventoryParams); ok {
filterAuthor = invParams.FilterAuthor
filterManufacturer = invParams.FilterManufacturer
filterMpn = invParams.FilterMpn
filterProtocol = invParams.FilterProtocol
filterName = invParams.FilterName
search = invParams.Search
} else if authorsParams, ok := params.(server.GetAuthorsParams); ok {
filterManufacturer = authorsParams.FilterManufacturer
filterMpn = authorsParams.FilterMpn
filterProtocol = authorsParams.FilterProtocol
search = authorsParams.Search
} else if manParams, ok := params.(server.GetManufacturersParams); ok {
filterAuthor = manParams.FilterAuthor
filterMpn = manParams.FilterMpn
filterProtocol = manParams.FilterProtocol
search = manParams.Search
} else if mpnsParams, ok := params.(server.GetMpnsParams); ok {
filterAuthor = mpnsParams.FilterAuthor
filterManufacturer = mpnsParams.FilterManufacturer
filterProtocol = mpnsParams.FilterProtocol
search = mpnsParams.Search
}

return model.ToSearchParams(filterAuthor, filterManufacturer, filterMpn, filterName, search,
return model.ToSearchParams(filterAuthor, filterManufacturer, filterMpn, filterProtocol, filterName, search,
&model.SearchOptions{NameFilterType: model.PrefixMatch})
}

Expand Down
10 changes: 6 additions & 4 deletions internal/app/http/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,13 @@ func Test_Inventory(t *testing.T) {
fAuthors := "a1,a2"
fMan := "man1,man2"
fMpn := "mpn1,mpn2"
fProtos := "coap,https"
search := "foo"

filterRoute := fmt.Sprintf("%s?filter.author=%s&filter.manufacturer=%s&filter.mpn=%s&search=%s",
route, fAuthors, fMan, fMpn, search)
filterRoute := fmt.Sprintf("%s?filter.author=%s&filter.manufacturer=%s&filter.mpn=%s&filter.protocol=%s&search=%s",
route, fAuthors, fMan, fMpn, fProtos, search)
// and given: searchParams, expected to be converted from request query parameters
expectedSearchParams := model.ToSearchParams(&fAuthors, &fMan, &fMpn, nil, &search, &model.SearchOptions{NameFilterType: model.PrefixMatch})
expectedSearchParams := model.ToSearchParams(&fAuthors, &fMan, &fMpn, &fProtos, nil, &search, &model.SearchOptions{NameFilterType: model.PrefixMatch})

hs.On("ListInventory", mock.Anything, "", expectedSearchParams).Return(&listResult1, nil).Once()

Expand Down Expand Up @@ -332,7 +333,7 @@ func Test_Authors(t *testing.T) {
route, fMan, fMpn, search)

// and given: searchParams, expected to be converted from request query parameters
expectedSearchParams := model.ToSearchParams(nil, &fMan, &fMpn, nil, &search, &model.SearchOptions{NameFilterType: model.PrefixMatch})
expectedSearchParams := model.ToSearchParams(nil, &fMan, &fMpn, nil, nil, &search, &model.SearchOptions{NameFilterType: model.PrefixMatch})

hs.On("ListAuthors", mock.Anything, expectedSearchParams).Return(authors, nil).Once()

Expand Down Expand Up @@ -1471,6 +1472,7 @@ var (
Digest: "234d1b462fff",
TimeStamp: "20240107123001",
ExternalID: "ext-4",
Protocols: []string{"coaps", "https"},
AttachmentContainer: model.AttachmentContainer{
Attachments: []model.Attachment{
{
Expand Down
3 changes: 3 additions & 0 deletions internal/app/http/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func (m *Mapper) GetInventoryEntryVersion(version model.FoundVersion) server.Inv
}

invVersion.Links = &links
if len(version.Protocols) > 0 {
invVersion.Protocols = &version.Protocols
}

atts := m.GetAttachmentsList(model.NewTMIDAttachmentContainerRef(version.TMID), version.AttachmentContainer, version.FoundIn.RepoName)
if atts != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/app/http/mocks/HandlerService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 684e485

Please sign in to comment.