Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ License URL: https://github.com/clipperhouse/uax29/blob/v2.4.0/LICENSE

----------
Module: github.com/codesphere-cloud/cs-go/pkg/io
Version: v0.16.2
Version: v0.16.4
License: Apache-2.0
License URL: https://github.com/codesphere-cloud/cs-go/blob/v0.16.2/LICENSE
License URL: https://github.com/codesphere-cloud/cs-go/blob/v0.16.4/LICENSE

----------
Module: github.com/codesphere-cloud/oms/internal/tmpl
Expand Down
47 changes: 24 additions & 23 deletions cli/cmd/init_install_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd

import (
"fmt"
"log"
"strings"

csio "github.com/codesphere-cloud/cs-go/pkg/io"
Expand Down Expand Up @@ -189,34 +190,34 @@ func (c *InitInstallConfigCmd) InitInstallConfig(icg installer.InstallConfigMana
}

func (c *InitInstallConfigCmd) printWelcomeMessage() {
fmt.Println("Welcome to OMS!")
fmt.Println("This wizard will help you create config.yaml and prod.vault.yaml for Codesphere installation.")
fmt.Println()
log.Println("Welcome to OMS!")
log.Println("This wizard will help you create config.yaml and prod.vault.yaml for Codesphere installation.")
log.Println()
}

func (c *InitInstallConfigCmd) printSuccessMessage() {
fmt.Println("\n" + strings.Repeat("=", 70))
fmt.Println("Configuration files successfully generated!")
fmt.Println(strings.Repeat("=", 70))

fmt.Println("\nIMPORTANT: Keys and certificates have been generated and embedded in the vault file.")
fmt.Println(" Keep the vault file secure and encrypt it with SOPS before storing.")

fmt.Println("\nNext steps:")
fmt.Println("1. Review the generated config.yaml and prod.vault.yaml")
fmt.Println("2. Install SOPS and Age: brew install sops age")
fmt.Println("3. Generate an Age keypair: age-keygen -o age_key.txt")
fmt.Println("4. Encrypt the vault file:")
fmt.Printf(" age-keygen -y age_key.txt # Get public key\n")
fmt.Printf(" sops --encrypt --age <PUBLIC_KEY> --in-place %s\n", c.Opts.VaultFile)
fmt.Println("5. Run the Codesphere installer with these configuration files")
fmt.Println()
log.Println("\n" + strings.Repeat("=", 70))
log.Println("Configuration files successfully generated!")
log.Println(strings.Repeat("=", 70))

log.Println("\nIMPORTANT: Keys and certificates have been generated and embedded in the vault file.")
log.Println(" Keep the vault file secure and encrypt it with SOPS before storing.")

log.Println("\nNext steps:")
log.Println("1. Review the generated config.yaml and prod.vault.yaml")
log.Println("2. Install SOPS and Age: brew install sops age")
log.Println("3. Generate an Age keypair: age-keygen -o age_key.txt")
log.Println("4. Encrypt the vault file:")
log.Printf(" age-keygen -y age_key.txt # Get public key\n")
log.Printf(" sops --encrypt --age <PUBLIC_KEY> --in-place %s\n", c.Opts.VaultFile)
log.Println("5. Run the Codesphere installer with these configuration files")
log.Println()
}

func (c *InitInstallConfigCmd) validateOnly(icg installer.InstallConfigManager) error {
fmt.Printf("Validating configuration files...\n")
log.Printf("Validating configuration files...\n")

fmt.Printf("Reading install config file: %s\n", c.Opts.ConfigFile)
log.Printf("Reading install config file: %s\n", c.Opts.ConfigFile)
err := icg.LoadInstallConfigFromFile(c.Opts.ConfigFile)
if err != nil {
return fmt.Errorf("failed to load config file: %w", err)
Expand All @@ -228,7 +229,7 @@ func (c *InitInstallConfigCmd) validateOnly(icg installer.InstallConfigManager)
}

if c.Opts.VaultFile != "" {
fmt.Printf("Reading vault file: %s\n", c.Opts.VaultFile)
log.Printf("Reading vault file: %s\n", c.Opts.VaultFile)
err := icg.LoadVaultFromFile(c.Opts.VaultFile)
if err != nil {
return fmt.Errorf("failed to load vault file: %w", err)
Expand All @@ -240,7 +241,7 @@ func (c *InitInstallConfigCmd) validateOnly(icg installer.InstallConfigManager)
}
}

fmt.Println("Configuration is valid!")
log.Println("Configuration is valid!")
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd

import (
"fmt"
"log"
"time"

"github.com/codesphere-cloud/cs-go/pkg/io"
Expand Down Expand Up @@ -39,7 +40,7 @@ func (c *RegisterCmd) RunE(_ *cobra.Command, args []string) error {
}

if newKey != nil {
fmt.Printf("API key registered successfully!\nOwner: %s\nOrganisation: %s\nKey: %s\n", newKey.Owner, newKey.Organization, newKey.ApiKey)
log.Printf("API key registered successfully!\nOwner: %s\nOrganisation: %s\nKey: %s\n", newKey.Owner, newKey.Organization, newKey.ApiKey)
}

return nil
Expand Down
13 changes: 6 additions & 7 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package cmd

import (
"fmt"
"log"
"os"

Expand All @@ -31,27 +30,27 @@ func GetRootCmd() *cobra.Command {
apiKey := os.Getenv("OMS_PORTAL_API_KEY")

if len(apiKey) == 25 {
fmt.Fprintf(os.Stderr, "Warning: You used an old API key format.\n")
fmt.Fprintf(os.Stderr, "Attempting to upgrade to the new format...\n\n")
log.Println("Warning: You used an old API key format.")
log.Println("Attempting to upgrade to the new format...")

portalClient := portal.NewPortalClient()
keyId, err := portalClient.GetApiKeyId(apiKey)

if err != nil {
fmt.Fprintf(os.Stderr, "Error: Failed to upgrade old API key: %v\n", err)
log.Printf("Error: Failed to upgrade old API key: %v\n", err)
return
}

newApiKey := keyId + apiKey

if err := os.Setenv("OMS_PORTAL_API_KEY", newApiKey); err != nil {
fmt.Fprintf(os.Stderr, "Error: Failed to set environment variable: %v\n", err)
log.Printf("Error: Failed to set environment variable: %v\n", err)
return
}
opts.OmsPortalApiKey = newApiKey

fmt.Fprintf(os.Stderr, "Please update your environment variable:\n\n")
fmt.Fprintf(os.Stderr, " export OMS_PORTAL_API_KEY='%s'\n\n", newApiKey)
log.Println("Please update your environment variable:")
log.Printf(" export OMS_PORTAL_API_KEY='%s'\n\n", newApiKey)
}
},
}
Expand Down
64 changes: 32 additions & 32 deletions cli/cmd/update_install_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ func AddUpdateInstallConfigCmd(update *cobra.Command, opts *GlobalOptions) {
}

func (c *UpdateInstallConfigCmd) UpdateInstallConfig(icg installer.InstallConfigManager) error {
fmt.Printf("Loading existing configuration from: %s\n", c.Opts.ConfigFile)
log.Printf("Loading existing configuration from: %s\n", c.Opts.ConfigFile)
err := icg.LoadInstallConfigFromFile(c.Opts.ConfigFile)
if err != nil {
return fmt.Errorf("failed to load config file: %w", err)
}

fmt.Printf("Loading existing vault from: %s\n", c.Opts.VaultFile)
log.Printf("Loading existing vault from: %s\n", c.Opts.VaultFile)
err = icg.LoadVaultFromFile(c.Opts.VaultFile)
if err != nil {
return fmt.Errorf("failed to load vault file: %w", err)
}

fmt.Println("Merging vault secrets into configuration...")
log.Println("Merging vault secrets into configuration...")
err = icg.MergeVaultIntoConfig()
if err != nil {
return fmt.Errorf("failed to merge vault into config: %w", err)
Expand All @@ -154,12 +154,12 @@ func (c *UpdateInstallConfigCmd) UpdateInstallConfig(icg installer.InstallConfig
}

if tracker.HasChanges() {
fmt.Println("\nRegenerating affected secrets and certificates...")
log.Println("\nRegenerating affected secrets and certificates...")
if err := c.regenerateSecrets(config, tracker); err != nil {
return fmt.Errorf("failed to regenerate secrets: %w", err)
}
} else {
fmt.Println("\nNo changes detected that require secret regeneration.")
log.Println("\nNo changes detected that require secret regeneration.")
}

if err := icg.WriteInstallConfig(c.Opts.ConfigFile, c.Opts.WithComments); err != nil {
Expand All @@ -180,12 +180,12 @@ func (c *UpdateInstallConfigCmd) applyUpdates(config *files.RootConfig, tracker
if c.Opts.PostgresPrimaryIP != "" || c.Opts.PostgresPrimaryHostname != "" {
if config.Postgres.Primary != nil {
if c.Opts.PostgresPrimaryIP != "" && config.Postgres.Primary.IP != c.Opts.PostgresPrimaryIP {
fmt.Printf("Updating PostgreSQL primary IP: %s -> %s\n", config.Postgres.Primary.IP, c.Opts.PostgresPrimaryIP)
log.Printf("Updating PostgreSQL primary IP: %s -> %s\n", config.Postgres.Primary.IP, c.Opts.PostgresPrimaryIP)
config.Postgres.Primary.IP = c.Opts.PostgresPrimaryIP
tracker.MarkPostgresPrimaryCertNeedsRegen()
}
if c.Opts.PostgresPrimaryHostname != "" && config.Postgres.Primary.Hostname != c.Opts.PostgresPrimaryHostname {
fmt.Printf("Updating PostgreSQL primary hostname: %s -> %s\n", config.Postgres.Primary.Hostname, c.Opts.PostgresPrimaryHostname)
log.Printf("Updating PostgreSQL primary hostname: %s -> %s\n", config.Postgres.Primary.Hostname, c.Opts.PostgresPrimaryHostname)
config.Postgres.Primary.Hostname = c.Opts.PostgresPrimaryHostname
tracker.MarkPostgresPrimaryCertNeedsRegen()
}
Expand All @@ -195,89 +195,89 @@ func (c *UpdateInstallConfigCmd) applyUpdates(config *files.RootConfig, tracker
if c.Opts.PostgresReplicaIP != "" || c.Opts.PostgresReplicaName != "" {
if config.Postgres.Replica != nil {
if c.Opts.PostgresReplicaIP != "" && config.Postgres.Replica.IP != c.Opts.PostgresReplicaIP {
fmt.Printf("Updating PostgreSQL replica IP: %s -> %s\n", config.Postgres.Replica.IP, c.Opts.PostgresReplicaIP)
log.Printf("Updating PostgreSQL replica IP: %s -> %s\n", config.Postgres.Replica.IP, c.Opts.PostgresReplicaIP)
config.Postgres.Replica.IP = c.Opts.PostgresReplicaIP
tracker.MarkPostgresReplicaCertNeedsRegen()
}
if c.Opts.PostgresReplicaName != "" && config.Postgres.Replica.Name != c.Opts.PostgresReplicaName {
fmt.Printf("Updating PostgreSQL replica name: %s -> %s\n", config.Postgres.Replica.Name, c.Opts.PostgresReplicaName)
log.Printf("Updating PostgreSQL replica name: %s -> %s\n", config.Postgres.Replica.Name, c.Opts.PostgresReplicaName)
config.Postgres.Replica.Name = c.Opts.PostgresReplicaName
tracker.MarkPostgresReplicaCertNeedsRegen()
}
}
}

if c.Opts.PostgresServerAddress != "" && config.Postgres.ServerAddress != c.Opts.PostgresServerAddress {
fmt.Printf("Updating PostgreSQL server address: %s -> %s\n", config.Postgres.ServerAddress, c.Opts.PostgresServerAddress)
log.Printf("Updating PostgreSQL server address: %s -> %s\n", config.Postgres.ServerAddress, c.Opts.PostgresServerAddress)
config.Postgres.ServerAddress = c.Opts.PostgresServerAddress
}

// Ceph updates
if c.Opts.CephNodesSubnet != "" && config.Ceph.NodesSubnet != c.Opts.CephNodesSubnet {
fmt.Printf("Updating Ceph nodes subnet: %s -> %s\n", config.Ceph.NodesSubnet, c.Opts.CephNodesSubnet)
log.Printf("Updating Ceph nodes subnet: %s -> %s\n", config.Ceph.NodesSubnet, c.Opts.CephNodesSubnet)
config.Ceph.NodesSubnet = c.Opts.CephNodesSubnet
}

// Kubernetes updates
if c.Opts.KubernetesAPIServerHost != "" && config.Kubernetes.APIServerHost != c.Opts.KubernetesAPIServerHost {
fmt.Printf("Updating Kubernetes API server host: %s -> %s\n", config.Kubernetes.APIServerHost, c.Opts.KubernetesAPIServerHost)
log.Printf("Updating Kubernetes API server host: %s -> %s\n", config.Kubernetes.APIServerHost, c.Opts.KubernetesAPIServerHost)
config.Kubernetes.APIServerHost = c.Opts.KubernetesAPIServerHost
}

if c.Opts.KubernetesPodCIDR != "" && config.Kubernetes.PodCIDR != c.Opts.KubernetesPodCIDR {
fmt.Printf("Updating Kubernetes Pod CIDR: %s -> %s\n", config.Kubernetes.PodCIDR, c.Opts.KubernetesPodCIDR)
log.Printf("Updating Kubernetes Pod CIDR: %s -> %s\n", config.Kubernetes.PodCIDR, c.Opts.KubernetesPodCIDR)
config.Kubernetes.PodCIDR = c.Opts.KubernetesPodCIDR
}

if c.Opts.KubernetesServiceCIDR != "" && config.Kubernetes.ServiceCIDR != c.Opts.KubernetesServiceCIDR {
fmt.Printf("Updating Kubernetes Service CIDR: %s -> %s\n", config.Kubernetes.ServiceCIDR, c.Opts.KubernetesServiceCIDR)
log.Printf("Updating Kubernetes Service CIDR: %s -> %s\n", config.Kubernetes.ServiceCIDR, c.Opts.KubernetesServiceCIDR)
config.Kubernetes.ServiceCIDR = c.Opts.KubernetesServiceCIDR
}

// Cluster Gateway updates
if c.Opts.ClusterGatewayServiceType != "" && config.Cluster.Gateway.ServiceType != c.Opts.ClusterGatewayServiceType {
fmt.Printf("Updating cluster gateway service type: %s -> %s\n", config.Cluster.Gateway.ServiceType, c.Opts.ClusterGatewayServiceType)
log.Printf("Updating cluster gateway service type: %s -> %s\n", config.Cluster.Gateway.ServiceType, c.Opts.ClusterGatewayServiceType)
config.Cluster.Gateway.ServiceType = c.Opts.ClusterGatewayServiceType
}

if len(c.Opts.ClusterGatewayIPAddresses) > 0 {
fmt.Printf("Updating cluster gateway IP addresses\n")
log.Printf("Updating cluster gateway IP addresses\n")
config.Cluster.Gateway.IPAddresses = c.Opts.ClusterGatewayIPAddresses
}

if c.Opts.ClusterPublicGatewayServiceType != "" && config.Cluster.PublicGateway.ServiceType != c.Opts.ClusterPublicGatewayServiceType {
fmt.Printf("Updating cluster public gateway service type: %s -> %s\n", config.Cluster.PublicGateway.ServiceType, c.Opts.ClusterPublicGatewayServiceType)
log.Printf("Updating cluster public gateway service type: %s -> %s\n", config.Cluster.PublicGateway.ServiceType, c.Opts.ClusterPublicGatewayServiceType)
config.Cluster.PublicGateway.ServiceType = c.Opts.ClusterPublicGatewayServiceType
}

if len(c.Opts.ClusterPublicGatewayIPAddresses) > 0 {
fmt.Printf("Updating cluster public gateway IP addresses\n")
log.Printf("Updating cluster public gateway IP addresses\n")
config.Cluster.PublicGateway.IPAddresses = c.Opts.ClusterPublicGatewayIPAddresses
}

// Codesphere updates
if c.Opts.CodesphereDomain != "" && config.Codesphere.Domain != c.Opts.CodesphereDomain {
fmt.Printf("Updating Codesphere domain: %s -> %s\n", config.Codesphere.Domain, c.Opts.CodesphereDomain)
log.Printf("Updating Codesphere domain: %s -> %s\n", config.Codesphere.Domain, c.Opts.CodesphereDomain)
config.Codesphere.Domain = c.Opts.CodesphereDomain
}

if c.Opts.CodespherePublicIP != "" && config.Codesphere.PublicIP != c.Opts.CodespherePublicIP {
fmt.Printf("Updating Codesphere public IP: %s -> %s\n", config.Codesphere.PublicIP, c.Opts.CodespherePublicIP)
log.Printf("Updating Codesphere public IP: %s -> %s\n", config.Codesphere.PublicIP, c.Opts.CodespherePublicIP)
config.Codesphere.PublicIP = c.Opts.CodespherePublicIP
}

if c.Opts.CodesphereWorkspaceHostingBaseDomain != "" && config.Codesphere.WorkspaceHostingBaseDomain != c.Opts.CodesphereWorkspaceHostingBaseDomain {
fmt.Printf("Updating workspace hosting base domain: %s -> %s\n", config.Codesphere.WorkspaceHostingBaseDomain, c.Opts.CodesphereWorkspaceHostingBaseDomain)
log.Printf("Updating workspace hosting base domain: %s -> %s\n", config.Codesphere.WorkspaceHostingBaseDomain, c.Opts.CodesphereWorkspaceHostingBaseDomain)
config.Codesphere.WorkspaceHostingBaseDomain = c.Opts.CodesphereWorkspaceHostingBaseDomain
}

if c.Opts.CodesphereCustomDomainsCNameBaseDomain != "" && config.Codesphere.CustomDomains.CNameBaseDomain != c.Opts.CodesphereCustomDomainsCNameBaseDomain {
fmt.Printf("Updating custom domains CNAME base domain: %s -> %s\n", config.Codesphere.CustomDomains.CNameBaseDomain, c.Opts.CodesphereCustomDomainsCNameBaseDomain)
log.Printf("Updating custom domains CNAME base domain: %s -> %s\n", config.Codesphere.CustomDomains.CNameBaseDomain, c.Opts.CodesphereCustomDomainsCNameBaseDomain)
config.Codesphere.CustomDomains.CNameBaseDomain = c.Opts.CodesphereCustomDomainsCNameBaseDomain
}

if len(c.Opts.CodesphereDNSServers) > 0 {
fmt.Printf("Updating DNS servers\n")
log.Printf("Updating DNS servers\n")
config.Codesphere.DNSServers = c.Opts.CodesphereDNSServers
}
}
Expand Down Expand Up @@ -317,23 +317,23 @@ func (c *UpdateInstallConfigCmd) regenerateSecrets(config *files.RootConfig, tra
}

func (c *UpdateInstallConfigCmd) printSuccessMessage(tracker *SecretDependencyTracker) {
fmt.Println("\n" + strings.Repeat("=", 70))
fmt.Println("Configuration successfully updated!")
fmt.Println(strings.Repeat("=", 70))
log.Println("\n" + strings.Repeat("=", 70))
log.Println("Configuration successfully updated!")
log.Println(strings.Repeat("=", 70))

if tracker.HasChanges() {
fmt.Println("\nRegenerated secrets:")
log.Println("\nRegenerated secrets:")
if tracker.NeedsPostgresPrimaryCertRegen() {
fmt.Println(" ✓ PostgreSQL primary server certificate")
log.Println(" ✓ PostgreSQL primary server certificate")
}
if tracker.NeedsPostgresReplicaCertRegen() {
fmt.Println(" ✓ PostgreSQL replica server certificate")
log.Println(" ✓ PostgreSQL replica server certificate")
}
}

fmt.Println("\nIMPORTANT: The vault file has been updated with new secrets.")
fmt.Println(" Remember to re-encrypt it with SOPS before storing.")
fmt.Println()
log.Println("\nIMPORTANT: The vault file has been updated with new secrets.")
log.Println(" Remember to re-encrypt it with SOPS before storing.")
log.Println()
}

type SecretDependencyTracker struct {
Expand Down
Loading