-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'real/develop' into develop
- Loading branch information
Showing
25 changed files
with
39,181 additions
and
38,920 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
package db | ||
|
||
type TemplateVaultType string | ||
|
||
const ( | ||
TemplateVaultPassword TemplateVaultType = "password" | ||
TemplateVaultScript TemplateVaultType = "script" | ||
) | ||
|
||
type TemplateVault struct { | ||
ID int `db:"id" json:"id" backup:"-"` | ||
ProjectID int `db:"project_id" json:"project_id" backup:"-"` | ||
TemplateID int `db:"template_id" json:"template_id" backup:"-"` | ||
VaultKeyID int `db:"vault_key_id" json:"vault_key_id" backup:"-"` | ||
Name *string `db:"name" json:"name"` | ||
ID int `db:"id" json:"id" backup:"-"` | ||
ProjectID int `db:"project_id" json:"project_id" backup:"-"` | ||
TemplateID int `db:"template_id" json:"template_id" backup:"-"` | ||
VaultKeyID *int `db:"vault_key_id" json:"vault_key_id" backup:"-"` | ||
Name *string `db:"name" json:"name"` | ||
Type TemplateVaultType `db:"type" json:"type"` | ||
Script *string `db:"script" json:"script"` | ||
|
||
Vault *AccessKey `db:"-" json:"-"` | ||
} | ||
|
||
func FillTemplateVault(d Store, projectID int, templateVault *TemplateVault) (err error) { | ||
var vault AccessKey | ||
vault, err = d.GetAccessKey(projectID, templateVault.VaultKeyID) | ||
if err != nil { | ||
return | ||
if templateVault.Type == TemplateVaultPassword && templateVault.VaultKeyID != nil { | ||
var vault AccessKey | ||
vault, err = d.GetAccessKey(projectID, *templateVault.VaultKeyID) | ||
if err != nil { | ||
return | ||
} | ||
templateVault.Vault = &vault | ||
} | ||
templateVault.Vault = &vault | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package bolt | ||
|
||
type migration_2_10_33 struct { | ||
migration | ||
} | ||
|
||
func (d migration_2_10_33) Apply() (err error) { | ||
projectIDs, err := d.getProjectIDs() | ||
|
||
if err != nil { | ||
return | ||
} | ||
|
||
vaults := make(map[string]map[string]map[string]interface{}) | ||
|
||
for _, projectID := range projectIDs { | ||
var err2 error | ||
vaults[projectID], err2 = d.getObjects(projectID, "template_vault") | ||
if err2 != nil { | ||
return err2 | ||
} | ||
} | ||
|
||
for projectID, projectVaults := range vaults { | ||
for repoID, vault := range projectVaults { | ||
if vault["type"] != nil && vault["type"] != "" { | ||
continue | ||
} | ||
vault["type"] = "password" | ||
err = d.setObject(projectID, "template_vault", repoID, vault) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package bolt | ||
|
||
import ( | ||
"encoding/json" | ||
"go.etcd.io/bbolt" | ||
"testing" | ||
) | ||
|
||
func TestMigration_2_10_33_Apply(t *testing.T) { | ||
store := CreateTestStore() | ||
|
||
err := store.db.Update(func(tx *bbolt.Tx) error { | ||
b, err := tx.CreateBucketIfNotExists([]byte("project")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = b.Put([]byte("0000000001"), []byte("{}")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
r, err := tx.CreateBucketIfNotExists([]byte("project__template_vault_0000000001")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = r.Put([]byte("0000000001"), | ||
[]byte("{\"id\":\"1\",\"project_id\":\"1\"}")) | ||
|
||
return err | ||
}) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = migration_2_10_33{migration{store.db}}.Apply() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var repo map[string]interface{} | ||
err = store.db.View(func(tx *bbolt.Tx) error { | ||
b := tx.Bucket([]byte("project__template_vault_0000000001")) | ||
str := string(b.Get([]byte("0000000001"))) | ||
return json.Unmarshal([]byte(str), &repo) | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if repo["type"] == nil { | ||
t.Fatal("app must be set") | ||
} | ||
|
||
if repo["type"].(string) != "password" { | ||
t.Fatal("invalid app: " + repo["type"].(string)) | ||
} | ||
} | ||
|
||
func TestMigration_2_10_33_Apply2(t *testing.T) { | ||
store := CreateTestStore() | ||
|
||
err := store.db.Update(func(tx *bbolt.Tx) error { | ||
b, err := tx.CreateBucketIfNotExists([]byte("project")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = b.Put([]byte("0000000001"), []byte("{}")) | ||
|
||
return err | ||
}) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = migration_2_10_33{migration{store.db}}.Apply() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
alter table `project__template_vault` change `vault_key_id` `vault_key_id` int; | ||
alter table `project__template_vault` add `type` varchar(20) not null default 'password'; | ||
alter table `project__template_vault` add `script` text; | ||
update `project__template_vault` set `type` = 'password' where `vault_key_id` IS NOT NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.