1
1
package application
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
6
7
"github.com/go-gorp/gorp"
@@ -10,7 +11,7 @@ import (
10
11
)
11
12
12
13
// Export an application
13
- func Export (db gorp.SqlExecutor , key string , appName string , encryptFunc sdk.EncryptFunc ) (exportentities.Application , error ) {
14
+ func Export (ctx context. Context , db gorp.SqlExecutor , key string , appName string , encryptFunc sdk.EncryptFunc ) (exportentities.Application , error ) {
14
15
app , err := LoadByNameWithClearVCSStrategyPassword (db , key , appName ,
15
16
LoadOptions .WithVariablesWithClearPassword ,
16
17
LoadOptions .WithClearKeys ,
@@ -20,19 +21,19 @@ func Export(db gorp.SqlExecutor, key string, appName string, encryptFunc sdk.Enc
20
21
return exportentities.Application {}, sdk .WrapError (err , "cannot load application %s" , appName )
21
22
}
22
23
23
- return ExportApplication (db , * app , encryptFunc , fmt .Sprintf ("appID:%d" , app .ID ))
24
+ return ExportApplication (ctx , db , * app , encryptFunc , fmt .Sprintf ("appID:%d" , app .ID ))
24
25
}
25
26
26
27
// ExportApplication encrypt and export
27
- func ExportApplication (db gorp.SqlExecutor , app sdk.Application , encryptFunc sdk.EncryptFunc , encryptPrefix string ) (exportentities.Application , error ) {
28
+ func ExportApplication (ctx context. Context , db gorp.SqlExecutor , app sdk.Application , encryptFunc sdk.EncryptFunc , encryptPrefix string ) (exportentities.Application , error ) {
28
29
var appvars []sdk.ApplicationVariable
29
30
for _ , v := range app .Variables {
30
31
switch v .Type {
31
32
case sdk .KeyVariable :
32
33
return exportentities.Application {}, sdk .NewErrorFrom (sdk .ErrUnknownError ,
33
34
"variable %s: variable of type key are deprecated. Please use the standard keys from your project or your application" , v .Name )
34
35
case sdk .SecretVariable :
35
- content , err := encryptFunc (db , app .ProjectID , fmt .Sprintf ("%s:%s" , encryptPrefix , v .Name ), v .Value )
36
+ content , err := encryptFunc (ctx , db , app .ProjectID , fmt .Sprintf ("%s:%s" , encryptPrefix , v .Name ), v .Value )
36
37
if err != nil {
37
38
return exportentities.Application {}, sdk .WrapError (err , "unknown key type" )
38
39
}
@@ -48,7 +49,7 @@ func ExportApplication(db gorp.SqlExecutor, app sdk.Application, encryptFunc sdk
48
49
var keys []exportentities.EncryptedKey
49
50
// Parse keys
50
51
for _ , k := range app .Keys {
51
- content , err := encryptFunc (db , app .ProjectID , fmt .Sprintf ("%s:%s" , encryptPrefix , k .Name ), k .Private )
52
+ content , err := encryptFunc (ctx , db , app .ProjectID , fmt .Sprintf ("%s:%s" , encryptPrefix , k .Name ), k .Private )
52
53
if err != nil {
53
54
return exportentities.Application {}, sdk .WrapError (err , "unable to encrypt key" )
54
55
}
@@ -61,7 +62,7 @@ func ExportApplication(db gorp.SqlExecutor, app sdk.Application, encryptFunc sdk
61
62
}
62
63
63
64
if app .RepositoryStrategy .Password != "" {
64
- content , err := encryptFunc (db , app .ProjectID , fmt .Sprintf ("%s:%s" , encryptPrefix , "vcs:password" ), app .RepositoryStrategy .Password )
65
+ content , err := encryptFunc (ctx , db , app .ProjectID , fmt .Sprintf ("%s:%s" , encryptPrefix , "vcs:password" ), app .RepositoryStrategy .Password )
65
66
if err != nil {
66
67
return exportentities.Application {}, sdk .WrapError (err , "unable to encrypt password" )
67
68
}
@@ -71,7 +72,7 @@ func ExportApplication(db gorp.SqlExecutor, app sdk.Application, encryptFunc sdk
71
72
for pfName , pfConfig := range app .DeploymentStrategies {
72
73
for k , v := range pfConfig {
73
74
if v .Type == sdk .SecretVariable {
74
- content , err := encryptFunc (db , app .ProjectID , fmt .Sprintf ("%s:%s:%s:%s" , encryptPrefix , pfName , k , "deployment:password" ), v .Value )
75
+ content , err := encryptFunc (ctx , db , app .ProjectID , fmt .Sprintf ("%s:%s:%s:%s" , encryptPrefix , pfName , k , "deployment:password" ), v .Value )
75
76
if err != nil {
76
77
return exportentities.Application {}, sdk .WrapError (err , "Unable to encrypt password" )
77
78
}
0 commit comments