Skip to content

Commit

Permalink
Add check to verify email address providedd for snapshot
Browse files Browse the repository at this point in the history
Signed-off-by: Eti Ijeoma <ijayeti@gmail.com>
  • Loading branch information
Aijeyomah committed Oct 11, 2024
1 parent 569ddcf commit f7fa548
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/kanvas-snapshot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"os"
"path/filepath"
"regexp"
"strings"
"time"

Expand All @@ -31,6 +32,8 @@ var (
designName string
)

var emailRegex = regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,}$`)

var generateKanvasSnapshotCmd = &cobra.Command{
Use: "kanvas",
Short: "Generate a Kanvas snapshot using a Helm chart",
Expand Down Expand Up @@ -255,6 +258,10 @@ func GenerateSnapshot(designID, chartURI, email, assetLocation string) error {
return nil
}

func isValidEmail(email string) bool {
return emailRegex.MatchString(email)
}

func main() {

generateKanvasSnapshotCmd.Flags().StringVarP(&chartURI, "file", "f", "", "URI to Helm chart (required)")
Expand Down
19 changes: 19 additions & 0 deletions internal/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import (
)

var (
<<<<<<< Updated upstream

Check failure on line 10 in internal/errors/error.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21, ubuntu-22.04)

syntax error: unexpected <<, expected name

Check failure on line 10 in internal/errors/error.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21, ubuntu-22.04)

expected 'IDENT', found '<<' (typecheck)
ErrInvalidChartURICode = "kanvas-snapshot-900"
ErrCreatingMesheryDesignCode = "kanvas-snapshot-901"
ErrGeneratingSnapshotCode = "kanvas-snapshot-902"
ErrHTTPPostRequestCode = "kanvas-snapshot-903"
ErrDecodingAPICode = "kanvas-snapshot-905"
ErrUnexpectedResponseCodeCode = "kanvas-snapshot-906"
ErrRequiredFieldNotProvidedCode = "kanvas-snapshot-907"
=======

Check failure on line 18 in internal/errors/error.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21, ubuntu-22.04)

syntax error: unexpected ==, expected name

Check failure on line 18 in internal/errors/error.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21, ubuntu-22.04)

expected 'IDENT', found '==' (typecheck)
ErrInvalidChartURICode = "kanvas-snapshot-900"
ErrCreatingMesheryDesignCode = "kanvas-snapshot-901"
ErrGeneratingSnapshotCode = "kanvas-snapshot-902"
ErrHTTPPostRequestCode = "kanvas-snapshot-903"
ErrDecodingAPICode = "kanvas-snapshot-905"
ErrUnexpectedResponseCodeCode = "kanvas-snapshot-906"
ErrInvalidEmailFormatCode = "kanvas-snapshot-907"
>>>>>>> Stashed changes

Check failure on line 26 in internal/errors/error.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21, ubuntu-22.04)

syntax error: unexpected >>, expected name

Check failure on line 26 in internal/errors/error.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21, ubuntu-22.04)

expected 'IDENT', found '>>' (typecheck)
)

func ErrInvalidChartURI(err error) error {
Expand Down Expand Up @@ -70,11 +80,20 @@ func ErrUnexpectedResponseCode(statusCode int, body string) error {
)
}

<<<<<<< Updated upstream

Check failure on line 83 in internal/errors/error.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21, ubuntu-22.04)

syntax error: non-declaration statement outside function body
func ErrRequiredFieldNotProvided(err error, field string) error {
return errors.New(ErrRequiredFieldNotProvidedCode, errors.Alert,
[]string{"All required flags are not passed."},
[]string{err.Error()},
[]string{"Required flag \"%s\" is not passed."},
[]string{"Ensure value for flag \"%s\" is correctly provided."},
=======

Check failure on line 90 in internal/errors/error.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21, ubuntu-22.04)

syntax error: unexpected ==, expected expression
func ErrInvalidEmailFormat(email string) error {

Check failure on line 91 in internal/errors/error.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21, ubuntu-22.04)

syntax error: unexpected error at end of statement
return errors.New(ErrInvalidEmailFormatCode, errors.Alert,
[]string{"Invalid email format provided."},
[]string{fmt.Sprintf("The provided email '%s' is not a valid email format.", email)},
[]string{"The email provided for the Kanvas snapshot request is not in the correct format."},
[]string{"Ensure the email address follows the correct format (e.g., user@example.com)."},
>>>>>>> Stashed changes

Check failure on line 97 in internal/errors/error.go

View workflow job for this annotation

GitHub Actions / golangci-lint (1.21, ubuntu-22.04)

syntax error: unexpected >>, expected expression (typecheck)
)
}

0 comments on commit f7fa548

Please sign in to comment.