Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deviceregistration): support security tokens, group assignment and templates #433

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions api/spec/json/deviceCredentials.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,28 @@
"afterEach": [
"Remove-DeviceRequest -Id \"ASDF098SD1J10912UD92JDLCNCU8\""
]
},
{
"description": "Register a new device",
"command": "Register-Device -Id \"ASDF098SD1J10912UD92JDLCNCU8\" -Group \"My Group\"",
"skipTest": true
}
],
"go": [
{
"description": "Register a new device",
"command": "c8y deviceregistration register --id \"ASDF098SD1J10912UD92JDLCNCU8\""
},
{
"description": "Register a new device and assign to a group",
"command": "c8y deviceregistration register --id \"ASDF098SD1J10912UD92JDLCNCU8\" --group \"My Group\"",
"assertStdOut": {
"json": {
"path": "/devicecontrol/newDeviceRequests",
"body.id": "ASDF098SD1J10912UD92JDLCNCU8",
"body.groupId": "r/^\\d+$"
}
}
}
]
},
Expand All @@ -117,6 +133,22 @@
"required": true,
"pipeline": true,
"description": "Device identifier. Max: 1000 characters. E.g. IMEI"
},
{
"name": "type",
"type": "string",
"description": "Type of the device"
},
{
"name": "group",
"property": "groupId",
"type": "devicegroup[]",
"description": "Group to which the device will be assigned"
},
{
"name": "data",
"type": "json",
"description": "Additional properties"
}
]
},
Expand Down Expand Up @@ -144,12 +176,21 @@
"afterEach": [
"Remove-DeviceRequest -Id $DeviceRequest.id"
]
},
{
"description": "Approve a new device request and provide a security token",
"skipTest": true,
"command": "Approve-DeviceRequest -Id $DeviceRequest.id -SecurityToken \"abcdef123456\""
}
],
"go": [
{
"description": "Approve a new device request",
"command": "c8y deviceregistration approve --id \"1234010101s01ldk208\""
},
{
"description": "Approve a new device request and provide a security token",
"command": "c8y deviceregistration approve --id \"1234010101s01ldk208\" --securityToken \"abcdef123456\""
}
]
},
Expand All @@ -172,6 +213,16 @@
"validationSet": [
"ACCEPTED"
]
},
{
"name": "securityToken",
"type": "string",
"description": "When accepting a device request, the security token is verified against the token submitted by the device when requesting credentials"
},
{
"name": "data",
"type": "json",
"description": "Additional properties"
}
],
"bodyTemplates": [
Expand Down Expand Up @@ -228,6 +279,7 @@
"descriptionLong": "Device credentials can be enquired by devices that do not have credentials for accessing a tenant yet. Since the device does not have credentials yet, a set of fixed credentials is used for this API. The credentials can be obtained by contacting support. Do not use your tenant credentials with this API.",
"path": "devicecontrol/deviceCredentials",
"accept": "application/vnd.com.nsn.cumulocity.deviceCredentials+json",
"semanticMethod": "GET",
"alias": {
"go": "getCredentials",
"powershell": "Request-DeviceCredentials"
Expand Down Expand Up @@ -257,6 +309,11 @@
"required": true,
"pipeline": true,
"description": "Device identifier. Max: 1000 characters. E.g. IMEI"
},
{
"name": "data",
"type": "json",
"description": "Additional properties"
}
]
}
Expand Down
46 changes: 46 additions & 0 deletions api/spec/yaml/deviceCredentials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,41 @@ commands:
afterEach:
- Remove-DeviceRequest -Id "ASDF098SD1J10912UD92JDLCNCU8"

- description: Register a new device
command: Register-Device -Id "ASDF098SD1J10912UD92JDLCNCU8" -Group "My Group"
skipTest: true

go:
- description: Register a new device
command: c8y deviceregistration register --id "ASDF098SD1J10912UD92JDLCNCU8"

- description: Register a new device and assign to a group
command: c8y deviceregistration register --id "ASDF098SD1J10912UD92JDLCNCU8" --group "My Group"
assertStdOut:
json:
path: /devicecontrol/newDeviceRequests
body.id: ASDF098SD1J10912UD92JDLCNCU8
body.groupId: r/^\d+$
body:
- name: id
type: id[]
required: true
pipeline: true
description: 'Device identifier. Max: 1000 characters. E.g. IMEI'

- name: type
type: string
description: Type of the device

- name: group
property: groupId
type: devicegroup[]
description: Group to which the device will be assigned

- name: data
type: json
description: Additional properties

- name: approveNewDeviceRequest
method: PUT
description: Approve device request
Expand All @@ -107,10 +132,18 @@ commands:
command: Approve-DeviceRequest -Id $DeviceRequest.id
afterEach:
- Remove-DeviceRequest -Id $DeviceRequest.id

