Bladeren bron

feat: add env to skip installation #357

Jacky 1 jaar geleden
bovenliggende
commit
13c4eb04a3
5 gewijzigde bestanden met toevoegingen van 22 en 1 verwijderingen
  1. 1 1
      api/system/install.go
  2. 10 0
      internal/kernal/boot.go
  3. 1 0
      settings/server.go
  4. 2 0
      settings/settings_test.go
  5. 8 0
      settings/user.go

+ 1 - 1
api/system/install.go

@@ -13,7 +13,7 @@ import (
 )
 
 func installLockStatus() bool {
-	return "" != settings.ServerSettings.JwtSecret
+	return settings.ServerSettings.SkipInstallation || "" != settings.ServerSettings.JwtSecret
 }
 
 func InstallLockCheck(c *gin.Context) {

+ 10 - 0
internal/kernal/boot.go

@@ -60,6 +60,16 @@ func recovery() {
 }
 
 func InitDatabase() {
+
+	// Skip installation
+	if settings.ServerSettings.SkipInstallation && settings.ServerSettings.JwtSecret == "" {
+		settings.ServerSettings.JwtSecret = uuid.New().String()
+		err := settings.Save()
+		if err != nil {
+			logger.Error(err)
+		}
+	}
+
 	if "" != settings.ServerSettings.JwtSecret {
 		db := model.Init()
 		query.Init(db)

+ 1 - 0
settings/server.go

@@ -20,6 +20,7 @@ type Server struct {
 	GithubProxy          string   `json:"github_proxy" binding:"omitempty,url"`
 	CertRenewalInterval  int      `json:"cert_renewal_interval" binding:"min=7,max=21"`
 	RecursiveNameservers []string `json:"recursive_nameservers" binding:"omitempty,dive,hostname_port"`
+	SkipInstallation     bool     `json:"skip_installation"`
 }
 
 func (s *Server) GetCADir() string {

+ 2 - 0
settings/settings_test.go

@@ -25,6 +25,7 @@ func TestSetup(t *testing.T) {
 	_ = os.Setenv("NGINX_UI_SERVER_HTTP_HOST", "127.0.0.1")
 	_ = os.Setenv("NGINX_UI_SERVER_CERT_RENEWAL_INTERVAL", "14")
 	_ = os.Setenv("NGINX_UI_SERVER_RECURSIVE_NAMESERVERS", "8.8.8.8")
+	_ = os.Setenv("NGINX_UI_SERVER_SKIP_INSTALLATION", "true")
 
 	_ = os.Setenv("NGINX_UI_NGINX_ACCESS_LOG_PATH", "/tmp/nginx/access.log")
 	_ = os.Setenv("NGINX_UI_NGINX_ERROR_LOG_PATH", "/tmp/nginx/error.log")
@@ -67,6 +68,7 @@ func TestSetup(t *testing.T) {
 	assert.Equal(t, "127.0.0.1", ServerSettings.HttpHost)
 	assert.Equal(t, 14, ServerSettings.CertRenewalInterval)
 	assert.Equal(t, []string{"8.8.8.8"}, ServerSettings.RecursiveNameservers)
+	assert.Equal(t, true, ServerSettings.SkipInstallation)
 
 	assert.Equal(t, "/tmp/nginx/access.log", NginxSettings.AccessLogPath)
 	assert.Equal(t, "/tmp/nginx/error.log", NginxSettings.ErrorLogPath)

+ 8 - 0
settings/user.go

@@ -0,0 +1,8 @@
+package settings
+
+type PredefinedUser struct {
+	User     string `json:"user"`
+	Password string `json:"password"`
+}
+
+var PredefinedUserSettings = &PredefinedUser{}