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

Fix #1427 Add apps.manifest.* & tooling.tokens.rotate API support #1430

Merged
merged 1 commit into from
Nov 21, 2023
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
200 changes: 200 additions & 0 deletions integration_tests/web/test_app_manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
import os
import unittest

from slack_sdk.web import WebClient


class TestWebClient(unittest.TestCase):
"""Runs integration tests with real Slack API"""

def setUp(self):
pass

def tearDown(self):
pass

def test_operations(self):
token = os.environ["SLACK_SDK_TEST_TOOLING_TOKEN"] # xoxe.xoxp-...
client = WebClient(token)
client.apps_manifest_validate(manifest=STR_MANIFEST)
client.apps_manifest_validate(manifest=DICT_MANIFEST)

response = client.apps_manifest_create(manifest=STR_MANIFEST)
app_id = response["app_id"]
try:
client.apps_manifest_update(app_id=app_id, manifest=DICT_MANIFEST)
client.apps_manifest_export(app_id=app_id)
finally:
client.apps_manifest_delete(app_id=app_id)


STR_MANIFEST = """{
"display_information": {
"name": "manifest-sandbox"
},
"features": {
"app_home": {
"home_tab_enabled": true,
"messages_tab_enabled": false,
"messages_tab_read_only_enabled": false
},
"bot_user": {
"display_name": "manifest-sandbox",
"always_online": true
},
"shortcuts": [
{
"name": "message one",
"type": "message",
"callback_id": "m",
"description": "message"
},
{
"name": "global one",
"type": "global",
"callback_id": "g",
"description": "global"
}
],
"slash_commands": [
{
"command": "/hey",
"url": "https://www.example.com/",
"description": "What's up?",
"usage_hint": "What's up?",
"should_escape": true
}
],
"unfurl_domains": [
"example.com"
]
},
"oauth_config": {
"redirect_urls": [
"https://www.example.com/foo"
],
"scopes": {
"user": [
"search:read",
"channels:read",
"groups:read",
"mpim:read"
],
"bot": [
"commands",
"incoming-webhook",
"app_mentions:read",
"links:read"
]
}
},
"settings": {
"allowed_ip_address_ranges": [
"123.123.123.123/32"
],
"event_subscriptions": {
"request_url": "https://www.example.com/slack/events",
"user_events": [
"member_joined_channel"
],
"bot_events": [
"app_mention",
"link_shared"
]
},
"interactivity": {
"is_enabled": true,
"request_url": "https://www.example.com/",
"message_menu_options_url": "https://www.example.com/"
},
"org_deploy_enabled": true,
"socket_mode_enabled": false,
"token_rotation_enabled": true
}
}
"""

DICT_MANIFEST = {
"display_information": {
"name": "manifest-sandbox"
},
"features": {
"app_home": {
"home_tab_enabled": True,
"messages_tab_enabled": False,
"messages_tab_read_only_enabled": False
},
"bot_user": {
"display_name": "manifest-sandbox",
"always_online": True
},
"shortcuts": [
{
"name": "message one",
"type": "message",
"callback_id": "m",
"description": "message"
},
{
"name": "global one",
"type": "global",
"callback_id": "g",
"description": "global"
}
],
"slash_commands": [
{
"command": "/hey",
"url": "https://www.example.com/",
"description": "What's up?",
"usage_hint": "What's up?",
"should_escape": True
}
],
"unfurl_domains": [
"example.com"
]
},
"oauth_config": {
"redirect_urls": [
"https://www.example.com/foo"
],
"scopes": {
"user": [
"search:read",
"channels:read",
"groups:read",
"mpim:read"
],
"bot": [
"commands",
"incoming-webhook",
"app_mentions:read",
"links:read"
]
}
},
"settings": {
"allowed_ip_address_ranges": [
"123.123.123.123/32"
],
"event_subscriptions": {
"request_url": "https://www.example.com/slack/events",
"user_events": [
"member_joined_channel"
],
"bot_events": [
"app_mention",
"link_shared"
]
},
"interactivity": {
"is_enabled": True,
"request_url": "https://www.example.com/",
"message_menu_options_url": "https://www.example.com/"
},
"org_deploy_enabled": True,
"socket_mode_enabled": False,
"token_rotation_enabled": True
}
}
85 changes: 85 additions & 0 deletions slack_sdk/web/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,91 @@
kwargs.update({"client_id": client_id, "client_secret": client_secret})
return await self.api_call("apps.uninstall", params=kwargs)

async def apps_manifest_create(
self,
*,
manifest: Union[str, Dict[str, Any]],
**kwargs,
) -> AsyncSlackResponse:
"""Create an app from an app manifest
https://api.slack.com/methods/apps.manifest.create
"""
if isinstance(manifest, str):
kwargs.update({"manifest": manifest})
else:
kwargs.update({"manifest": json.dumps(manifest)})

Check warning on line 1943 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L1943

Added line #L1943 was not covered by tests
return await self.api_call("apps.manifest.create", params=kwargs)

async def apps_manifest_delete(
self,
*,
app_id: str,
**kwargs,
) -> AsyncSlackResponse:
"""Permanently deletes an app created through app manifests
https://api.slack.com/methods/apps.manifest.delete
"""
kwargs.update({"app_id": app_id})
return await self.api_call("apps.manifest.delete", params=kwargs)

