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

fix: Adjust GetFileType() function for new secret URI format #1507

Merged
merged 1 commit into from
Sep 8, 2023
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
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