diff --git a/cicd-integration/.thy.yml b/cicd-integration/.thy.yml index 6a11a26e..42a74cb3 100644 --- a/cicd-integration/.thy.yml +++ b/cicd-integration/.thy.yml @@ -19,6 +19,3 @@ local: domain: {{.LOCAL_DOMAIN}} http: http tenant: {{.TEST_TENANT}} - - - diff --git a/commands/conf b/commands/conf deleted file mode 100644 index 27ba77dd..00000000 --- a/commands/conf +++ /dev/null @@ -1 +0,0 @@ -true diff --git a/inittests/input/change_password_pass b/inittests/input/change_password_pass deleted file mode 100644 index a0da5d18..00000000 --- a/inittests/input/change_password_pass +++ /dev/null @@ -1,4 +0,0 @@ -./[INIT_CLINAME] auth change-password --config configs/base_modified.yml -[INIT_DEV_PASSWORD] -Str@ngT3mpPass -Str@ngT3mpPass \ No newline at end of file diff --git a/utils/path.go b/utils/path.go deleted file mode 100644 index c911f384..00000000 --- a/utils/path.go +++ /dev/null @@ -1,164 +0,0 @@ -package utils - -import ( - "fmt" - "log" - "strings" - cst "thy/constants" - "thy/errors" - - "github.com/thycotic-rd/viper" -) - -func GetInternalPathFromURIPath(uriPath string) string { - path := strings.Replace(uriPath, "/", ":", -1) - if strings.Index(path, ":") == 0 { - path = path[1:] - } - if strings.Index(path, cst.PrefixEntityInternal) < 0 { - path = cst.PrefixEntityInternal + path - } - return path -} - -func GetURIPathFromInternalPath(internalPath string) string { - path := strings.Replace(internalPath, ":", "/", -1) - if strings.Index(path, "/") == 0 { - path = path[1:] - } - if strings.Index(path, cst.PrefixEntity) == 0 { - path = path[len(cst.PrefixEntity):] - } - return path -} - -func GetPermissionURIFromPermissionPath(resourceType string, path string, id string, suffix string) (string, *errors.ApiError) { - if path == "" { - path = "<.*>" - } - if strings.HasSuffix(resourceType, "s") { - resourceType = resourceType[:len(resourceType)-1] - } - resourceType = strings.ToLower(resourceType) - return GetResourceURIFromResourcePath(resourceType, path, id, suffix, true, nil) -} - -func GetResourceURIFromResourcePath(resourceType string, path string, id string, suffix string, trailingSlash bool, queryTerms map[string]string) (string, *errors.ApiError) { - if id != "" && path != "" { - return "", errors.NewS("error: only one of --id and --path (or [path]) may be set") - } - if path == "" && id == "" { - return "", errors.NewS("error: must specify --id or --path (or [path])") - } - - var resourcePath string - if path != "" { - resourcePath = GetURIPathFromInternalPath(path) - } - - requestURI := CreateResourceURI(resourceType, resourcePath, suffix, trailingSlash, queryTerms, true) - if id != "" { - requestURI = requestURI + fmt.Sprintf("?id=%s", id) - } - return requestURI, nil -} - -func CreateResourceURI(resourceType string, path string, suffix string, trailingSlash bool, queryTerms map[string]string, pluralize bool) string { - var completePath string - plural := "s" - if !pluralize { - plural = "" - } - if trailingSlash { - completePath = fmt.Sprintf("%s%s/%s%s", resourceType, plural, path, suffix) - } else { - completePath = fmt.Sprintf("%s%s%s%s", resourceType, plural, path, suffix) - } - - return CreateURI(completePath, queryTerms) -} - -func CreateURI(path string, queryTerms map[string]string) string { - httpScheme := cst.HTTPSchemeSecure - if httpSchemeOverride := viper.GetString(cst.HTTPSchemeKey); httpSchemeOverride != "" { - httpScheme = httpSchemeOverride - } - - domain := GetDomain() - port := GetPort() - apiVersion := GetAPIVersion() - - uri := fmt.Sprintf("%s://%s.%s%s/%s/%s", httpScheme, viper.Get(cst.Tenant), domain, port, apiVersion, path) - if queryTerms != nil { - first := true - for k, v := range queryTerms { - if first { - first = false - uri = uri + "?" - } else { - uri = uri + "&" - } - uri = uri + fmt.Sprintf("%s=%s", k, v) - } - } - log.Printf("Request URI is %s\n", uri) - return uri -} - -func GetPath(args []string) string { - path := viper.GetString(cst.Path) - if len(args) > 0 { - path = args[0] - } - return path -} - -func GetDomain() string { - domain := cst.Domain - if domainOverride := viper.GetString(cst.DomainKey); domainOverride != "" { - domain = domainOverride - } - return domain -} - -func GetPort() string { - port := "" - if portOverride := viper.GetString(cst.PortKey); portOverride != "" { - port = ":" + portOverride - } - return port -} - -func GetAPIVersion() string { - ver := cst.APIVersion - if verOverride := viper.GetString(cst.APIVersionKey); verOverride != "" { - ver = verOverride - } - return ver -} - -// GetFilenameFromArgs tries to extract a filename from args. If args has a --data or -d flag and -// its value starts with an '@' followed by a filename, the function tries to capture that filename. -func GetFilenameFromArgs(args []string) string { - var fileName string - for i := range args { - if args[i] == "--data" || args[i] == "-d" { - value := args[i+1] - if strings.HasPrefix(value, "@") { - fileName = value[1:] - } - break - } - } - return fileName -} - -// GetDefault tries to parse the flag and if it is blank it gets the first item in the args -// Use for the default first parameter, like path, name, username, etc... -func GetDefault(args []string, flagName string) string { - val := viper.GetString(flagName) - if val == "" && len(args) > 0 { - val = args[0] - } - return val -} diff --git a/utils/path_test.go b/utils/path_test.go deleted file mode 100644 index 1d9e9fb2..00000000 --- a/utils/path_test.go +++ /dev/null @@ -1,238 +0,0 @@ -package utils - -import ( - "testing" - - cst "thy/constants" - - "github.com/stretchr/testify/assert" - "github.com/thycotic-rd/viper" -) - -func TestGetAPIVersion(t *testing.T) { - tests := []struct { - name string - mockAPIVersion interface{} - expected string - }{ - { - name: "Default_Path", - expected: "v1", - }, - { - name: "Happy_Path", - mockAPIVersion: "v2", - expected: "v2", - }, - { - name: "Happy_Path#01", - mockAPIVersion: 12313, - expected: "12313", - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - - viper.Set(cst.APIVersionKey, test.mockAPIVersion) - - actual := GetAPIVersion() - assert.Equal(t, test.expected, actual) - }) - } -} - -func TestGetPort(t *testing.T) { - tests := []struct { - name string - mockAPIVersion interface{} - expected string - }{ - { - name: "Default_Path", - expected: "", - }, - { - name: "Happy_Path", - mockAPIVersion: "8089", - expected: ":8089", - }, - { - name: "Happy_Path#01", - mockAPIVersion: 9192, - expected: ":9192", - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - - viper.Set(cst.PortKey, test.mockAPIVersion) - - actual := GetPort() - assert.Equal(t, test.expected, actual) - }) - } -} - -func TestGetDomain(t *testing.T) { - tests := []struct { - name string - mockAPIVersion interface{} - expected string - }{ - { - name: "Default_Path", - expected: "secretsvaultcloud.com", - }, - { - name: "Happy_Path", - mockAPIVersion: "test.com", - expected: "test.com", - }, - { - name: "Happy_Path#01", - mockAPIVersion: 9192, - expected: "9192", - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - - viper.Set(cst.DomainKey, test.mockAPIVersion) - - actual := GetDomain() - assert.Equal(t, test.expected, actual) - }) - } -} - -func TestGetPath(t *testing.T) { - tests := []struct { - name string - input []string - mockAPIVersion interface{} - expected string - }{ - { - name: "Default_Path", - expected: "", - }, - { - name: "Happy_Path", - mockAPIVersion: "test", - expected: "test", - }, - { - name: "Happy_Path#01", - input: []string{"com"}, - mockAPIVersion: "test", - expected: "com", - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - - viper.Set(cst.Path, test.mockAPIVersion) - - actual := GetPath(test.input) - assert.Equal(t, test.expected, actual) - }) - } -} - -func TestCreateURI(t *testing.T) { - tests := []struct { - name string - path string - queryTerms map[string]string - mockHTTPSchemeKey interface{} - mockTenant interface{} - mockAPIVersionKey interface{} - mockPortKey interface{} - mockDomainKey interface{} - expected string - }{ - { - name: "Default_Path", - expected: "https://%!s().secretsvaultcloud.com/v1/", - }, - { - name: "HTTPSchemeKey", - mockHTTPSchemeKey: "http", - expected: "http://%!s().secretsvaultcloud.com/v1/", - }, - { - name: "APIVersionKey", - mockHTTPSchemeKey: "http", - mockAPIVersionKey: "v2", - expected: "http://%!s().secretsvaultcloud.com/v2/", - }, - { - name: "PortKey", - mockHTTPSchemeKey: "http", - mockAPIVersionKey: "v2", - mockPortKey: "8080", - expected: "http://%!s().secretsvaultcloud.com:8080/v2/", - }, - { - name: "DomainKey", - mockHTTPSchemeKey: "http", - mockAPIVersionKey: "v2", - mockPortKey: "8080", - mockDomainKey: "secretsvaultcloud", - expected: "http://%!s().secretsvaultcloud:8080/v2/", - }, - { - name: "Tenant", - mockHTTPSchemeKey: "http", - mockAPIVersionKey: "v2", - mockPortKey: "8080", - mockDomainKey: "secretsvaultcloud.com", - mockTenant: "www", - expected: "http://www.secretsvaultcloud.com:8080/v2/", - }, - { - name: "Path", - path: "path", - mockHTTPSchemeKey: "http", - mockAPIVersionKey: "v2", - mockPortKey: "8080", - mockDomainKey: "secretsvaultcloud.com", - mockTenant: "www", - expected: "http://www.secretsvaultcloud.com:8080/v2/path", - }, - { - name: "QueryTerms", - path: "path", - queryTerms: map[string]string{}, - mockHTTPSchemeKey: "http", - mockAPIVersionKey: "v2", - mockPortKey: "8080", - mockDomainKey: "secretsvaultcloud.com", - mockTenant: "www", - expected: "http://www.secretsvaultcloud.com:8080/v2/path", - }, - { - name: "QueryTerms#01", - path: "path", - queryTerms: map[string]string{"query1": "query1"}, - mockHTTPSchemeKey: "http", - mockAPIVersionKey: "v2", - mockPortKey: "8080", - mockDomainKey: "secretsvaultcloud.com", - mockTenant: "www", - expected: "http://www.secretsvaultcloud.com:8080/v2/path?query1=query1", - }, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - viper.Set(cst.HTTPSchemeKey, test.mockHTTPSchemeKey) - viper.Set(cst.Tenant, test.mockTenant) - viper.Set(cst.APIVersionKey, test.mockAPIVersionKey) - viper.Set(cst.PortKey, test.mockPortKey) - viper.Set(cst.DomainKey, test.mockDomainKey) - - actual := CreateURI(test.path, test.queryTerms) - assert.Equal(t, test.expected, actual) - }) - } -}