Skip to content

Commit

Permalink
fix: Adjust GetFileType() function for new secret URI format
Browse files Browse the repository at this point in the history
Closes #1504

Signed-off-by: Elizabeth J Lee <elizabeth.j.lee@intel.com>
  • Loading branch information
ejlee3 committed Sep 7, 2023
1 parent 44a516e commit f6709ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions internal/provision/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ const (
)

func GetFileType(fullPath string) FileType {
if strings.HasSuffix(fullPath, yamlExt) || strings.HasSuffix(fullPath, ymlExt) {
res := strings.Split(fullPath, "?")
if strings.HasSuffix(res[0], yamlExt) || strings.HasSuffix(res[0], ymlExt) {
return YAML
} else if strings.HasSuffix(fullPath, ".json") {
} else if strings.HasSuffix(res[0], ".json") {
return JSON
} else {
return OTHER
Expand All @@ -46,5 +47,6 @@ func GetFullAndRedactedURI(baseURI *url.URL, file, description string, lc logger
}
fullURI.User = baseURI.User
fullURI.Path = newPath
lc.Debugf("%s URI for %s: %s", description, file, fullURI.String())
return fullURI.String(), fullURI.Redacted()
}
6 changes: 6 additions & 0 deletions internal/provision/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func Test_GetFileType(t *testing.T) {
{"valid get Yaml file type", path.Join("..", "..", "example", "cmd", "device-simple", "res", "devices", "simple-device.yml"), YAML},
{"valid get Json file type", path.Join("..", "..", "example", "cmd", "device-simple", "res", "devices", "simple-device.json"), JSON},
{"valid get other file type", path.Join("..", "..", "example", "cmd", "device-simple", "res", "devices", "simple-device.bogus"), OTHER},
{"valid EdgeX Username/Password URI get Yaml file type", "http://edgexuser:edgexpasswd@httpd-auth:80/http_files/simple-device.yaml", YAML},
{"valid EdgeX Username/Password URI get Json file type", "http://edgexuser:edgexpasswd@httpd-auth:80/http_files/simple-device.json", JSON},
{"valid EdgeX Username/Password URI get other file type", "http://edgexuser:edgexpasswd@httpd-auth:80/http_files/simple-device.bogus", OTHER},
{"valid EdgeX Secret URI get Yaml file type", "http://httpd-auth:80/http_files/simple-device.yaml?edgexSecretName=httpserver", YAML},
{"valid EdgeX Secret URI get Json file type", "http://httpd-auth:80/http_files/simple-device.json?edgexSecretName=httpserver", JSON},
{"valid EdgeX Secret URI get other file type", "http://httpd-auth:80/http_files/simple-device.bogus?edgexSecretName=httpserver", OTHER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion internal/provision/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ func loadProfilesFromURI(inputURI string, parsedURI *url.URL, dpc interfaces.Dev
func processProfiles(fullPath, displayPath string, secretProvider bootstrapInterfaces.SecretProvider, lc logger.LoggingClient, dpc interfaces.DeviceProfileClient) ([]requests.DeviceProfileRequest, errors.EdgeX) {
var profile dtos.DeviceProfile
var addProfilesReq []requests.DeviceProfileRequest

fileType := GetFileType(fullPath)

// if the file type is not yaml or json, it cannot be parsed - just return to not break the loop for other devices
Expand Down

0 comments on commit f6709ff

Please sign in to comment.