Repository: getsentry/sentry

Issue:
feat(api): allow the configuration of a provider
This MR fixes the ability to provide boolean values to the organization detail API and also adds the ablity to add a provider to the organization via API.

It's working. I know that it's not the prettiest way (probably) to solve this, but I'm very much open to improvements and changes!


Discussion:
Not sure what's wrong with `security/snyk (sentry)`. I can't access it.
Hi @max-wittig, thanks for the PR! Ideally this would be split up into multiple PRs, but let's address them here for now.

* re: `defaultRole` - this is already handled here: https://github.com/getsentry/sentry/blob/be3ffa6ce61d40274f432b1612355673cbbe3fe3/src/sentry/api/endpoints/organization_details.py#L322-L334 - only owners of the organization are allowed to set the default role.

* I'm not sure what you mean IRT boolean values as organization details already supports boolean values.

* provider - can you explain further what you're trying to accomplish here?

 
Hi @billyvg thanks for your review!

Sure. I will split these two commits up into multiple PRs. No problem.

* Ah I see, `defaultRole` is handled then. Guess I have to be owner. Weird that you don't have to be owner for the other permissions. For example `require2FA`, but okay.

* Seems like boolean is not supported. When I tried to set these values using the API before, they were just ignored. For example, when I tried to set `openMembership` to `true` or `True` via API, the value was ignored and just stayed like it was. After my fix here, it worked as expected.

* I want to accomplish that you can setup an SSO provider (like GitHub or Google) for an organization via API, not just via the UI.
Is there already an existing API endpoint to do something like this? The API docs are outdated and looking through `urls.py`, I haven't found an endpoint that would make this possible today.
@max-wittig testing localling, this works for me: `curl 'http://localhost:8000/api/0/organizations/sentry/' -X PUT -H 'Accept: application/json; charset=utf-8' -H 'Content-Type: application/json' --data-binary '{"isEarlyAdopter":true}' --compressed`

Is it possible you're sending the boolean value as a string?
@billyvg Yes I was using multi-part forms instead of `application/json`. That's why I couldn't send booleans. 
Thanks for clearing that up!

So I'm just missing the last puzzle piece then 😄 
How do I connect a SSO provider via API to an organization? Is there already a way that I missed?

E.g. `PUT /api/0/organizations/my-org/`

```
{
   "provider": "github"
}
```
@max-wittig I don't really have enough context around this to be helpful here. I'm not sure if this is something we want to expose via APIs -- @leedongwei I know you've been doing work with SSO recently, any thoughts here?
@billyvg I think it should be exposed via API, as you already expose the rest of the config. Why not the SSO setting? 😄 

Resolving patch:
diff --git a/src/sentry/conf/server.py b/src/sentry/conf/server.py
--- a/src/sentry/conf/server.py
+++ b/src/sentry/conf/server.py
@@ -1068,6 +1068,8 @@ def SOCIAL_AUTH_DEFAULT_USERNAME():
     "organizations:advanced-search": True,
     # Use metrics as the dataset for crash free metric alerts
     "organizations:alert-crash-free-metrics": False,
+    # Enable auth provider configuration through api
+    "organizations:api-auth-provider": False,
     "organizations:api-keys": False,
     # Enable multiple Apple app-store-connect sources per project.
     "organizations:app-store-connect-multiple": False,
diff --git a/src/sentry/features/__init__.py b/src/sentry/features/__init__.py
--- a/src/sentry/features/__init__.py
+++ b/src/sentry/features/__init__.py
@@ -201,6 +201,7 @@
 # also be listed in SubscriptionPlanFeatureHandler in getsentry so that sentry.io
 # behaves correctly.
 default_manager.add("organizations:advanced-search", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
+default_manager.add("organizations:api-auth-provider", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
 default_manager.add("organizations:app-store-connect-multiple", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
 default_manager.add("organizations:change-alerts", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
 default_manager.add('organizations:commit-context', OrganizationFeature, FeatureHandlerStrategy.INTERNAL)


Test patch: