Consolidate controller bootstrap login in run command (#38)

This commit is contained in:
Fedor Korotkov
2023-03-21 15:36:55 -04:00
committed by GitHub
parent 10f56bb5e3
commit 9b5ad09841
7 changed files with 68 additions and 95 deletions
-1
View File
@@ -19,7 +19,6 @@ const ctxServiceAccountKey = "service-account"
var ErrUnauthorized = errors.New("unauthorized")
func (controller *Controller) initAPI() *gin.Engine {
gin.SetMode(gin.DebugMode)
ginEngine := gin.Default()
// v1 API
+2 -1
View File
@@ -116,7 +116,8 @@ func (controller *Controller) EnsureServiceAccount(serviceAccount *v1.ServiceAcc
}
if serviceAccount.Token == "" {
serviceAccount.Token = uuid.New().String()
return fmt.Errorf("%w: attempted to create a service account with an empty token",
ErrAdminTaskFailed)
}
serviceAccount.CreatedAt = time.Now()
+9
View File
@@ -70,6 +70,15 @@ func (dataDir *DataDir) DBPath() string {
return filepath.Join(dataDir.path, "db")
}
func (dataDir *DataDir) ControllerCertificateExists() bool {
return fileExist(dataDir.ControllerCertificatePath()) && fileExist(dataDir.ControllerKeyPath())
}
func fileExist(path string) bool {
_, err := os.Stat(path)
return err == nil
}
func (dataDir *DataDir) ControllerCertificatePath() string {
return filepath.Join(dataDir.path, "controller.crt")
}