Skip to content
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

ref: unify signature of plugin get_config #74880

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sentry/api/serializers/models/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_attrs(self, item_list, user, **kwargs):
"config": [
serialize_field(self.project, item, c)
for c in item.get_config(
project=self.project, user=user, add_additial_fields=True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lolright

project=self.project, user=user, add_additional_fields=True
)
]
}
Expand Down
6 changes: 4 additions & 2 deletions src/sentry/plugins/bases/issue2.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,11 @@ def plugin_issues(self, request: Request, group, plugin_issues, **kwargs) -> Non
item.update(PluginSerializer(group.project).serialize(self, None, request.user))
plugin_issues.append(item)

def get_config(self, *args, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
# TODO(dcramer): update existing plugins to just use get_config
return self.get_configure_plugin_fields(*args, **kwargs)
return self.get_configure_plugin_fields(
project=project, user=user, initial=initial, add_additional_fields=add_additional_fields
)

def check_config_and_auth(self, request: Request, group):
has_auth_configured = self.has_auth_configured()
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/plugins/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_metadata(self):
"""
return {}

def get_config(self, project, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
form = self.project_conf_form
if not form:
return []
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/plugins/sentry_webhooks/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class WebHooksPlugin(notify.NotificationPlugin):
def is_configured(self, project, **kwargs):
return bool(self.get_option("urls", project))

def get_config(self, project, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
return [
{
"name": "urls",
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/amazon_sqs/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AmazonSQSPlugin(CorePluginMixin, DataForwardingPlugin):
)
]

def get_config(self, project, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
return [
{
"name": "queue_url",
Expand Down
5 changes: 2 additions & 3 deletions src/sentry_plugins/asana/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ def validate_config(self, project, config, actor):
raise PluginError("Non-numeric workspace value")
return config

def get_config(self, *args, **kwargs):
user = kwargs["user"]
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
try:
client = self.get_client(user)
except PluginIdentityRequired as e:
Expand All @@ -208,7 +207,7 @@ def get_config(self, *args, **kwargs):
raise PluginIdentityRequired(ERR_BEARER_EXPIRED)
raise
workspace_choices = self.get_workspace_choices(workspaces)
workspace = self.get_option("workspace", kwargs["project"])
workspace = self.get_option("workspace", project)
# check to make sure the current user has access to the workspace
helptext = None
if workspace and not self.has_workspace_access(workspace, workspace_choices):
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/heroku/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def has_project_conf(self):
def get_conf_key(self):
return "heroku"

def get_config(self, project, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
repo_list = list(Repository.objects.filter(organization_id=project.organization_id))
if not ProjectOption.objects.get_value(project=project, key="heroku:repository"):
choices = [("", "select a repo")]
Expand Down
4 changes: 2 additions & 2 deletions src/sentry_plugins/pagerduty/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def error_message_from_json(self, data):
def is_configured(self, project, **kwargs):
return bool(self.get_option("service_key", project))

def get_config(self, **kwargs):
service_key = self.get_option("service_key", kwargs["project"])
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
service_key = self.get_option("service_key", project)
secret_field = get_secret_field_config(
service_key, "PagerDuty's Sentry service Integration Key", include_prefix=True
)
Expand Down
6 changes: 3 additions & 3 deletions src/sentry_plugins/pushover/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class PushoverPlugin(CorePluginMixin, NotifyPlugin):
def is_configured(self, project):
return all(self.get_option(key, project) for key in ("userkey", "apikey"))

def get_config(self, **kwargs):
userkey = self.get_option("userkey", kwargs["project"])
apikey = self.get_option("apikey", kwargs["project"])
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
userkey = self.get_option("userkey", project)
apikey = self.get_option("apikey", project)

userkey_field = get_secret_field_config(
userkey, "Your user key. See https://pushover.net/", include_prefix=True
Expand Down
4 changes: 2 additions & 2 deletions src/sentry_plugins/redmine/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ def build_initial(self, initial_args, project):
initial[field] = value
return initial

def get_config(self, project, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
self.client_errors = []
self.fields = self.build_config()
initial_args = kwargs.get("initial") or {}
initial_args = initial or {}
initial = self.build_initial(initial_args, project)

has_credentials = all(initial.get(k) for k in ("host", "key"))
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/segment/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SegmentPlugin(CorePluginMixin, DataForwardingPlugin):
)
]

def get_config(self, project, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
return [
get_secret_field_config(
name="write_key",
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/sessionstack/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def validate_config(self, project, config, actor=None):

return config

def get_config(self, project, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
account_email = self.get_option("account_email", project)
api_token = self.get_option("api_token", project)
website_id = self.get_option("website_id", project)
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/slack/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class SlackPlugin(CorePluginMixin, notify.NotificationPlugin):
def is_configured(self, project):
return bool(self.get_option("webhook", project))

def get_config(self, project, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
return [
{
"name": "webhook",
Expand Down
2 changes: 1 addition & 1 deletion src/sentry_plugins/splunk/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_rate_limit(self):
def get_client(self):
return SplunkApiClient(self.project_instance, self.project_token)

def get_config(self, project, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
return [
{
"name": "instance",
Expand Down
6 changes: 3 additions & 3 deletions src/sentry_plugins/trello/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class TrelloPlugin(CorePluginMixin, IssuePlugin2):
),
]

def get_config(self, project, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
"""
Return the configuration of the plugin.
Pull the value out of our the arguments to this function or from the DB
"""

def get_value(field):
initial_values = kwargs.get("initial", {})
initial_values = initial or {}
return initial_values.get(field) or self.get_option(field, project)

token_config: dict[str, object] = {
Expand Down Expand Up @@ -87,7 +87,7 @@ def get_value(field):

config = [key_config, token_config]
org_value = get_value("organization")
include_org = kwargs.get("add_additial_fields", org_value)
include_org = add_additional_fields or org_value
if api_key and token_val and include_org:
trello_client = TrelloApiClient(api_key, token_val)
try:
Expand Down
4 changes: 2 additions & 2 deletions src/sentry_plugins/victorops/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class VictorOpsPlugin(CorePluginMixin, NotifyPlugin):
def is_configured(self, project, **kwargs):
return bool(self.get_option("api_key", project))

def get_config(self, **kwargs):
def get_config(self, project, user=None, initial=None, add_additional_fields: bool = False):
return [
get_secret_field_config(
name="api_key",
label="API Key",
secret=self.get_option("api_key", kwargs["project"]),
secret=self.get_option("api_key", project),
help_text="VictorOps's Sentry API Key",
include_prefix=True,
),
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry_plugins/trello/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_get_config_include_additional(self):
"https://api.trello.com/1/members/me/organizations",
json=[{"name": "team 1", "id": "2d8e"}, {"name": "team 2", "id": "d0cc"}],
)
out = self.plugin.get_config(self.project, add_additial_fields=True)
out = self.plugin.get_config(self.project, add_additional_fields=True)
assert out == [
{
"default": "39g",
Expand Down
Loading