Repository: slackapi/python-slack-sdk
Pull request #872 (2020-11-07 14:17:06)

Addition to #871: AsyncOAuthStateStore and built-in implementations
## Summary

This pull request appends additional changes to #871 

### Category (place an `x` in each of the `[ ]`)

- [ ] **slack_sdk.web.WebClient** (Web API client)
- [ ] **slack_sdk.webhook.WebhookClient** (Incoming Webhook, response_url sender)
- [ ] **slack_sdk.models** (UI component builders)
- [x] **slack_sdk.oauth** (OAuth Flow Utilities)
- [ ] **slack_sdk.rtm.RTMClient** (RTM client)
- [ ] **slack_sdk.signature** (Request Signature Verifier)
- [ ] `/docs-src` (Documents, have you run `./docs.sh`?)
- [ ] `/docs-src-v2` (Documents, have you run `./docs-v2.sh`?)

## Requirements (place an `x` in each `[ ]`)

- [x] I've read and understood the [Contributing Guidelines](https://github.com/slackapi/python-slack-sdk/blob/main/.github/contributing.md) and have done my best effort to follow them.
- [x] I've read and agree to the [Code of Conduct](https://slackhq.github.io/code-of-conduct).
- [x] I've run `python setup.py validate` after making the changes.


codecov[bot]: # [Codecov](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872?src=pr&el=h1) Report
> Merging [#872](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872?src=pr&el=desc) (8e32f15) into [main](https://codecov.io/gh/slackapi/python-slack-sdk/commit/dca70886d2535dd843ea995b8d193958997de41b?el=desc) (dca7088) will **not change** coverage.
> The diff coverage is `54.54%`.

[![Impacted file tree graph](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872/graphs/tree.svg?width=650&height=150&src=pr&token=F0O7meYmtD)](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##             main     #872   +/-   ##
=======================================
  Coverage   76.28%   76.28%           
=======================================
  Files          35       35           
  Lines        3226     3226           
=======================================
  Hits         2461     2461           
  Misses        765      765           
```


| [Impacted Files](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [slack\_sdk/oauth/state\_store/amazon\_s3/\_\_init\_\_.py](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872/diff?src=pr&el=tree#diff-c2xhY2tfc2RrL29hdXRoL3N0YXRlX3N0b3JlL2FtYXpvbl9zMy9fX2luaXRfXy5weQ==) | `0.00% <0.00%> (ø)` | |
| [slack\_sdk/oauth/state\_store/file/\_\_init\_\_.py](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872/diff?src=pr&el=tree#diff-c2xhY2tfc2RrL29hdXRoL3N0YXRlX3N0b3JlL2ZpbGUvX19pbml0X18ucHk=) | `92.30% <66.66%> (ø)` | |
| [slack\_sdk/oauth/state\_store/sqlite3/\_\_init\_\_.py](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872/diff?src=pr&el=tree#diff-c2xhY2tfc2RrL29hdXRoL3N0YXRlX3N0b3JlL3NxbGl0ZTMvX19pbml0X18ucHk=) | `87.69% <66.66%> (ø)` | |
| [slack\_sdk/oauth/state\_store/async\_state\_store.py](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872/diff?src=pr&el=tree#diff-c2xhY2tfc2RrL29hdXRoL3N0YXRlX3N0b3JlL2FzeW5jX3N0YXRlX3N0b3JlLnB5) | `66.66% <100.00%> (ø)` | |
| [slack\_sdk/oauth/state\_store/sqlalchemy/\_\_init\_\_.py](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872/diff?src=pr&el=tree#diff-c2xhY2tfc2RrL29hdXRoL3N0YXRlX3N0b3JlL3NxbGFsY2hlbXkvX19pbml0X18ucHk=) | `90.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872?src=pr&el=footer). Last update [dca7088...8e32f15](https://codecov.io/gh/slackapi/python-slack-sdk/pull/872?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/scripts/run_validation.sh b/scripts/run_validation.sh
new file mode 100755
index 0000000..8f7f432
--- /dev/null
+++ b/scripts/run_validation.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+# ./scripts/run_validation.sh
+
+script_dir=`dirname $0`
+cd ${script_dir}/..
+black slack_sdk/ slack/ tests/ && \
+  python setup.py codegen && \
+  python setup.py validate
diff --git a/setup.py b/setup.py
index 2a36d06..8725330 100644
--- a/setup.py
+++ b/setup.py
@@ -187,10 +187,10 @@ class ValidateCommand(BaseCommand):
             "Running black ...", [sys.executable, "-m", "black", f"{here}/slack_sdk"]
         )
         self._run(
-            "Running flake8 ...", [sys.executable, "-m", "flake8", f"{here}/slack"]
+            "Running flake8 for legacy packages ...", [sys.executable, "-m", "flake8", f"{here}/slack"]
         )
         self._run(
-            "Running flake8 ...", [sys.executable, "-m", "flake8", f"{here}/slack_sdk"]
+            "Running flake8 for slack_sdk package ...", [sys.executable, "-m", "flake8", f"{here}/slack_sdk"]
         )
 
         target = self.test_target.replace("tests/", "", 1)
diff --git a/slack_sdk/oauth/state_store/amazon_s3/__init__.py b/slack_sdk/oauth/state_store/amazon_s3/__init__.py
index 518548e..06a5de2 100644
--- a/slack_sdk/oauth/state_store/amazon_s3/__init__.py
+++ b/slack_sdk/oauth/state_store/amazon_s3/__init__.py
@@ -29,13 +29,13 @@ class AmazonS3OAuthStateStore(OAuthStateStore, AsyncOAuthStateStore):
             self._logger = logging.getLogger(__name__)
         return self._logger
 
-    async def async_issue(self) -> str:
-        return self.issue()
+    async def async_issue(self, *args, **kwargs) -> str:
+        return self.issue(*args, **kwargs)
 
     async def async_consume(self, state: str) -> bool:
         return self.consume(state)
 
-    def issue(self) -> str:
+    def issue(self, *args, **kwargs) -> str:
         state = str(uuid4())
         response = self.s3_client.put_object(
             Bucket=self.bucket_name, Body=str(time.time()), Key=state,
diff --git a/slack_sdk/oauth/state_store/async_state_store.py b/slack_sdk/oauth/state_store/async_state_store.py
index d5add58..22e883b 100644
--- a/slack_sdk/oauth/state_store/async_state_store.py
+++ b/slack_sdk/oauth/state_store/async_state_store.py
@@ -6,7 +6,7 @@ class AsyncOAuthStateStore:
     def logger(self) -> Logger:
         raise NotImplementedError()
 
-    async def async_issue(self) -> str:
+    async def async_issue(self, *args, **kwargs) -> str:
         raise NotImplementedError()
 
     async def async_consume(self, state: str) -> bool:
diff --git a/slack_sdk/oauth/state_store/file/__init__.py b/slack_sdk/oauth/state_store/file/__init__.py
index ae73c35..ffd619c 100644
--- a/slack_sdk/oauth/state_store/file/__init__.py
+++ b/slack_sdk/oauth/state_store/file/__init__.py
@@ -33,13 +33,13 @@ class FileOAuthStateStore(OAuthStateStore, AsyncOAuthStateStore):
             self._logger = logging.getLogger(__name__)
         return self._logger
 
-    async def async_issue(self) -> str:
-        return self.issue()
+    async def async_issue(self, *args, **kwargs) -> str:
+        return self.issue(*args, **kwargs)
 
     async def async_consume(self, state: str) -> bool:
         return self.consume(state)
 
-    def issue(self) -> str:
+    def issue(self, *args, **kwargs) -> str:
         state = str(uuid4())
         self._mkdir(self.base_dir)
         filepath = f"{self.base_dir}/{state}"
diff --git a/slack_sdk/oauth/state_store/sqlalchemy/__init__.py b/slack_sdk/oauth/state_store/sqlalchemy/__init__.py
index 3caf9d4..b90f415 100644
--- a/slack_sdk/oauth/state_store/sqlalchemy/__init__.py
+++ b/slack_sdk/oauth/state_store/sqlalchemy/__init__.py
@@ -48,7 +48,7 @@ class SQLAlchemyOAuthStateStore(OAuthStateStore):
             self._logger = logging.getLogger(__name__)
         return self._logger
 
-    def issue(self) -> str:
+    def issue(self, *args, **kwargs) -> str:
         state: str = str(uuid4())
         now = datetime.utcfromtimestamp(time.time() + self.expiration_seconds)
         with self.engine.begin() as conn:
diff --git a/slack_sdk/oauth/state_store/sqlite3/__init__.py b/slack_sdk/oauth/state_store/sqlite3/__init__.py
index e0f30d0..89418ce 100644
--- a/slack_sdk/oauth/state_store/sqlite3/__init__.py
+++ b/slack_sdk/oauth/state_store/sqlite3/__init__.py
@@ -59,13 +59,13 @@ class SQLite3OAuthStateStore(OAuthStateStore, AsyncOAuthStateStore):
             self.logger.debug(f"Tables have been created (database: {self.database})")
             conn.commit()
 
-    async def async_issue(self) -> str:
-        return self.issue()
+    async def async_issue(self, *args, **kwargs) -> str:
+        return self.issue(*args, **kwargs)
 
     async def async_consume(self, state: str) -> bool:
         return self.consume(state)
 
-    def issue(self) -> str:
+    def issue(self, *args, **kwargs) -> str:
         state: str = str(uuid4())
         with self.connect() as conn:
             parameters = [


Test patch:
diff --git a/tests/slack_sdk/oauth/state_store/test_file.py b/tests/slack_sdk/oauth/state_store/test_file.py
index 74d2a72..49e430c 100644
--- a/tests/slack_sdk/oauth/state_store/test_file.py
+++ b/tests/slack_sdk/oauth/state_store/test_file.py
@@ -21,3 +21,7 @@ class TestFile(unittest.TestCase):
         self.assertTrue(result)
         result = store.consume(state)
         self.assertFalse(result)
+
+    def test_kwargs(self):
+        store = FileOAuthStateStore(expiration_seconds=10)
+        store.issue(foo=123, bar="baz")