Просмотр исходного кода

add omitempty to github actions yaml structs

Alexander Belanger 5 лет назад
Родитель
Сommit
d9e10f35f8
2 измененных файлов с 40 добавлено и 11 удалено
  1. 29 0
      cmd/migrate/keyrotate/rotate.go
  2. 11 11
      internal/integrations/ci/actions/actions.go

+ 29 - 0
cmd/migrate/keyrotate/rotate.go

@@ -14,69 +14,98 @@ import (
 const stepSize = 100
 
 func Rotate(db *_gorm.DB, oldKey, newKey *[32]byte) error {
+	oldKeyBytes := make([]byte, 32)
+	newKeyBytes := make([]byte, 32)
+
+	copy(oldKeyBytes[:], oldKey[:])
+	copy(newKeyBytes[:], newKey[:])
+
+	fmt.Printf("beginning key rotation from %s to %s\n", string(oldKeyBytes), string(newKeyBytes))
+
 	err := rotateClusterModel(db, oldKey, newKey)
 
 	if err != nil {
+		fmt.Printf("failed on cluster rotation: %v\n", err)
 		return err
 	}
 
 	err = rotateClusterCandidateModel(db, oldKey, newKey)
 
 	if err != nil {
+		fmt.Printf("failed on cc rotation: %v\n", err)
+
 		return err
 	}
 
 	err = rotateRegistryModel(db, oldKey, newKey)
 
 	if err != nil {
+		fmt.Printf("failed on registry rotation: %v\n", err)
+
 		return err
 	}
 
 	err = rotateHelmRepoModel(db, oldKey, newKey)
 
 	if err != nil {
+		fmt.Printf("failed on hr rotation: %v\n", err)
+
 		return err
 	}
 
 	err = rotateInfraModel(db, oldKey, newKey)
 
 	if err != nil {
+		fmt.Printf("failed on infra rotation: %v\n", err)
+
 		return err
 	}
 
 	err = rotateKubeIntegrationModel(db, oldKey, newKey)
 
 	if err != nil {
+		fmt.Printf("failed on ki rotation: %v\n", err)
+
 		return err
 	}
 
 	err = rotateBasicIntegrationModel(db, oldKey, newKey)
 
 	if err != nil {
+		fmt.Printf("failed on basic rotation: %v\n", err)
+
 		return err
 	}
 
 	err = rotateOIDCIntegrationModel(db, oldKey, newKey)
 
 	if err != nil {
+		fmt.Printf("failed on oidc rotation: %v\n", err)
+
 		return err
 	}
 
 	err = rotateOAuthIntegrationModel(db, oldKey, newKey)
 
 	if err != nil {
+		fmt.Printf("failed on oauth rotation: %v\n", err)
+
 		return err
 	}
 
 	err = rotateGCPIntegrationModel(db, oldKey, newKey)
 
 	if err != nil {
+		fmt.Printf("failed on gcp rotation: %v\n", err)
+
 		return err
 	}
 
 	err = rotateAWSIntegrationModel(db, oldKey, newKey)
 
 	if err != nil {
+		fmt.Printf("failed on aws rotation: %v\n", err)
+
 		return err
 	}
 

+ 11 - 11
internal/integrations/ci/actions/actions.go

@@ -79,31 +79,31 @@ func (g *GithubActions) Setup() (string, error) {
 }
 
 type GithubActionYAMLStep struct {
-	Name string `yaml:"name"`
-	ID   string `yaml:"id"`
-	Uses string `yaml:"uses"`
-	Run  string `yaml:"run"`
+	Name string `yaml:"name,omitempty"`
+	ID   string `yaml:"id,omitempty"`
+	Uses string `yaml:"uses,omitempty"`
+	Run  string `yaml:"run,omitempty"`
 }
 
 type GithubActionYAMLOnPushBranches struct {
-	Branches []string `yaml:"branches"`
+	Branches []string `yaml:"branches,omitempty"`
 }
 
 type GithubActionYAMLOnPush struct {
-	Push GithubActionYAMLOnPushBranches `yaml:"push"`
+	Push GithubActionYAMLOnPushBranches `yaml:"push,omitempty"`
 }
 
 type GithubActionYAMLJob struct {
-	RunsOn string                 `yaml:"runs-on"`
-	Steps  []GithubActionYAMLStep `yaml:"steps"`
+	RunsOn string                 `yaml:"runs-on,omitempty"`
+	Steps  []GithubActionYAMLStep `yaml:"steps,omitempty"`
 }
 
 type GithubActionYAML struct {
-	On GithubActionYAMLOnPush `yaml:"on"`
+	On GithubActionYAMLOnPush `yaml:"on,omitempty"`
 
-	Name string `yaml:"name"`
+	Name string `yaml:"name,omitempty"`
 
-	Jobs map[string]GithubActionYAMLJob `yaml:"jobs"`
+	Jobs map[string]GithubActionYAMLJob `yaml:"jobs,omitempty"`
 }
 
 func (g *GithubActions) GetGithubActionYAML() ([]byte, error) {