async def apps_manifest_export(
self,
*,
app_id: str,
**kwargs,
) -> AsyncSlackResponse:
"""Export an app manifest from an existing app
https://api.slack.com/methods/apps.manifest.export
"""
kwargs.update({"app_id": app_id})
return await self.api_call("apps.manifest.export", params=kwargs)

async def apps_manifest_update(
self,
*,
app_id: str,
manifest: Union[str, Dict[str, Any]],
**kwargs,
) -> AsyncSlackResponse:
"""Update an app from an app manifest
https://api.slack.com/methods/apps.manifest.update
"""
if isinstance(manifest, str):
kwargs.update({"manifest": manifest})
else:
kwargs.update({"manifest": json.dumps(manifest)})

Check warning on line 1983 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L1983

Added line #L1983 was not covered by tests
kwargs.update({"app_id": app_id})
return await self.api_call("apps.manifest.update", params=kwargs)

async def apps_manifest_validate(
self,
*,
manifest: Union[str, Dict[str, Any]],
app_id: Optional[str] = None,
**kwargs,
) -> AsyncSlackResponse:
"""Validate an app manifest
https://api.slack.com/methods/apps.manifest.validate
"""
if isinstance(manifest, str):
kwargs.update({"manifest": manifest})
else:
kwargs.update({"manifest": json.dumps(manifest)})

Check warning on line 2000 in slack_sdk/web/async_client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/async_client.py#L2000

Added line #L2000 was not covered by tests
kwargs.update({"app_id": app_id})
return await self.api_call("apps.manifest.validate", params=kwargs)

async def tooling_tokens_rotate(
self,
*,
refresh_token: str,
**kwargs,
) -> AsyncSlackResponse:
"""Exchanges a refresh token for a new app configuration token
https://api.slack.com/methods/tooling.tokens.rotate
"""
kwargs.update({"refresh_token": refresh_token})
return await self.api_call("tooling.tokens.rotate", params=kwargs)

async def auth_revoke(
self,
*,
Expand Down
85 changes: 85 additions & 0 deletions slack_sdk/web/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1919,6 +1919,91 @@
kwargs.update({"client_id": client_id, "client_secret": client_secret})
return self.api_call("apps.uninstall", params=kwargs)

def apps_manifest_create(
self,
*,
manifest: Union[str, Dict[str, Any]],
**kwargs,
) -> SlackResponse:
"""Create an app from an app manifest
https://api.slack.com/methods/apps.manifest.create
"""
if isinstance(manifest, str):
kwargs.update({"manifest": manifest})
else:
kwargs.update({"manifest": json.dumps(manifest)})

Check warning on line 1934 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L1934

Added line #L1934 was not covered by tests
return self.api_call("apps.manifest.create", params=kwargs)

def apps_manifest_delete(
self,
*,
app_id: str,
**kwargs,
) -> SlackResponse:
"""Permanently deletes an app created through app manifests
https://api.slack.com/methods/apps.manifest.delete
"""
kwargs.update({"app_id": app_id})
return self.api_call("apps.manifest.delete", params=kwargs)

def apps_manifest_export(
self,
*,
app_id: str,
**kwargs,
) -> SlackResponse:
"""Export an app manifest from an existing app
https://api.slack.com/methods/apps.manifest.export
"""
kwargs.update({"app_id": app_id})
return self.api_call("apps.manifest.export", params=kwargs)

def apps_manifest_update(
self,
*,
app_id: str,
manifest: Union[str, Dict[str, Any]],
**kwargs,
) -> SlackResponse:
"""Update an app from an app manifest
https://api.slack.com/methods/apps.manifest.update
"""
if isinstance(manifest, str):
kwargs.update({"manifest": manifest})
else:
kwargs.update({"manifest": json.dumps(manifest)})

Check warning on line 1974 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L1974

Added line #L1974 was not covered by tests
kwargs.update({"app_id": app_id})
return self.api_call("apps.manifest.update", params=kwargs)

def apps_manifest_validate(
self,
*,
manifest: Union[str, Dict[str, Any]],
app_id: Optional[str] = None,
**kwargs,
) -> SlackResponse:
"""Validate an app manifest
https://api.slack.com/methods/apps.manifest.validate
"""
if isinstance(manifest, str):
kwargs.update({"manifest": manifest})
else:
kwargs.update({"manifest": json.dumps(manifest)})

Check warning on line 1991 in slack_sdk/web/client.py

View check run for this annotation

Codecov / codecov/patch

slack_sdk/web/client.py#L1991

Added line #L1991 was not covered by tests
kwargs.update({"app_id": app_id})
return self.api_call("apps.manifest.validate", params=kwargs)

def tooling_tokens_rotate(
self,
*,
refresh_token: str,
**kwargs,
) -> SlackResponse:
"""Exchanges a refresh token for a new app configuration token
https://api.slack.com/methods/tooling.tokens.rotate
"""
kwargs.update({"refresh_token": refresh_token})
return self.api_call("tooling.tokens.rotate", params=kwargs)

def auth_revoke(
self,
*,
Expand Down
Loading
Loading