@@ -4,8 +4,17 @@ import (
44 "fmt"
55 "log"
66 "net/url"
7+
8+ "golang.org/x/exp/slices"
79)
810
11+ var encryptedContextTypes = []string {
12+ "secret" ,
13+ "secret-yaml" ,
14+ "storage.s3" ,
15+ "storage.azuref" ,
16+ }
17+
918type ContextErrorResponse struct {
1019 Status int `json:"status,omitempty"`
1120 Message string `json:"message,omitempty"`
@@ -17,9 +26,10 @@ type ContextMetadata struct {
1726}
1827
1928type 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"`
2333}
2434
2535type ContextSpec struct {
@@ -32,7 +42,18 @@ func (context *Context) GetID() string {
3242}
3343
3444func (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+
3657 opts := RequestOptions {
3758 Path : fullPath ,
3859 Method : "GET" ,
@@ -49,8 +70,17 @@ func (client *Client) GetContext(name string) (*Context, error) {
4970 return nil , err
5071 }
5172
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 )
5376
77+ respContext .IsEncrypred = false
78+
79+ if forbidDecrypt && isEncryptedType {
80+ respContext .IsEncrypred = true
81+ }
82+
83+ return & respContext , nil
5484}
5585
5686func (client * Client ) CreateContext (context * Context ) (* Context , error ) {
0 commit comments