-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace s3:// urls with signed urls for metal.server (#51)
When creating the bootscript bss will now convert s3:// urls to signed urls. This conversion is done for the params field for the metal.server field. For example, it will convert the following to a signed url: 'metal.server=s3://bucket/path' It will leave other s3 uris alone. For example this will remain untouched: 'root=craycps-s3:s3://boot-images/2b63caf8' Jira: CASMHMS-5656
- Loading branch information
Showing
4 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.19.0 | ||
1.20.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// MIT License | ||
// | ||
// (C) Copyright [2022] Hewlett Packard Enterprise Development LP | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a | ||
// copy of this software and associated documentation files (the "Software"), | ||
// to deal in the Software without restriction, including without limitation | ||
// the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
// and/or sell copies of the Software, and to permit persons to whom the | ||
// Software is furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | ||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
// OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
) | ||
|
||
func mockGetSignedS3Url(s3Url string) (string, error) { | ||
return s3Url + "_signed", nil | ||
} | ||
|
||
func mockGetSignedS3UrlError(s3Url string) (string, error) { | ||
return s3Url, fmt.Errorf("error") | ||
} | ||
|
||
func TestReplaceS3Params_regex(t *testing.T) { | ||
r, err := regexp.Compile(s3ParamsRegex) | ||
if err != nil { | ||
t.Errorf("Failed to compile the regex: %s, error: %v\n", s3ParamsRegex, err) | ||
return | ||
} | ||
params := fmt.Sprintf("%s%s", | ||
"metal.server=s3://b1/p1/p2", | ||
" metal.server=s3://b2/p1/p2") | ||
|
||
expected := [][]string{ | ||
[]string{ | ||
"metal.server=s3://b1/p1/p2", | ||
"", | ||
"metal.server=s3://b1/p1/p2", | ||
"metal.server=", | ||
"s3://b1/p1/p2", | ||
}, | ||
[]string{ | ||
" metal.server=s3://b2/p1/p2", | ||
" ", | ||
"metal.server=s3://b2/p1/p2", | ||
"metal.server=", | ||
"s3://b2/p1/p2", | ||
}, | ||
} | ||
|
||
matches := r.FindAllStringSubmatch(params, -1) | ||
if len(matches) != 2 { | ||
t.Errorf("Failed expected two matches for: %s, using: %s\n", params, s3ParamsRegex) | ||
return | ||
} | ||
|
||
for i, match := range matches { | ||
if len(match) != 5 { | ||
t.Errorf("Failed. Expected %d match to have 5. groups: %v, params: %s\n", i, match, params) | ||
return | ||
} | ||
for j, group := range match { | ||
if group != expected[i][j] { | ||
t.Errorf("Failed wrong string for match %d group %d. expected: '%s', actual: '%s'\n", | ||
i, j, expected[i][j], group) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestReplaceS3Params_replace(t *testing.T) { | ||
params := fmt.Sprintf("%s %s %s %s %s", | ||
"metal.server=s3://ncn-images/k8s/0.2.78/filesystem.squashfs", | ||
"bond=bond0", | ||
"metal.server=s3://bucket/path", | ||
"root=craycps-s3:s3://boot-images", | ||
"m=s3://b/p") | ||
|
||
expected_params := fmt.Sprintf("%s %s %s %s %s", | ||
"metal.server=s3://ncn-images/k8s/0.2.78/filesystem.squashfs_signed", | ||
"bond=bond0", | ||
"metal.server=s3://bucket/path_signed", | ||
"root=craycps-s3:s3://boot-images", | ||
"m=s3://b/p") | ||
|
||
newParams, err := replaceS3Params(params, mockGetSignedS3Url) | ||
if err != nil { | ||
t.Errorf("replaceS3Params returned an error for params: %s, error: %v\n", params, err) | ||
} | ||
if newParams != expected_params { | ||
t.Errorf("replaceS3Params failed.\n expected: %s\n actual: %s\n", expected_params, newParams) | ||
} | ||
} | ||
|
||
func TestReplaceS3Params_replace2(t *testing.T) { | ||
params := fmt.Sprintf("%s %s", | ||
"xmetal.server=s3://ncn-images/k8s/0.2.78/filesystem.squashfs", | ||
"metal.server=s3://ncn-images/k8s/0.2.78/filesystem.squashfs") | ||
expected_params := fmt.Sprintf("%s %s", | ||
"xmetal.server=s3://ncn-images/k8s/0.2.78/filesystem.squashfs", | ||
"metal.server=s3://ncn-images/k8s/0.2.78/filesystem.squashfs_signed") | ||
|
||
newParams, err := replaceS3Params(params, mockGetSignedS3Url) | ||
if err != nil { | ||
t.Errorf("replaceS3Params returned an error for params: %s, error: %v\n", params, err) | ||
} | ||
if newParams != expected_params { | ||
t.Errorf("replaceS3Params failed.\n expected: %s\n actual: %s\n", expected_params, newParams) | ||
} | ||
} | ||
|
||
func TestReplaceS3Params_no_replace(t *testing.T) { | ||
// This test expects the string to remain unchanged | ||
params := fmt.Sprintf( | ||
"%s %s %s %s %s", | ||
"made_up_key=s3://ncn-images/path", | ||
"xmetal.server=s3://ncn-images/k8s/0.2.78/filesystem.squashfs", | ||
"nmd_data=url=s3://boot-images/bb-86/rootfs,etag=c8-204", | ||
"bos_update_frequency=4h", | ||
"root=craycps-s3:s3://boot-images/bb-78/rootfs:c8-204:dvs:api-gw-service-nmn.local:300:hsn0,nmn0:0") | ||
expected_params := params | ||
|
||
newParams, err := replaceS3Params(params, mockGetSignedS3Url) | ||
if err != nil { | ||
t.Errorf("replaceS3Params returned an error for params: %s, error: %v\n", params, err) | ||
} | ||
if newParams != expected_params { | ||
t.Errorf("replaceS3Params failed.\n expected: %s\n actual: %s\n", expected_params, newParams) | ||
} | ||
} | ||
|
||
func TestReplaceS3Params_error(t *testing.T) { | ||
params := "bond=bond0 metal.server=s3://bucket/path" | ||
expected_params := params | ||
newParams, err := replaceS3Params(params, mockGetSignedS3UrlError) | ||
if err == nil { | ||
t.Errorf("replaceS3Params failed to return an error when using mock that injects an error. params: %s\n", params) | ||
} | ||
if newParams != expected_params { | ||
t.Errorf("replaceS3Params failed.\n expected: %s\n actual: %s\n", expected_params, newParams) | ||
} | ||
} |