-
Notifications
You must be signed in to change notification settings - Fork 763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: updating pubsub system #3646
Open
JaydipGabani
wants to merge
12
commits into
open-policy-agent:master
Choose a base branch
from
JaydipGabani:exporter-interface
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
71820bd
updating violation system
JaydipGabani 5c0eb8c
fixing errors
JaydipGabani 7c48595
fixing unit tests
JaydipGabani c6ef42d
Merge branch 'master' into exporter-interface
JaydipGabani d8f3524
Merge branch 'master' into exporter-interface
JaydipGabani 6574a0c
Merge branch 'master' into exporter-interface
JaydipGabani 6f82df9
updating export interface
JaydipGabani 07c07ac
updating docs
JaydipGabani 32c9d88
Merge branch 'master' into exporter-interface
JaydipGabani 150f347
Merge branch 'master' into exporter-interface
JaydipGabani 887fa35
fixing doc link for website
JaydipGabani cd49d2e
Merge branch 'master' into exporter-interface
JaydipGabani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,88 @@ | ||
package dapr | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
daprClient "github.com/dapr/go-sdk/client" | ||
) | ||
|
||
type Connection struct { | ||
// Name of the component object to use in Dapr | ||
component string | ||
|
||
client daprClient.Client | ||
} | ||
|
||
// Dapr represents driver to use Dapr. | ||
type Dapr struct { | ||
openConnections map[string]Connection | ||
} | ||
|
||
const ( | ||
Name = "dapr" | ||
) | ||
|
||
var Connections = &Dapr{ | ||
openConnections: make(map[string]Connection), | ||
} | ||
|
||
func (r *Dapr) Publish(_ context.Context, connectionName string, data interface{}, topic string) error { | ||
jsonData, err := json.Marshal(data) | ||
if err != nil { | ||
return fmt.Errorf("error marshaling data: %w", err) | ||
} | ||
|
||
conn, ok := r.openConnections[connectionName] | ||
if !ok { | ||
return fmt.Errorf("connection not found: %s for Dapr driver", connectionName) | ||
} | ||
err = conn.client.PublishEvent(context.Background(), conn.component, topic, jsonData) | ||
if err != nil { | ||
return fmt.Errorf("error publishing message to dapr: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *Dapr) CloseConnection(connectionName string) error { | ||
delete(r.openConnections, connectionName) | ||
return nil | ||
} | ||
|
||
func (r *Dapr) UpdateConnection(_ context.Context, connectionName string, config interface{}) error { | ||
cfg, ok := config.(map[string]interface{}) | ||
if !ok { | ||
return fmt.Errorf("invalid type assertion, config is not in expected format") | ||
} | ||
component, ok := cfg["component"].(string) | ||
if !ok { | ||
return fmt.Errorf("failed to get value of component") | ||
} | ||
conn := r.openConnections[connectionName] | ||
conn.component = component | ||
r.openConnections[connectionName] = conn | ||
return nil | ||
} | ||
|
||
func (r *Dapr) CreateConnection(_ context.Context, connectionName string, config interface{}) error { | ||
var conn Connection | ||
cfg, ok := config.(map[string]interface{}) | ||
if !ok { | ||
return fmt.Errorf("invalid type assertion, config is not in expected format") | ||
} | ||
conn.component, ok = cfg["component"].(string) | ||
if !ok { | ||
return fmt.Errorf("failed to get value of component") | ||
} | ||
|
||
tmp, err := daprClient.NewClient() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
conn.client = tmp | ||
r.openConnections[connectionName] = conn | ||
return nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to rename the flag to remove
pub-sub
word?