@@ -4,8 +4,17 @@ import (
4
4
"fmt"
5
5
"log"
6
6
"net/url"
7
+
8
+ "golang.org/x/exp/slices"
7
9
)
8
10
11
+ var encryptedContextTypes = []string {
12
+ "secret" ,
13
+ "secret-yaml" ,
14
+ "storage.s3" ,
15
+ "storage.azuref" ,
16
+ }
17
+
9
18
type ContextErrorResponse struct {
10
19
Status int `json:"status,omitempty"`
11
20
Message string `json:"message,omitempty"`
@@ -17,9 +26,10 @@ type ContextMetadata struct {
17
26
}
18
27
19
28
type Context struct {
20
- Metadata ContextMetadata `json:"metadata,omitempty"`
21
- Spec ContextSpec `json:"spec,omitempty"`
22
- Version string `json:"version,omitempty"`
29
+ Metadata ContextMetadata `json:"metadata,omitempty"`
30
+ Spec ContextSpec `json:"spec,omitempty"`
31
+ Version string `json:"version,omitempty"`
32
+ IsEncrypred bool `json:"isEncrypted,omitempty"`
23
33
}
24
34
25
35
type ContextSpec struct {
@@ -32,7 +42,18 @@ func (context *Context) GetID() string {
32
42
}
33
43
34
44
func (client * Client ) GetContext (name string ) (* Context , error ) {
35
- fullPath := fmt .Sprintf ("/contexts/%s?decrypt=true" , url .PathEscape (name ))
45
+ fullPath := fmt .Sprintf ("/contexts/%s" , url .PathEscape (name ))
46
+
47
+ forbidDecrypt , err := client .isFeatureFlagEnabled ("forbidDecrypt" )
48
+
49
+ if err != nil {
50
+ forbidDecrypt = false
51
+ }
52
+
53
+ if ! forbidDecrypt {
54
+ fullPath += "?decrypt=true"
55
+ }
56
+
36
57
opts := RequestOptions {
37
58
Path : fullPath ,
38
59
Method : "GET" ,
@@ -49,8 +70,17 @@ func (client *Client) GetContext(name string) (*Context, error) {
49
70
return nil , err
50
71
}
51
72
52
- return & respContext , nil
73
+ // This is so not to break existing behavior while adding support for forbidDecrypt feature flag
74
+ // The provider used to always decrypt the contexts, hence we treat all contexts as decrypted unless forbidDecrypt is set
75
+ isEncryptedType := slices .Contains (encryptedContextTypes , respContext .Spec .Type )
53
76
77
+ respContext .IsEncrypred = false
78
+
79
+ if forbidDecrypt && isEncryptedType {
80
+ respContext .IsEncrypred = true
81
+ }
82
+
83
+ return & respContext , nil
54
84
}
55
85
56
86
func (client * Client ) CreateContext (context * Context ) (* Context , error ) {
0 commit comments