Skip to content

Commit

Permalink
Feat/sendstatement properties on did change config (#2871)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guttz authored Sep 6, 2024
1 parent 6086d94 commit 0fa4940
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
9 changes: 5 additions & 4 deletions pkg/flink/app/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ func StartApp(gatewayClient ccloudv2.GatewayClientInterface, tokenRefreshFunc fu
// Instantiate Component Controllers
lspCompleter := lsp.LspCompleter(lspClient, func() lsp.CliContext {
return lsp.CliContext{
AuthToken: getAuthToken(),
Catalog: userProperties.Get(config.KeyCatalog),
Database: userProperties.Get(config.KeyDatabase),
ComputePoolId: appOptions.GetComputePoolId(),
AuthToken: getAuthToken(),
Catalog: userProperties.Get(config.KeyCatalog),
Database: userProperties.Get(config.KeyDatabase),
ComputePoolId: appOptions.GetComputePoolId(),
StatementProperties: userProperties.GetMaskedNonLocalProperties(),
}
})

Expand Down
2 changes: 2 additions & 0 deletions pkg/flink/internal/controller/input_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ func (c *InputController) initPrompt() (prompt.IPrompt, error) {
prompt.OptionSelectedSuggestionBGColor(prompt.LightGray),
prompt.OptionSuggestionBGColor(prompt.DarkGray),
prompt.OptionSetLexer(highlighting.Lexer),
prompt.OptionDiagnosticsDetailsBGColor(prompt.Red),
prompt.OptionDiagnosticsDetailsTextColor(prompt.White),
prompt.OptionSetStatementTerminator(func(lastKeyStroke prompt.Key, buffer *prompt.Buffer) bool {
text := buffer.Text()
text = strings.TrimSpace(text)
Expand Down
13 changes: 13 additions & 0 deletions pkg/flink/internal/store/user_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ func (p *UserProperties) GetNonLocalProperties() map[string]string {
return nonLocalProperties
}

// GetMaskedNonLocalProperties returns the same as GetNonLocalProperties but with sensitive values masked
func (p *UserProperties) GetMaskedNonLocalProperties() map[string]string {
maskedProperties := p.GetNonLocalProperties()
for key := range maskedProperties {
if !strings.HasPrefix(key, config.NamespaceClient) {
if hasSensitiveKey(key) {
maskedProperties[key] = "hidden"
}
}
}
return maskedProperties
}

func (p *UserProperties) Delete(key string) {
defaultValue, isDefaultKey := p.defaultProperties[key]
if isDefaultKey {
Expand Down
21 changes: 20 additions & 1 deletion pkg/flink/internal/store/user_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,26 @@ func (s *UserPropertiesTestSuite) TestShouldOnlyReturnNonLocalNamespacePropertie
s.userProperties.Set(config.KeyCatalog, "test-catalog")

require.Equal(s.T(), map[string]string{
config.KeyCatalog: "test-catalog",
"default-key": "default-value",
config.KeyCatalog: "test-catalog",
}, s.userProperties.GetNonLocalProperties())
}

func (s *UserPropertiesTestSuite) TestShouldReturnMaskedProperties() {
// Test if non local non sensitive keys are preserved
s.userProperties.Set(config.KeyResultsTimeout, "1000")
s.userProperties.Set(config.KeyCatalog, "test-catalog")

expectedProperties := map[string]string{
"default-key": "default-value",
config.KeyCatalog: "test-catalog",
}
require.Equal(s.T(), expectedProperties, s.userProperties.GetMaskedNonLocalProperties())

// Test if sensitive keys are masked
secretKey := config.KeySqlSecrets + "api_key_1"
s.userProperties.Set(secretKey, "my-apy-key-value")

expectedProperties[secretKey] = "hidden"
require.Equal(s.T(), expectedProperties, s.userProperties.GetMaskedNonLocalProperties())
}
9 changes: 5 additions & 4 deletions pkg/flink/lsp/lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ type LSPClient struct {
}

type CliContext struct {
AuthToken string
Catalog string
Database string
ComputePoolId string
AuthToken string
Catalog string
Database string
ComputePoolId string
StatementProperties map[string]string
}

func NewLSPClient(conn types.JSONRpcConn) *LSPClient {
Expand Down
1 change: 1 addition & 0 deletions pkg/flink/types/user_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type UserPropertiesInterface interface {
Clear()
Delete(key string)
Get(key string) string
GetMaskedNonLocalProperties() map[string]string
GetNonLocalProperties() map[string]string
GetOrDefault(key string, defaultValue string) string
GetOutputFormat() config.OutputFormat
Expand Down

0 comments on commit 0fa4940

Please sign in to comment.