-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: Added URL Param Parsing for better security (#33) Signed-off-by: Soorya U <[email protected]> * feat: added function to extract content from the yaml file (#34) --------- Signed-off-by: Soorya U <[email protected]> Co-authored-by: Soorya U <[email protected]> Co-authored-by: Kushal Jetty <[email protected]>
- Loading branch information
1 parent
f4a8de9
commit 9f4c569
Showing
5 changed files
with
106 additions
and
4 deletions.
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
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,50 @@ | ||
package initializers | ||
|
||
import ( | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
// YMLConfig represents the overall structure of the YAML | ||
type YMLConfig struct { | ||
Configuration ymlConfiguration `yaml:"configuration"` | ||
Environment ymlEnvironment `yaml:"environment"` | ||
Caching ymlCaching `yaml:"caching"` | ||
} | ||
|
||
// Configuration holds the YAML configuration fields | ||
type ymlConfiguration struct { | ||
TestDirectory string `yaml:"test-directory"` | ||
Comments string `yaml:"comments"` | ||
TestingBranch string `yaml:"testing-branch"` | ||
TestingFramework string `yaml:"testing-framework"` | ||
WaterMark string `yaml:"water-mark"` | ||
} | ||
|
||
// Environment holds environment-specific configurations | ||
type ymlEnvironment struct { | ||
PythonVersion string `yaml:"python-version"` | ||
} | ||
|
||
// Caching holds caching-related configurations | ||
type ymlCaching struct { | ||
Enabled bool `yaml:"enabled"` | ||
RedisCaching string `yaml:"redis-caching"` | ||
} | ||
|
||
// FetchAndReturnYAMLContents fetches YAML contents and returns it as a structure | ||
func FetchAndReturnYAMLContents(owner, repo, commitSHA, filePath string) (YMLConfig, error) { | ||
// Fetch the file content from GitHub | ||
content, err := FetchFileContentFromGitHub(owner, repo, commitSHA, filePath) | ||
if err != nil { | ||
return YMLConfig{}, err | ||
} | ||
|
||
// Parse YAML content | ||
var config YMLConfig | ||
err = yaml.Unmarshal([]byte(content), &config) | ||
if err != nil { | ||
return YMLConfig{}, err | ||
} | ||
|
||
return config, nil | ||
} |
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,20 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"regexp" | ||
) | ||
|
||
func CleanURLParams(owner, repo string, prNumber int) (string, string, error) { | ||
owner = url.QueryEscape(owner) | ||
repo = url.QueryEscape(repo) | ||
|
||
githubNameRegex := regexp.MustCompile(`^[a-zA-Z0-9-]+$`) | ||
|
||
if !githubNameRegex.MatchString(owner) || !githubNameRegex.MatchString(repo) || prNumber <= 0 { | ||
return "", "", fmt.Errorf("unable to clean url params") | ||
} | ||
|
||
return owner, repo, nil | ||
} |