- description: Approve a new device request and provide a security token
skipTest: true # todo: requests usage of the device bootstrap user
command: Approve-DeviceRequest -Id $DeviceRequest.id -SecurityToken "abcdef123456"

go:
- description: Approve a new device request
command: c8y deviceregistration approve --id "1234010101s01ldk208"

- description: Approve a new device request and provide a security token
command: c8y deviceregistration approve --id "1234010101s01ldk208" --securityToken "abcdef123456"

pathParameters:
- name: id
type: devicerequest[]
Expand All @@ -124,6 +157,14 @@ commands:
description: 'Status of registration'
default: ""
validationSet: [ACCEPTED]

- name: securityToken
type: string
description: When accepting a device request, the security token is verified against the token submitted by the device when requesting credentials

- name: data
type: json
description: Additional properties
bodyTemplates:
- type: jsonnet
applyLast: false
Expand Down Expand Up @@ -163,6 +204,7 @@ commands:
descriptionLong: 'Device credentials can be enquired by devices that do not have credentials for accessing a tenant yet. Since the device does not have credentials yet, a set of fixed credentials is used for this API. The credentials can be obtained by contacting support. Do not use your tenant credentials with this API.'
path: devicecontrol/deviceCredentials
accept: application/vnd.com.nsn.cumulocity.deviceCredentials+json
semanticMethod: GET
alias:
go: getCredentials
powershell: Request-DeviceCredentials
Expand All @@ -183,3 +225,7 @@ commands:
required: true
pipeline: true
description: 'Device identifier. Max: 1000 characters. E.g. IMEI'

- name: data
type: json
description: Additional properties
8 changes: 7 additions & 1 deletion pkg/cmd/deviceregistration/approve/approve.auto.go

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

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

12 changes: 11 additions & 1 deletion pkg/cmd/deviceregistration/register/register.auto.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ tests:
json:
method: PUT
path: /devicecontrol/newDeviceRequests/1234010101s01ldk208
deviceregistration_approve_Approve a new device request and provide a security token:
command: c8y deviceregistration approve --id "1234010101s01ldk208" --securityToken "abcdef123456"
exit-code: 0
stdout:
json:
body.securityToken: abcdef123456
method: PUT
path: /devicecontrol/newDeviceRequests/1234010101s01ldk208
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ tests:
body.id: ASDF098SD1J10912UD92JDLCNCU8
method: POST
path: /devicecontrol/newDeviceRequests
deviceregistration_register_Register a new device and assign to a group:
command: c8y deviceregistration register --id "ASDF098SD1J10912UD92JDLCNCU8" --group "My Group"
exit-code: 0
stdout:
json:
body.groupId: r/^\d+$
body.id: ASDF098SD1J10912UD92JDLCNCU8
method: POST
path: /devicecontrol/newDeviceRequests
12 changes: 11 additions & 1 deletion tools/PSc8y/Public/Approve-DeviceRequest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ PS> Approve-DeviceRequest -Id $DeviceRequest.id

Approve a new device request

.EXAMPLE
PS> Approve-DeviceRequest -Id $DeviceRequest.id -SecurityToken "abcdef123456"

Approve a new device request and provide a security token


#>
[cmdletbinding(PositionalBinding=$true,
Expand All @@ -33,7 +38,12 @@ Approve a new device request
[Parameter()]
[ValidateSet('ACCEPTED')]
[string]
$Status
$Status,

# When accepting a device request, the security token is verified against the token submitted by the device when requesting credentials
[Parameter()]
[string]
$SecurityToken
)
DynamicParam {
Get-ClientCommonParameters -Type "Update", "Template"
Expand Down
17 changes: 16 additions & 1 deletion tools/PSc8y/Public/Register-Device.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ PS> Register-Device -Id "ASDF098SD1J10912UD92JDLCNCU8"

Register a new device

.EXAMPLE
PS> Register-Device -Id "ASDF098SD1J10912UD92JDLCNCU8" -Group "My Group"

Register a new device


#>
[cmdletbinding(PositionalBinding=$true,
Expand All @@ -27,7 +32,17 @@ Register a new device
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[object[]]
$Id
$Id,

# Type of the device
[Parameter()]
[string]
$Type,

# Group to which the device will be assigned
[Parameter()]
[object[]]
$Group
)
DynamicParam {
Get-ClientCommonParameters -Type "Create", "Template"
Expand Down
6 changes: 6 additions & 0 deletions tools/PSc8y/Tests/Approve-DeviceRequest.auto.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Describe -Name "Approve-DeviceRequest" {
$Response | Should -Not -BeNullOrEmpty
}

It -Skip "Approve a new device request and provide a security token" {
$Response = PSc8y\Approve-DeviceRequest -Id $DeviceRequest.id -SecurityToken "abcdef123456"
$LASTEXITCODE | Should -Be 0
$Response | Should -Not -BeNullOrEmpty
}


AfterEach {
Remove-DeviceRequest -Id $DeviceRequest.id
Expand Down
Loading