Skip to content

Commit

Permalink
Make improvements to be able to use Resource structure fields (#210)
Browse files Browse the repository at this point in the history
[#209] Make improvements to be able to use Resource structure fields

Signed-off-by: Antonia Avramova <[email protected]>
  • Loading branch information
antonia-avramova authored Mar 20, 2023
1 parent d6e3637 commit fb02c52
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions integration/util/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (

// Resource holds all needed properties to create resources for the device.
type Resource struct {
url string
URL string

method string
body string
Method string
Body string

user string
pass string
User string
Pass string

delete bool
Delete bool
}

// BootstrapConfiguration holds the required configuration to suite bootstrapping to connect and
Expand Down Expand Up @@ -64,25 +64,25 @@ func CreateDeviceResources(newDeviceID, tenantID, policyID, password, registryAP
devicePath := tenantID + "/" + newDeviceID
return []*Resource{
&Resource{
url: registryAPI + "/devices/" + devicePath,
method: http.MethodPost,
body: `{"authorities":["auto-provisioning-enabled"]}`,
user: registryAPIUsername,
pass: registryAPIPassword,
delete: true},
URL: registryAPI + "/devices/" + devicePath,
Method: http.MethodPost,
Body: `{"authorities":["auto-provisioning-enabled"]}`,
User: registryAPIUsername,
Pass: registryAPIPassword,
Delete: true},
&Resource{
url: registryAPI + "/credentials/" + devicePath,
method: http.MethodPut,
body: getCredentialsBody(strings.ReplaceAll(newDeviceID, ":", "_"), password),
user: registryAPIUsername,
pass: registryAPIPassword},
URL: registryAPI + "/credentials/" + devicePath,
Method: http.MethodPut,
Body: getCredentialsBody(strings.ReplaceAll(newDeviceID, ":", "_"), password),
User: registryAPIUsername,
Pass: registryAPIPassword},
&Resource{
url: GetThingURL(cfg.DigitalTwinAPIAddress, newDeviceID),
method: http.MethodPut,
body: fmt.Sprintf(`{"policyId": "%s"}`, policyID),
user: cfg.DigitalTwinAPIUsername,
pass: cfg.DigitalTwinAPIPassword,
delete: true},
URL: GetThingURL(cfg.DigitalTwinAPIAddress, newDeviceID),
Method: http.MethodPut,
Body: fmt.Sprintf(`{"policyId": "%s"}`, policyID),
User: cfg.DigitalTwinAPIUsername,
Pass: cfg.DigitalTwinAPIPassword,
Delete: true},
}
}

Expand Down Expand Up @@ -113,8 +113,8 @@ func DeleteResources(cfg *TestConfiguration, resources []*Resource, deviceID, ur
for i := len(resources) - 1; i >= 0; i-- {
r := resources[i]

if r.delete {
if _, err := SendDeviceRegistryRequest(nil, http.MethodDelete, r.url, r.user, r.pass); err != nil {
if r.Delete {
if _, err := SendDeviceRegistryRequest(nil, http.MethodDelete, r.URL, r.User, r.Pass); err != nil {
errors = append(errors, err)
}
}
Expand Down

0 comments on commit fb02c52

Please sign in to comment.