Skip to content

Commit 10b4cfc

Browse files
authored
Secret storage for env (#3143)
* feat(secrets): support secret storages by variable groups * fix: migrations * fix: migrations
1 parent 18d98b2 commit 10b4cfc

File tree

7 files changed

+26
-17
lines changed

7 files changed

+26
-17
lines changed

cli/cmd/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var migrationArgs struct {
1212

1313
func init() {
1414
migrateCmd.PersistentFlags().StringVar(&migrationArgs.undoTo, "undo-to", "", "Undo to specific version")
15-
migrateCmd.PersistentFlags().StringVar(&migrationArgs.undoTo, "apply-to", "", "Apply to specific version")
15+
migrateCmd.PersistentFlags().StringVar(&migrationArgs.applyTo, "apply-to", "", "Apply to specific version")
1616

1717
rootCmd.AddCommand(migrateCmd)
1818
}

db/Environment.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type Environment struct {
5050

5151
// Secrets is a field which used to update secrets associated with the environment.
5252
Secrets []EnvironmentSecret `db:"-" json:"secrets" backup:"-"`
53+
54+
SecretStorageID *int `db:"secret_storage_id" json:"secret_storage_id,omitempty" backup:"-"`
55+
SecretStorageKeyPrefix *string `db:"secret_storage_key_prefix" json:"secret_storage_key_prefix,omitempty"`
5356
}
5457

5558
func (s *EnvironmentSecret) Validate() error {

db/Migration.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func GetMigrations(dialect string) []Migration {
2626
if dialect == util.DbDriverSQLite {
2727
return []Migration{
2828
{Version: "2.15.1.sqlite"},
29-
{Version: "2.15.1"},
3029
{Version: "2.15.2"},
3130
{Version: "2.15.3"},
3231
{Version: "2.15.4"},
@@ -131,7 +130,7 @@ func (m Migration) ParseVersion() (res MigrationVersion, err error) {
131130

132131
parts := strings.Split(m.Version, ".")
133132

134-
if len(parts) > 3 || len(parts) < 2 {
133+
if len(parts) < 2 {
135134
err = fmt.Errorf("invalid migration version format %s", m.Version)
136135
return
137136
}

db/Project.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66

77
// Project is the top level structure in Semaphore
88
type Project struct {
9-
ID int `db:"id" json:"id" backup:"-"`
10-
Name string `db:"name" json:"name" binding:"required"`
11-
Created time.Time `db:"created" json:"created" backup:"-"`
12-
Alert bool `db:"alert" json:"alert,omitempty"`
13-
AlertChat *string `db:"alert_chat" json:"alert_chat,omitempty"`
14-
MaxParallelTasks int `db:"max_parallel_tasks" json:"max_parallel_tasks,omitempty"`
15-
Type string `db:"type" json:"type"`
9+
ID int `db:"id" json:"id" backup:"-"`
10+
Name string `db:"name" json:"name" binding:"required"`
11+
Created time.Time `db:"created" json:"created" backup:"-"`
12+
Alert bool `db:"alert" json:"alert,omitempty"`
13+
AlertChat *string `db:"alert_chat" json:"alert_chat,omitempty"`
14+
MaxParallelTasks int `db:"max_parallel_tasks" json:"max_parallel_tasks,omitempty"`
15+
Type string `db:"type" json:"type"`
16+
DefaultSecretStorageID *int `db:"default_secret_storage_id" json:"default_secret_storage_id,omitempty" backup:"-"`
1617
}

db/sql/environment.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,16 @@ func (d *SqlDb) CreateEnvironment(env db.Environment) (newEnv db.Environment, er
4545

4646
insertID, err := d.insert(
4747
"id",
48-
"insert into project__environment (project_id, name, json, env, password) values (?, ?, ?, ?, ?)",
48+
"insert into project__environment "+
49+
"(project_id, name, json, env, password, secret_storage_id, secret_storage_key_prefix) values "+
50+
"(?, ?, ?, ?, ?, ?, ?)",
4951
env.ProjectID,
5052
env.Name,
5153
env.JSON,
5254
env.ENV,
53-
env.Password)
55+
env.Password,
56+
env.SecretStorageID,
57+
env.SecretStorageKeyPrefix)
5458

5559
if err != nil {
5660
return

db/sql/migrations/v2.16.0.err.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
alter table `project__environment` drop `source_storage_id`;
2-
alter table `project__environment` drop `source_storage_key`;
1+
alter table `project` drop `default_secret_storage_id`;
2+
alter table `project__environment` drop `secret_storage_id`;
3+
alter table `project__environment` drop `secret_storage_key_prefix`;
34
alter table `access_key` drop `storage_id`;
45
alter table `access_key` drop `source_storage_id`;
56
alter table `access_key` drop `source_storage_key`;

db/sql/migrations/v2.16.0.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ create table project__secret_storage (
1616
);
1717

1818
alter table `access_key` add `storage_id` int null references `project__secret_storage`(`id`);
19-
2019
alter table `access_key` add `source_storage_id` int null references `project__secret_storage`(`id`);
2120
alter table `access_key` add `source_storage_key` varchar(1000);
2221

23-
alter table `project__environment` add `source_storage_id` int null references `project__secret_storage`(`id`);
24-
alter table `project__environment` add `source_storage_key` varchar(1000);
22+
alter table `project__environment` add `secret_storage_id` int null references `project__secret_storage`(`id`);
23+
alter table `project__environment` add `secret_storage_key_prefix` varchar(1000);
24+
25+
alter table `project` add `default_secret_storage_id` int null references `project__secret_storage`(`id`);

0 commit comments

Comments
 (0)