-
Notifications
You must be signed in to change notification settings - Fork 10
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
Feature Adding TLS-HTTPS configuration #288
Merged
MaartendeKruijf
merged 11 commits into
development
from
feature/287-feature-adding-https-tls
Dec 19, 2024
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
172e49b
added auto generated certs to gitignore
RabbITCybErSeC 62a96e0
added docker compose with self-signed certificates
RabbITCybErSeC d704276
updated env
RabbITCybErSeC 376b466
controller changes for tls
RabbITCybErSeC e2215be
env variable rename
RabbITCybErSeC b09119f
finished controller
RabbITCybErSeC 8837774
use native run tls function by gin instead
RabbITCybErSeC 619a8a3
fixed missing stat check
RabbITCybErSeC 324fd39
moved envs to run function
RabbITCybErSeC beaa4db
fixed port
RabbITCybErSeC 465b992
fix linting
RabbITCybErSeC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ docs/package-lock.json | |
docs/.hugo_build.lock | ||
**.hugo_build.lock | ||
|
||
certs |
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the refactor to an other branch |
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 |
---|---|---|
|
@@ -177,16 +177,50 @@ func Initialize() error { | |
return err | ||
} | ||
|
||
port := utils.GetEnv("PORT", "8080") | ||
err = app.Run(":" + port) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. app.RunTLS |
||
err = run(app) | ||
if err != nil { | ||
log.Error("failed to run gin") | ||
} | ||
log.Info("exit") | ||
|
||
return err | ||
} | ||
|
||
func validateCertificates(certFile string, keyFile string) error { | ||
_, err := os.Stat(certFile) | ||
if os.IsNotExist(err) { | ||
return fmt.Errorf("certificate file not found: %s", certFile) | ||
} | ||
|
||
_, err = os.Stat(keyFile) | ||
if os.IsNotExist(err) { | ||
_, err = os.Stat(keyFile) | ||
return fmt.Errorf("key file not found: %s", keyFile) | ||
} | ||
return nil | ||
} | ||
|
||
func run(app *gin.Engine) error { | ||
port := utils.GetEnv("PORT", "8080") | ||
port = ":" + port | ||
|
||
enableTLS, _ := strconv.ParseBool(utils.GetEnv("ENABLE_TLS", "false")) | ||
certFile := utils.GetEnv("CERT_FILE", "./certs/server.crt") | ||
keyFile := utils.GetEnv("CERT_KEY_FILE", "./certs/server.key") | ||
|
||
if enableTLS { | ||
err := validateCertificates(certFile, keyFile) | ||
if err != nil { | ||
return fmt.Errorf("TLS configuration error: %w", err) | ||
} | ||
log.Infof("Starting HTTPS server on port %s", port) | ||
return app.RunTLS(port, certFile, keyFile) | ||
|
||
} | ||
|
||
log.Infof("Starting HTTP server on port %s", port) | ||
return app.Run(port) | ||
} | ||
|
||
func initializeCore(app *gin.Engine) error { | ||
origins := strings.Split(strings.ReplaceAll(utils.GetEnv("SOARCA_ALLOWED_ORIGINS", "*"), " ", ""), ",") | ||
routes.Cors(app, origins) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only minimal config in here