Skip to content

Commit

Permalink
fix: add swiftwave, db, registry port to restricted ports for ingress…
Browse files Browse the repository at this point in the history
… rule (#796) (#797)

(cherry picked from commit 79136d9)

Co-authored-by: Tanmoy Sarkar <[email protected]>
  • Loading branch information
mergify[bot] and tanmoysrt authored Jun 16, 2024
1 parent b4ccac8 commit 9844940
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion swiftwave_service/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ var initCmd = &cobra.Command{
},
PostgresqlConfig: local_config.PostgresqlConfig{
Host: defaultString(currentPostgresHost, "127.0.0.1"),
Port: defaultInt(currentPostgresPort, 5432),
Port: defaultInt(currentPostgresPort, 3335),
User: defaultString(currentPostgresUser, "user_"+generateRandomString(8)),
Password: defaultString(currentPostgresPassword, generateRandomString(20)),
Database: defaultString(currentPostgresDatabase, "db_"+generateRandomString(8)),
Expand Down
31 changes: 31 additions & 0 deletions swiftwave_service/config/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"github.com/lib/pq"
"github.com/swiftwave-org/swiftwave/swiftwave_service/config/local_config"
"github.com/swiftwave-org/swiftwave/swiftwave_service/config/system_config"
"github.com/swiftwave-org/swiftwave/swiftwave_service/db"
Expand Down Expand Up @@ -29,6 +30,26 @@ func Fetch() (*Config, error) {
if err != nil {
return nil, err
}

// add swiftwave, registry and db port in restricted ports if not configured
if systemConfig != nil && localConfig != nil {
if localConfig.ServiceConfig.BindPort != 80 && localConfig.ServiceConfig.BindPort != 443 {
if !isPortAdded(localConfig.ServiceConfig.BindPort, systemConfig.RestrictedPorts) {
systemConfig.RestrictedPorts = append(systemConfig.RestrictedPorts, int64(localConfig.ServiceConfig.BindPort))
}
}
if localConfig.PostgresqlConfig.RunLocalPostgres {
if !isPortAdded(localConfig.PostgresqlConfig.Port, systemConfig.RestrictedPorts) {
systemConfig.RestrictedPorts = append(systemConfig.RestrictedPorts, int64(localConfig.PostgresqlConfig.Port))
}
}
if !systemConfig.ImageRegistryConfig.IsConfigured() {
if !isPortAdded(localConfig.LocalImageRegistryConfig.Port, systemConfig.RestrictedPorts) {
systemConfig.RestrictedPorts = append(systemConfig.RestrictedPorts, int64(localConfig.LocalImageRegistryConfig.Port))
}
}
}

return &Config{
LocalConfig: localConfig,
SystemConfig: systemConfig,
Expand All @@ -55,3 +76,13 @@ func (config *Config) ImageRegistryPassword() string {
}
return config.LocalConfig.LocalImageRegistryConfig.Password
}

// private functions
func isPortAdded(port int, ports pq.Int64Array) bool {
for _, p := range ports {
if int(p) == port {
return true
}
}
return false
}

0 comments on commit 9844940

Please sign in to comment.