├── docs ├── requirements.txt ├── contributing.rst ├── changelog.rst ├── auth.rst ├── Makefile ├── update_endpoints.py ├── make.bat ├── sample_async_connection.py ├── sample_sync_connection.py ├── index.rst ├── api_deprecation.rst └── mmDriverTokenAuthExample.py ├── src └── mattermostautodriver │ ├── endpoints │ ├── __init__.py │ ├── _base.py │ ├── logs.py │ ├── cluster.py │ ├── bleve.py │ ├── root.py │ ├── permissions.py │ ├── playbook_autofollows.py │ ├── group_message.py │ ├── timeline.py │ ├── agents.py │ ├── usage.py │ ├── imports.py │ ├── elasticsearch.py │ ├── audit_logs.py │ ├── ip.py │ ├── filtering.py │ ├── brand.py │ ├── exports.py │ ├── migrate.py │ ├── authentication.py │ ├── uploads.py │ ├── metrics.py │ ├── reactions.py │ ├── compliance.py │ ├── roles.py │ ├── terms_of_service.py │ ├── preferences.py │ ├── oauth.py │ ├── outgoing_connections.py │ ├── outgoing_oauth_connections.py │ ├── conditions.py │ ├── internal.py │ ├── search.py │ ├── integration_actions.py │ ├── jobs.py │ ├── scheduled_post.py │ ├── custom_profile_attributes.py │ ├── schemes.py │ ├── emoji.py │ └── status.py │ ├── endpoints_old │ ├── __init__.py │ ├── _base.py │ ├── logs.py │ ├── cluster.py │ ├── bleve.py │ ├── root.py │ ├── permissions.py │ ├── playbook_autofollows.py │ ├── group_message.py │ ├── timeline.py │ ├── agents.py │ ├── usage.py │ ├── imports.py │ ├── elasticsearch.py │ ├── audit_logs.py │ ├── ip.py │ ├── metrics.py │ ├── filtering.py │ ├── brand.py │ ├── migrate.py │ ├── exports.py │ ├── authentication.py │ ├── uploads.py │ ├── reactions.py │ ├── compliance.py │ ├── roles.py │ ├── terms_of_service.py │ ├── search.py │ ├── integration_actions.py │ ├── preferences.py │ ├── internal.py │ ├── oauth.py │ ├── outgoing_connections.py │ ├── conditions.py │ ├── scheduled_post.py │ ├── outgoing_oauth_connections.py │ ├── jobs.py │ ├── schemes.py │ ├── reports.py │ ├── custom_profile_attributes.py │ ├── emoji.py │ ├── bookmarks.py │ ├── status.py │ ├── remote_clusters.py │ ├── shared_channels.py │ ├── plugins.py │ ├── commands.py │ └── saml.py │ ├── version.py │ ├── driver │ ├── __init__.py │ └── base.py │ ├── __init__.py │ └── exceptions.py ├── MANIFEST.in ├── requirements.txt ├── .editorconfig ├── .github └── workflows │ ├── lint_black_pull_request.yml │ ├── test_package_build_pull_request.yml │ ├── pypi_release.yml │ ├── build_docs.yml │ └── check_mattermost_new_release_and_self_update.yml ├── pyproject.toml ├── scripts ├── generate_endpoints.sh └── check_release.sh ├── LICENSE ├── CONTRIBUTING.rst ├── setup.py └── .gitignore /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | ../requirements.txt -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CONTRIBUTING.rst -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/changelog.rst: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | ========= 3 | 4 | .. include:: ../CHANGELOG.rst -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.rst 2 | include CHANGELOG.rst 3 | include CONTRIBUTING.rst 4 | include LICENSE -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | aiohttp>=3.9.5,<4.0.0 2 | httpx~=0.28.1 3 | sphinx-rtd-theme 4 | inflection~=0.5.1 5 | black 6 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/_base.py: -------------------------------------------------------------------------------- 1 | class Base: 2 | def __init__(self, client): 3 | self.client = client 4 | -------------------------------------------------------------------------------- /src/mattermostautodriver/version.py: -------------------------------------------------------------------------------- 1 | full_version = "11.2.0" 2 | short_version = ".".join(full_version.split(".", 2)[:2]) 3 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/_base.py: -------------------------------------------------------------------------------- 1 | class Base: 2 | def __init__(self, client): 3 | self.client = client 4 | -------------------------------------------------------------------------------- /src/mattermostautodriver/driver/__init__.py: -------------------------------------------------------------------------------- 1 | from .driver import Driver, AsyncDriver, TypedDriver, AsyncTypedDriver 2 | 3 | 4 | __all__ = ["Driver", "AsyncDriver", "TypedDriver", "AsyncTypedDriver"] 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.yml] 12 | indent_size = 2 13 | indent_style = space 14 | -------------------------------------------------------------------------------- /src/mattermostautodriver/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ["AsyncClient", "AsyncDriver", "Client", "Driver", "Websocket", "AsyncTypedDriver", "TypedDriver"] 2 | from .driver import Driver, AsyncDriver, TypedDriver, AsyncTypedDriver 3 | from .client import Client, AsyncClient 4 | from .websocket import Websocket 5 | -------------------------------------------------------------------------------- /.github/workflows/lint_black_pull_request.yml: -------------------------------------------------------------------------------- 1 | name: Lint using black 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | lint: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v4 10 | - uses: psf/black@stable 11 | with: 12 | options: "--check --verbose ." 13 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.black] 2 | line-length = 120 3 | target-version = ['py310'] 4 | include = 'src\/.*\.py$' 5 | extend-exclude = ''' 6 | # A regex preceded with ^/ will apply only to files and directories 7 | # in the root of the project. 8 | ^/foo.py # exclude a file named foo.py in the root of the project (in addition to the defaults) 9 | ''' 10 | -------------------------------------------------------------------------------- /docs/auth.rst: -------------------------------------------------------------------------------- 1 | Authentication 2 | '''''''''''''' 3 | Yuu can either use the normal ways for login, by token and or username, 4 | or authenticate using the .netrc file. This passes the credentials to the 5 | requests library, where you can also read more about that. 6 | 7 | A nice example for authentication with .netrc by `@apfeiffer `_. 8 | 9 | .. literalinclude:: mmDriverTokenAuthExample.py 10 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/logs.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Logs"] 4 | 5 | 6 | class Logs(Base): 7 | 8 | def download_system_logs(self): 9 | """Download system logs 10 | `Read in Mattermost API docs (logs - DownloadSystemLogs) `_ 11 | 12 | """ 13 | return self.client.get("""/api/v4/logs/download""") 14 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/cluster.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Cluster"] 4 | 5 | 6 | class Cluster(Base): 7 | 8 | def get_cluster_status(self): 9 | """Get cluster status 10 | `Read in Mattermost API docs (cluster - GetClusterStatus) `_ 11 | 12 | """ 13 | return self.client.get("""/api/v4/cluster/status""") 14 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/bleve.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Bleve"] 4 | 5 | 6 | class Bleve(Base): 7 | 8 | def purge_bleve_indexes(self): 9 | """Purge all Bleve indexes 10 | `Read in Mattermost API docs (bleve - PurgeBleveIndexes) `_ 11 | 12 | """ 13 | return self.client.post("""/api/v4/bleve/purge_indexes""") 14 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/logs.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Logs"] 5 | 6 | 7 | class Logs(Base): 8 | 9 | def download_system_logs(self): 10 | """Download system logs 11 | `Read in Mattermost API docs (logs - DownloadSystemLogs) `_ 12 | 13 | """ 14 | return self.client.get("""/api/v4/logs/download""") 15 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/cluster.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Cluster"] 5 | 6 | 7 | class Cluster(Base): 8 | 9 | def get_cluster_status(self): 10 | """Get cluster status 11 | `Read in Mattermost API docs (cluster - GetClusterStatus) `_ 12 | 13 | """ 14 | return self.client.get("""/api/v4/cluster/status""") 15 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/root.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Root"] 4 | 5 | 6 | class Root(Base): 7 | 8 | def acknowledge_notification(self): 9 | """Acknowledge receiving of a notification 10 | `Read in Mattermost API docs (root - AcknowledgeNotification) `_ 11 | 12 | """ 13 | return self.client.post("""/api/v4/notifications/ack""") 14 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/bleve.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Bleve"] 5 | 6 | 7 | class Bleve(Base): 8 | 9 | def purge_bleve_indexes(self): 10 | """Purge all Bleve indexes 11 | `Read in Mattermost API docs (bleve - PurgeBleveIndexes) `_ 12 | 13 | """ 14 | return self.client.post("""/api/v4/bleve/purge_indexes""") 15 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/root.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Root"] 5 | 6 | 7 | class Root(Base): 8 | 9 | def acknowledge_notification(self): 10 | """Acknowledge receiving of a notification 11 | `Read in Mattermost API docs (root - AcknowledgeNotification) `_ 12 | 13 | """ 14 | return self.client.post("""/api/v4/notifications/ack""") 15 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/permissions.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Permissions"] 4 | 5 | 6 | class Permissions(Base): 7 | 8 | def get_ancillary_permissions_post(self, options): 9 | """Return all system console subsection ancillary permissions 10 | `Read in Mattermost API docs (permissions - GetAncillaryPermissionsPost) `_ 11 | 12 | """ 13 | return self.client.post("""/api/v4/permissions/ancillary""", options=options) 14 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/permissions.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Permissions"] 5 | 6 | 7 | class Permissions(Base): 8 | 9 | def get_ancillary_permissions_post(self, options: list[str]): 10 | """Return all system console subsection ancillary permissions 11 | `Read in Mattermost API docs (permissions - GetAncillaryPermissionsPost) `_ 12 | 13 | """ 14 | return self.client.post("""/api/v4/permissions/ancillary""", options=options) 15 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/playbook_autofollows.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["PlaybookAutofollows"] 4 | 5 | 6 | class PlaybookAutofollows(Base): 7 | 8 | def get_auto_follows(self, id): 9 | """Get the list of followers' user IDs of a playbook 10 | 11 | id: ID of the playbook to retrieve followers from. 12 | 13 | `Read in Mattermost API docs (playbook_autofollows - getAutoFollows) `_ 14 | 15 | """ 16 | return self.client.get(f"/plugins/playbooks/api/v0/playbooks/{id}/autofollows") 17 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/group_message.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["GroupMessage"] 4 | 5 | 6 | class GroupMessage(Base): 7 | 8 | def get_group_message_members_common_teams(self, channel_id): 9 | """Get common teams for members of a Group Message. 10 | 11 | channel_id: Channel GUID 12 | 13 | `Read in Mattermost API docs (group_message - GetGroupMessageMembersCommonTeams) `_ 14 | 15 | """ 16 | return self.client.get(f"/api/v4/channels/{channel_id}/common_teams") 17 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/playbook_autofollows.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["PlaybookAutofollows"] 5 | 6 | 7 | class PlaybookAutofollows(Base): 8 | 9 | def get_auto_follows(self, id: str): 10 | """Get the list of followers' user IDs of a playbook 11 | 12 | id: ID of the playbook to retrieve followers from. 13 | 14 | `Read in Mattermost API docs (playbook_autofollows - getAutoFollows) `_ 15 | 16 | """ 17 | return self.client.get(f"/plugins/playbooks/api/v0/playbooks/{id}/autofollows") 18 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/group_message.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["GroupMessage"] 5 | 6 | 7 | class GroupMessage(Base): 8 | 9 | def get_group_message_members_common_teams(self, channel_id: str): 10 | """Get common teams for members of a Group Message. 11 | 12 | channel_id: Channel GUID 13 | 14 | `Read in Mattermost API docs (group_message - GetGroupMessageMembersCommonTeams) `_ 15 | 16 | """ 17 | return self.client.get(f"/api/v4/channels/{channel_id}/common_teams") 18 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/timeline.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Timeline"] 4 | 5 | 6 | class Timeline(Base): 7 | 8 | def remove_timeline_event(self, id, event_id): 9 | """Remove a timeline event from the playbook run 10 | 11 | id: ID of the playbook run whose timeline event will be modified. 12 | event_id: ID of the timeline event to be deleted 13 | 14 | `Read in Mattermost API docs (timeline - removeTimelineEvent) `_ 15 | 16 | """ 17 | return self.client.delete(f"/plugins/playbooks/api/v0/runs/{id}/timeline/{event_id}") 18 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = python -msphinx 7 | SPHINXPROJ = mattermostautodriver 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/timeline.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Timeline"] 5 | 6 | 7 | class Timeline(Base): 8 | 9 | def remove_timeline_event(self, id: str, event_id: str): 10 | """Remove a timeline event from the playbook run 11 | 12 | id: ID of the playbook run whose timeline event will be modified. 13 | event_id: ID of the timeline event to be deleted 14 | 15 | `Read in Mattermost API docs (timeline - removeTimelineEvent) `_ 16 | 17 | """ 18 | return self.client.delete(f"/plugins/playbooks/api/v0/runs/{id}/timeline/{event_id}") 19 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/agents.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Agents"] 4 | 5 | 6 | class Agents(Base): 7 | 8 | def get_agents(self): 9 | """Get available agents 10 | `Read in Mattermost API docs (agents - GetAgents) `_ 11 | 12 | """ 13 | return self.client.get("""/api/v4/agents""") 14 | 15 | def get_llm_services(self): 16 | """Get available LLM services 17 | `Read in Mattermost API docs (agents - GetLLMServices) `_ 18 | 19 | """ 20 | return self.client.get("""/api/v4/llmservices""") 21 | -------------------------------------------------------------------------------- /.github/workflows/test_package_build_pull_request.yml: -------------------------------------------------------------------------------- 1 | name: Test building python package 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | strategy: 10 | max-parallel: 4 11 | matrix: 12 | python-version: ['3.10', '3.11', '3.12', '3.13'] 13 | 14 | steps: 15 | - uses: actions/checkout@v4 16 | - name: Set up Python ${{ matrix.python-version }} 17 | uses: actions/setup-python@v5 18 | with: 19 | python-version: ${{ matrix.python-version }} 20 | - name: Install dependencies 21 | run: | 22 | python -m pip install --upgrade pip 23 | pip install -r requirements.txt 24 | - name: Install dependencies 25 | run: | 26 | pip install . 27 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/agents.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Agents"] 5 | 6 | 7 | class Agents(Base): 8 | 9 | def get_agents(self): 10 | """Get available agents 11 | `Read in Mattermost API docs (agents - GetAgents) `_ 12 | 13 | """ 14 | return self.client.get("""/api/v4/agents""") 15 | 16 | def get_llm_services(self): 17 | """Get available LLM services 18 | `Read in Mattermost API docs (agents - GetLLMServices) `_ 19 | 20 | """ 21 | return self.client.get("""/api/v4/llmservices""") 22 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/usage.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Usage"] 4 | 5 | 6 | class Usage(Base): 7 | 8 | def get_posts_usage(self): 9 | """Get current usage of posts 10 | `Read in Mattermost API docs (usage - GetPostsUsage) `_ 11 | 12 | """ 13 | return self.client.get("""/api/v4/usage/posts""") 14 | 15 | def get_storage_usage(self): 16 | """Get the total file storage usage for the instance in bytes. 17 | `Read in Mattermost API docs (usage - GetStorageUsage) `_ 18 | 19 | """ 20 | return self.client.get("""/api/v4/usage/storage""") 21 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/usage.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Usage"] 5 | 6 | 7 | class Usage(Base): 8 | 9 | def get_posts_usage(self): 10 | """Get current usage of posts 11 | `Read in Mattermost API docs (usage - GetPostsUsage) `_ 12 | 13 | """ 14 | return self.client.get("""/api/v4/usage/posts""") 15 | 16 | def get_storage_usage(self): 17 | """Get the total file storage usage for the instance in bytes. 18 | `Read in Mattermost API docs (usage - GetStorageUsage) `_ 19 | 20 | """ 21 | return self.client.get("""/api/v4/usage/storage""") 22 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/imports.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Imports"] 4 | 5 | 6 | class Imports(Base): 7 | 8 | def list_imports(self): 9 | """List import files 10 | `Read in Mattermost API docs (imports - ListImports) `_ 11 | 12 | """ 13 | return self.client.get("""/api/v4/imports""") 14 | 15 | def delete_import(self, import_name): 16 | """Delete an import file 17 | 18 | import_name: The name of the import file to delete 19 | 20 | `Read in Mattermost API docs (imports - DeleteImport) `_ 21 | 22 | """ 23 | return self.client.delete(f"/api/v4/imports/{import_name}") 24 | -------------------------------------------------------------------------------- /docs/update_endpoints.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | 5 | template = """ 6 | {name_title} 7 | {title_under} 8 | 9 | .. automodule:: mattermostautodriver.endpoints.{endpoint} 10 | :members: 11 | :undoc-members: 12 | :show-inheritance: 13 | """ 14 | 15 | with open("endpoints.rst", "w") as fh: 16 | fh.write("Endpoints\n=========\n") 17 | 18 | for endpoint in sorted(os.listdir("../src/mattermostautodriver/endpoints/")): 19 | if endpoint.startswith("_"): 20 | continue 21 | 22 | name = os.path.splitext(endpoint)[0] 23 | 24 | name_title = name.replace("_", " ").title() 25 | title_under = len(name_title) * "-" 26 | 27 | fh.write(template.format(**{ 28 | "name_title": name_title, 29 | "title_under": title_under, 30 | "endpoint": name, 31 | })) 32 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/imports.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Imports"] 5 | 6 | 7 | class Imports(Base): 8 | 9 | def list_imports(self): 10 | """List import files 11 | `Read in Mattermost API docs (imports - ListImports) `_ 12 | 13 | """ 14 | return self.client.get("""/api/v4/imports""") 15 | 16 | def delete_import(self, import_name: str): 17 | """Delete an import file 18 | 19 | import_name: The name of the import file to delete 20 | 21 | `Read in Mattermost API docs (imports - DeleteImport) `_ 22 | 23 | """ 24 | return self.client.delete(f"/api/v4/imports/{import_name}") 25 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/elasticsearch.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Elasticsearch"] 4 | 5 | 6 | class Elasticsearch(Base): 7 | 8 | def test_elasticsearch(self): 9 | """Test Elasticsearch configuration 10 | `Read in Mattermost API docs (elasticsearch - TestElasticsearch) `_ 11 | 12 | """ 13 | return self.client.post("""/api/v4/elasticsearch/test""") 14 | 15 | def purge_elasticsearch_indexes(self): 16 | """Purge all Elasticsearch indexes 17 | `Read in Mattermost API docs (elasticsearch - PurgeElasticsearchIndexes) `_ 18 | 19 | """ 20 | return self.client.post("""/api/v4/elasticsearch/purge_indexes""") 21 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/elasticsearch.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Elasticsearch"] 5 | 6 | 7 | class Elasticsearch(Base): 8 | 9 | def test_elasticsearch(self): 10 | """Test Elasticsearch configuration 11 | `Read in Mattermost API docs (elasticsearch - TestElasticsearch) `_ 12 | 13 | """ 14 | return self.client.post("""/api/v4/elasticsearch/test""") 15 | 16 | def purge_elasticsearch_indexes(self): 17 | """Purge all Elasticsearch indexes 18 | `Read in Mattermost API docs (elasticsearch - PurgeElasticsearchIndexes) `_ 19 | 20 | """ 21 | return self.client.post("""/api/v4/elasticsearch/purge_indexes""") 22 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=python -msphinx 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | set SPHINXPROJ=mattermostautodriver 13 | 14 | if "%1" == "" goto help 15 | 16 | %SPHINXBUILD% >NUL 2>NUL 17 | if errorlevel 9009 ( 18 | echo. 19 | echo.The Sphinx module was not found. Make sure you have Sphinx installed, 20 | echo.then set the SPHINXBUILD environment variable to point to the full 21 | echo.path of the 'sphinx-build' executable. Alternatively you may add the 22 | echo.Sphinx directory to PATH. 23 | echo. 24 | echo.If you don't have Sphinx installed, grab it from 25 | echo.http://sphinx-doc.org/ 26 | exit /b 1 27 | ) 28 | 29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 30 | goto end 31 | 32 | :help 33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 34 | 35 | :end 36 | popd 37 | -------------------------------------------------------------------------------- /scripts/generate_endpoints.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | GREEN="\e[1;32m" 4 | RESET="\e[0m" 5 | 6 | color() { 7 | echo -e "${GREEN}$1${RESET}" 8 | } 9 | 10 | set -eu 11 | 12 | STORE_DIR="mattermostautodriver" 13 | 14 | for DEST in "endpoints" "endpoints_old"; do 15 | rm -f src/$STORE_DIR/$DEST/*.py 16 | touch src/$STORE_DIR/$DEST/__init__.py 17 | 18 | cat << EOF > src/$STORE_DIR/$DEST/_base.py 19 | class Base: 20 | def __init__(self, client): 21 | self.client = client 22 | EOF 23 | done 24 | 25 | color "Generating deprecated-style endpoints" 26 | python bin/generate_endpoints_ast_deprecated.py 27 | 28 | color "Generating new API endpoints" 29 | python bin/generate_endpoints_ast.py 30 | 31 | color "Updating driver" 32 | python bin/generate_driver_ast.py 33 | 34 | color "Updating documentation for new endpoints" 35 | # Executing in a subshell so we don't have to worry about a failing chdir 36 | ( cd docs && python update_endpoints.py ) 37 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/audit_logs.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["AuditLogs"] 4 | 5 | 6 | class AuditLogs(Base): 7 | 8 | def add_audit_log_certificate(self, files, data=None): 9 | """Upload audit log certificate 10 | 11 | certificate: The certificate file 12 | 13 | `Read in Mattermost API docs (audit_logs - AddAuditLogCertificate) `_ 14 | 15 | """ 16 | return self.client.post("""/api/v4/audit_logs/certificate""", files=files, data=data) 17 | 18 | def remove_audit_log_certificate(self): 19 | """Remove audit log certificate 20 | `Read in Mattermost API docs (audit_logs - RemoveAuditLogCertificate) `_ 21 | 22 | """ 23 | return self.client.delete("""/api/v4/audit_logs/certificate""") 24 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/ip.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Ip"] 4 | 5 | 6 | class Ip(Base): 7 | 8 | def get_ip_filters(self): 9 | """Get all IP filters 10 | `Read in Mattermost API docs (ip - GetIPFilters) `_ 11 | 12 | """ 13 | return self.client.get("""/api/v4/ip_filtering""") 14 | 15 | def apply_ip_filters(self, options): 16 | """Get all IP filters 17 | `Read in Mattermost API docs (ip - ApplyIPFilters) `_ 18 | 19 | """ 20 | return self.client.post("""/api/v4/ip_filtering""", options=options) 21 | 22 | def my_ip(self): 23 | """Get all IP filters 24 | `Read in Mattermost API docs (ip - MyIP) `_ 25 | 26 | """ 27 | return self.client.get("""/api/v4/ip_filtering/my_ip""") 28 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/audit_logs.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["AuditLogs"] 5 | 6 | 7 | class AuditLogs(Base): 8 | 9 | def add_audit_log_certificate(self, certificate: BinaryIO): 10 | """Upload audit log certificate 11 | 12 | certificate: The certificate file 13 | 14 | `Read in Mattermost API docs (audit_logs - AddAuditLogCertificate) `_ 15 | 16 | """ 17 | __files = {"certificate": certificate} 18 | return self.client.post("""/api/v4/audit_logs/certificate""", files=__files) 19 | 20 | def remove_audit_log_certificate(self): 21 | """Remove audit log certificate 22 | `Read in Mattermost API docs (audit_logs - RemoveAuditLogCertificate) `_ 23 | 24 | """ 25 | return self.client.delete("""/api/v4/audit_logs/certificate""") 26 | -------------------------------------------------------------------------------- /.github/workflows/pypi_release.yml: -------------------------------------------------------------------------------- 1 | name: Publish Python Package to PyPI 2 | 3 | on: 4 | workflow_dispatch: 5 | release: 6 | types: [ created ] 7 | push: 8 | tags: 9 | - '[0-9]+.[0-9]+.[0-9]+' 10 | 11 | jobs: 12 | build-n-publish: 13 | name: Build and publish Python 🐍 distributions 📦 to PyPI 14 | runs-on: ubuntu-latest 15 | environment: pypi-deployment 16 | steps: 17 | - uses: actions/checkout@v4 18 | - name: "Set up Python 3.12" 19 | uses: actions/setup-python@v5 20 | with: 21 | python-version: "3.12" 22 | - name: Install dependencies 23 | run: | 24 | python -m pip install --upgrade pip 25 | pip install setuptools wheel twine 26 | - name: Build a binary wheel and a source tarball 27 | run: | 28 | python setup.py sdist bdist_wheel 29 | - name: Publish to pypi 30 | env: 31 | TWINE_USERNAME: __token__ 32 | TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} 33 | run: 34 | twine upload dist/* 35 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/metrics.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Metrics"] 4 | 5 | 6 | class Metrics(Base): 7 | 8 | def submit_performance_report(self, options=None): 9 | """Report client performance metrics 10 | 11 | version: An identifier for the schema of the data being submitted which currently must be "0.1.0" 12 | client_id: Not currently used 13 | labels: Labels to be applied to all metrics when recorded by the metrics backend 14 | start: The time in milliseconds of the first metric in this report 15 | end: The time in milliseconds of the last metric in this report 16 | counters: An array of counter metrics to be reported 17 | histograms: An array of histogram measurements to be reported 18 | 19 | `Read in Mattermost API docs (metrics - SubmitPerformanceReport) `_ 20 | 21 | """ 22 | return self.client.post("""/api/v4/client_perf""", options=options) 23 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/filtering.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Filtering"] 4 | 5 | 6 | class Filtering(Base): 7 | 8 | def get_ip_filters(self): 9 | """Get all IP filters 10 | `Read in Mattermost API docs (filtering - GetIPFilters) `_ 11 | 12 | """ 13 | return self.client.get("""/api/v4/ip_filtering""") 14 | 15 | def apply_ip_filters(self, options): 16 | """Get all IP filters 17 | `Read in Mattermost API docs (filtering - ApplyIPFilters) `_ 18 | 19 | """ 20 | return self.client.post("""/api/v4/ip_filtering""", options=options) 21 | 22 | def my_ip(self): 23 | """Get all IP filters 24 | `Read in Mattermost API docs (filtering - MyIP) `_ 25 | 26 | """ 27 | return self.client.get("""/api/v4/ip_filtering/my_ip""") 28 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/ip.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Ip"] 5 | 6 | 7 | class Ip(Base): 8 | 9 | def get_ip_filters(self): 10 | """Get all IP filters 11 | `Read in Mattermost API docs (ip - GetIPFilters) `_ 12 | 13 | """ 14 | return self.client.get("""/api/v4/ip_filtering""") 15 | 16 | def apply_ip_filters(self, options: list[Any]): 17 | """Get all IP filters 18 | `Read in Mattermost API docs (ip - ApplyIPFilters) `_ 19 | 20 | """ 21 | return self.client.post("""/api/v4/ip_filtering""", options=options) 22 | 23 | def my_ip(self): 24 | """Get all IP filters 25 | `Read in Mattermost API docs (ip - MyIP) `_ 26 | 27 | """ 28 | return self.client.get("""/api/v4/ip_filtering/my_ip""") 29 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/filtering.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Filtering"] 5 | 6 | 7 | class Filtering(Base): 8 | 9 | def get_ip_filters(self): 10 | """Get all IP filters 11 | `Read in Mattermost API docs (filtering - GetIPFilters) `_ 12 | 13 | """ 14 | return self.client.get("""/api/v4/ip_filtering""") 15 | 16 | def apply_ip_filters(self, options: list[Any]): 17 | """Get all IP filters 18 | `Read in Mattermost API docs (filtering - ApplyIPFilters) `_ 19 | 20 | """ 21 | return self.client.post("""/api/v4/ip_filtering""", options=options) 22 | 23 | def my_ip(self): 24 | """Get all IP filters 25 | `Read in Mattermost API docs (filtering - MyIP) `_ 26 | 27 | """ 28 | return self.client.get("""/api/v4/ip_filtering/my_ip""") 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Christian Plümer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /scripts/check_release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | MM="mattermost" 4 | PYPI_PACKAGE="mattermostautodriver" 5 | 6 | if ! TAGS_JSON="$(curl -s -f https://api.github.com/repos/${MM}/${MM}/tags)"; then 7 | echo "GitHub API call failed" 8 | exit 1 9 | fi 10 | 11 | # Extract and sort version tags 12 | LATEST_TAG="$(echo "$TAGS_JSON" | jq -r '.[].name' | grep -Eo '^v[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -n 1)" 13 | 14 | if [ -z "$LATEST_TAG" ]; then 15 | echo "No version tags found" 16 | exit 1 17 | fi 18 | 19 | echo "Latest Mattermost Server GitHub tag: $LATEST_TAG" 20 | 21 | # Check if the version exists on PyPI - strip 'v' as Mattermost has it in the tag but we don't on PyPI 22 | VERSION="${LATEST_TAG#v}" 23 | 24 | if ! PYPI_VERSIONS=$(curl -s -f https://pypi.org/pypi/$PYPI_PACKAGE/json); then 25 | echo "Failed to retrieve versions from PyPI" 26 | exit 1 27 | fi 28 | 29 | if echo "$PYPI_VERSIONS" | jq -e --arg ver "$VERSION" '.releases[$ver]' > /dev/null; then 30 | echo "MattermostAutoDriver version $VERSION exists on PyPI" 31 | exit 1 32 | else 33 | echo "MattermostAutoDriver version $VERSION not found on PyPI" 34 | exit 0 35 | fi 36 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/brand.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Brand"] 4 | 5 | 6 | class Brand(Base): 7 | 8 | def get_brand_image(self): 9 | """Get brand image 10 | `Read in Mattermost API docs (brand - GetBrandImage) `_ 11 | 12 | """ 13 | return self.client.get("""/api/v4/brand/image""") 14 | 15 | def upload_brand_image(self, files, data=None): 16 | """Upload brand image 17 | 18 | image: The image to be uploaded 19 | 20 | `Read in Mattermost API docs (brand - UploadBrandImage) `_ 21 | 22 | """ 23 | return self.client.post("""/api/v4/brand/image""", files=files, data=data) 24 | 25 | def delete_brand_image(self): 26 | """Delete current brand image 27 | `Read in Mattermost API docs (brand - DeleteBrandImage) `_ 28 | 29 | """ 30 | return self.client.delete("""/api/v4/brand/image""") 31 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/migrate.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Migrate"] 4 | 5 | 6 | class Migrate(Base): 7 | 8 | def migrate_auth_to_ldap(self, options=None): 9 | """Migrate user accounts authentication type to LDAP. 10 | 11 | from: The current authentication type for the matched users. 12 | match_field: Foreign user field name to match. 13 | force: 14 | 15 | `Read in Mattermost API docs (migrate - MigrateAuthToLdap) `_ 16 | 17 | """ 18 | return self.client.post("""/api/v4/users/migrate_auth/ldap""", options=options) 19 | 20 | def migrate_auth_to_saml(self, options=None): 21 | """Migrate user accounts authentication type to SAML. 22 | 23 | from: The current authentication type for the matched users. 24 | matches: Users map. 25 | auto: 26 | 27 | `Read in Mattermost API docs (migrate - MigrateAuthToSaml) `_ 28 | 29 | """ 30 | return self.client.post("""/api/v4/users/migrate_auth/saml""", options=options) 31 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/brand.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Brand"] 5 | 6 | 7 | class Brand(Base): 8 | 9 | def get_brand_image(self): 10 | """Get brand image 11 | `Read in Mattermost API docs (brand - GetBrandImage) `_ 12 | 13 | """ 14 | return self.client.get("""/api/v4/brand/image""") 15 | 16 | def upload_brand_image(self, image: BinaryIO): 17 | """Upload brand image 18 | 19 | image: The image to be uploaded 20 | 21 | `Read in Mattermost API docs (brand - UploadBrandImage) `_ 22 | 23 | """ 24 | __files = {"image": image} 25 | return self.client.post("""/api/v4/brand/image""", files=__files) 26 | 27 | def delete_brand_image(self): 28 | """Delete current brand image 29 | `Read in Mattermost API docs (brand - DeleteBrandImage) `_ 30 | 31 | """ 32 | return self.client.delete("""/api/v4/brand/image""") 33 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/exports.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Exports"] 4 | 5 | 6 | class Exports(Base): 7 | 8 | def list_exports(self): 9 | """List export files 10 | `Read in Mattermost API docs (exports - ListExports) `_ 11 | 12 | """ 13 | return self.client.get("""/api/v4/exports""") 14 | 15 | def download_export(self, export_name): 16 | """Download an export file 17 | 18 | export_name: The name of the export file to download 19 | 20 | `Read in Mattermost API docs (exports - DownloadExport) `_ 21 | 22 | """ 23 | return self.client.get(f"/api/v4/exports/{export_name}") 24 | 25 | def delete_export(self, export_name): 26 | """Delete an export file 27 | 28 | export_name: The name of the export file to delete 29 | 30 | `Read in Mattermost API docs (exports - DeleteExport) `_ 31 | 32 | """ 33 | return self.client.delete(f"/api/v4/exports/{export_name}") 34 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/authentication.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Authentication"] 4 | 5 | 6 | class Authentication(Base): 7 | 8 | def migrate_auth_to_ldap(self, options=None): 9 | """Migrate user accounts authentication type to LDAP. 10 | 11 | from: The current authentication type for the matched users. 12 | match_field: Foreign user field name to match. 13 | force: 14 | 15 | `Read in Mattermost API docs (authentication - MigrateAuthToLdap) `_ 16 | 17 | """ 18 | return self.client.post("""/api/v4/users/migrate_auth/ldap""", options=options) 19 | 20 | def migrate_auth_to_saml(self, options=None): 21 | """Migrate user accounts authentication type to SAML. 22 | 23 | from: The current authentication type for the matched users. 24 | matches: Users map. 25 | auto: 26 | 27 | `Read in Mattermost API docs (authentication - MigrateAuthToSaml) `_ 28 | 29 | """ 30 | return self.client.post("""/api/v4/users/migrate_auth/saml""", options=options) 31 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/exports.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Exports"] 5 | 6 | 7 | class Exports(Base): 8 | 9 | def list_exports(self): 10 | """List export files 11 | `Read in Mattermost API docs (exports - ListExports) `_ 12 | 13 | """ 14 | return self.client.get("""/api/v4/exports""") 15 | 16 | def download_export(self, export_name: str): 17 | """Download an export file 18 | 19 | export_name: The name of the export file to download 20 | 21 | `Read in Mattermost API docs (exports - DownloadExport) `_ 22 | 23 | """ 24 | return self.client.get(f"/api/v4/exports/{export_name}") 25 | 26 | def delete_export(self, export_name: str): 27 | """Delete an export file 28 | 29 | export_name: The name of the export file to delete 30 | 31 | `Read in Mattermost API docs (exports - DeleteExport) `_ 32 | 33 | """ 34 | return self.client.delete(f"/api/v4/exports/{export_name}") 35 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | CONTRIBUTING 2 | '''''''''''' 3 | 4 | Yes, please! Feel free to contribute to the project. 5 | 6 | I would be glad if you do! 7 | There are only a few things to keep in mind. 8 | 9 | This project follows PEP 8, and uses black to format/check the files 10 | 11 | If there are more exceptions from it, which I don't know about it, please try to be consistent! 12 | And please try to avoid to mix big style changes with feature changes! 13 | 14 | Thanks! :-) 15 | 16 | 17 | How to update the documentation 18 | ------------------------------- 19 | 20 | The documentation lies on the branch `gh-pages`. 21 | 22 | In order to build these, change into the folder `docs/` and run `make html`. 23 | The files will be output into `docs/_build/`. 24 | The relevant files are under `docs/_build/html/`. 25 | These are the ones that are on the `gh-pages` branch. 26 | 27 | The easiest way to update the documentation would be to: 28 | - `git clone https://github.com/embl-bio-it/python-mattermost-autodriver.git python-mattermost-autodriver-docs` 29 | - `cd python-mattermost-autodriver-docs` 30 | - `git checkout gh-pages` 31 | - `cp -r python-mattermostautodriver/docs/_build/html/. python-mattermost-autodriver-docs/` 32 | - Check the changed files with `git status` 33 | - Add them and commit/push 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/migrate.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Migrate"] 5 | 6 | 7 | class Migrate(Base): 8 | 9 | def migrate_auth_to_ldap(self, from_: str, match_field: str, force: bool): 10 | """Migrate user accounts authentication type to LDAP. 11 | 12 | from: The current authentication type for the matched users. 13 | match_field: Foreign user field name to match. 14 | force: 15 | 16 | `Read in Mattermost API docs (migrate - MigrateAuthToLdap) `_ 17 | 18 | """ 19 | __options = {"from": from_, "match_field": match_field, "force": force} 20 | return self.client.post("""/api/v4/users/migrate_auth/ldap""", options=__options) 21 | 22 | def migrate_auth_to_saml(self, from_: str, matches: dict[str, Any], auto: bool): 23 | """Migrate user accounts authentication type to SAML. 24 | 25 | from: The current authentication type for the matched users. 26 | matches: Users map. 27 | auto: 28 | 29 | `Read in Mattermost API docs (migrate - MigrateAuthToSaml) `_ 30 | 31 | """ 32 | __options = {"from": from_, "matches": matches, "auto": auto} 33 | return self.client.post("""/api/v4/users/migrate_auth/saml""", options=__options) 34 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/uploads.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Uploads"] 4 | 5 | 6 | class Uploads(Base): 7 | 8 | def create_upload(self, options): 9 | """Create an upload 10 | 11 | channel_id: The ID of the channel to upload to. 12 | filename: The name of the file to upload. 13 | file_size: The size of the file to upload in bytes. 14 | 15 | `Read in Mattermost API docs (uploads - CreateUpload) `_ 16 | 17 | """ 18 | return self.client.post("""/api/v4/uploads""", options=options) 19 | 20 | def get_upload(self, upload_id): 21 | """Get an upload session 22 | 23 | upload_id: The ID of the upload session to get. 24 | 25 | `Read in Mattermost API docs (uploads - GetUpload) `_ 26 | 27 | """ 28 | return self.client.get(f"/api/v4/uploads/{upload_id}") 29 | 30 | def upload_data(self, upload_id, files, options=None): 31 | """Perform a file upload 32 | 33 | upload_id: The ID of the upload session the data belongs to. 34 | 35 | `Read in Mattermost API docs (uploads - UploadData) `_ 36 | 37 | """ 38 | return self.client.post(f"/api/v4/uploads/{upload_id}", files=files, options=options) 39 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/authentication.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Authentication"] 5 | 6 | 7 | class Authentication(Base): 8 | 9 | def migrate_auth_to_ldap(self, from_: str, match_field: str, force: bool): 10 | """Migrate user accounts authentication type to LDAP. 11 | 12 | from: The current authentication type for the matched users. 13 | match_field: Foreign user field name to match. 14 | force: 15 | 16 | `Read in Mattermost API docs (authentication - MigrateAuthToLdap) `_ 17 | 18 | """ 19 | __options = {"from": from_, "match_field": match_field, "force": force} 20 | return self.client.post("""/api/v4/users/migrate_auth/ldap""", options=__options) 21 | 22 | def migrate_auth_to_saml(self, from_: str, matches: dict[str, Any], auto: bool): 23 | """Migrate user accounts authentication type to SAML. 24 | 25 | from: The current authentication type for the matched users. 26 | matches: Users map. 27 | auto: 28 | 29 | `Read in Mattermost API docs (authentication - MigrateAuthToSaml) `_ 30 | 31 | """ 32 | __options = {"from": from_, "matches": matches, "auto": auto} 33 | return self.client.post("""/api/v4/users/migrate_auth/saml""", options=__options) 34 | -------------------------------------------------------------------------------- /docs/sample_async_connection.py: -------------------------------------------------------------------------------- 1 | from mattermostautodriver import AsyncTypedDriver 2 | import asyncio 3 | 4 | 5 | async def my_event_handler(message): 6 | print(repr(message)) 7 | 8 | 9 | class Handler: 10 | def __init__(self): 11 | self.driver = AsyncTypedDriver({ 12 | "url": "127.0.0.1", 13 | "token": "e691u15hajdebcnqpfdceqihcc", 14 | "scheme": 'http', 15 | "port": 8065, 16 | "verify": False, 17 | # "debug": True, 18 | }) 19 | 20 | async def amain(self): 21 | print(">>> Login:", await self.driver.login()) 22 | 23 | task = asyncio.create_task(self.driver.init_websocket(my_event_handler)) 24 | 25 | print(">>> Get Admin:", await self.driver.users.get_user_by_username('admin')) 26 | 27 | print(">>> Get my own details:", await self.driver.users.get_user(user_id='me')) 28 | 29 | print(">>> Get all teams:", await self.driver.teams.get_all_teams()) 30 | 31 | print("Websocket connected, closing main thread in 5 seconds") 32 | await asyncio.sleep(5) 33 | print("Disconnecting") 34 | 35 | self.driver.disconnect() 36 | 37 | # Will disconnect as soon as a message is sent by the Mattermost server 38 | # which can be a rather long time on a mostly inactive server 39 | # await task 40 | # alternatively use: 41 | task.cancel() 42 | 43 | 44 | handler = Handler() 45 | 46 | asyncio.run(handler.amain()) 47 | 48 | print("Disconnected") 49 | -------------------------------------------------------------------------------- /.github/workflows/build_docs.yml: -------------------------------------------------------------------------------- 1 | name: Build and deploy sphinx docs 2 | on: 3 | push: 4 | branches: ["main"] 5 | 6 | # Allows you to run this workflow manually from the Actions tab 7 | workflow_dispatch: 8 | 9 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 10 | permissions: 11 | contents: read 12 | pages: write 13 | id-token: write 14 | 15 | # Allow one concurrent deployment 16 | concurrency: 17 | group: "pages" 18 | cancel-in-progress: true 19 | 20 | jobs: 21 | # Single deploy job since we're just deploying 22 | deploy: 23 | environment: 24 | name: github-pages 25 | url: ${{ steps.deployment.outputs.page_url }} 26 | runs-on: ubuntu-latest 27 | steps: 28 | - name: Checkout 29 | uses: actions/checkout@v4 30 | - name: Install Python 3 31 | run: | 32 | sudo apt-get update 33 | sudo apt-get install -y python3 python3-pip make 34 | - name: Build docs 35 | run: | 36 | python3 -m venv .venv 37 | source .venv/bin/activate 38 | pip install --upgrade pip 39 | pip install -r requirements.txt 40 | cd docs 41 | make html 42 | - name: Setup Pages 43 | uses: actions/configure-pages@v5 44 | - name: Upload artifact 45 | uses: actions/upload-pages-artifact@v3 46 | with: 47 | # Upload entire repository 48 | path: 'docs/_build/html/' 49 | - name: Deploy to GitHub Pages 50 | id: deployment 51 | uses: actions/deploy-pages@v4 52 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os.path 5 | 6 | from setuptools import setup, find_packages 7 | 8 | full_version = '' 9 | 10 | root_dir = os.path.abspath(os.path.dirname(__file__)) 11 | 12 | readme_file = os.path.join(root_dir, 'README.rst') 13 | with open(readme_file, encoding='utf-8') as f: 14 | long_description = f.read() 15 | 16 | version_module = os.path.join(root_dir, 'src', 'mattermostautodriver', 'version.py') 17 | with open(version_module, encoding='utf-8') as f: 18 | exec(f.read()) 19 | 20 | setup( 21 | name='mattermostautodriver', 22 | version=full_version, 23 | description='A Python Mattermost Auto Driver', 24 | long_description=long_description, 25 | url='https://github.com/embl-bio-it/python-mattermost-autodriver', 26 | author='Renato Alves, Christian Plümer', 27 | author_email='bio-it@embl.de, github@kuuku.net', 28 | license='MIT', 29 | classifiers=[ 30 | 'Development Status :: 5 - Production/Stable', 31 | 'Environment :: Web Environment', 32 | 'Intended Audience :: Developers', 33 | 'Programming Language :: Python', 34 | 'Programming Language :: Python :: 3', 35 | 'Programming Language :: Python :: 3.10', 36 | 'Programming Language :: Python :: 3.11', 37 | 'Programming Language :: Python :: 3.12', 38 | 'Programming Language :: Python :: 3.13', 39 | ], 40 | package_dir={'': 'src'}, 41 | packages=find_packages('src'), 42 | python_requires=">=3.10", 43 | install_requires=[ 44 | 'aiohttp>=3.9.5,<4.0.0', 45 | 'httpx~=0.28.1', 46 | ], 47 | ) 48 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/uploads.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Uploads"] 5 | 6 | 7 | class Uploads(Base): 8 | 9 | def create_upload(self, channel_id: str, filename: str, file_size: int): 10 | """Create an upload 11 | 12 | channel_id: The ID of the channel to upload to. 13 | filename: The name of the file to upload. 14 | file_size: The size of the file to upload in bytes. 15 | 16 | `Read in Mattermost API docs (uploads - CreateUpload) `_ 17 | 18 | """ 19 | __options = {"channel_id": channel_id, "filename": filename, "file_size": file_size} 20 | return self.client.post("""/api/v4/uploads""", options=__options) 21 | 22 | def get_upload(self, upload_id: str): 23 | """Get an upload session 24 | 25 | upload_id: The ID of the upload session to get. 26 | 27 | `Read in Mattermost API docs (uploads - GetUpload) `_ 28 | 29 | """ 30 | return self.client.get(f"/api/v4/uploads/{upload_id}") 31 | 32 | def upload_data(self, upload_id: str, data: dict[str, Any] | None = None): 33 | """Perform a file upload 34 | 35 | upload_id: The ID of the upload session the data belongs to. 36 | 37 | `Read in Mattermost API docs (uploads - UploadData) `_ 38 | 39 | """ 40 | return self.client.post(f"/api/v4/uploads/{upload_id}", data=data) 41 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/metrics.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Metrics"] 5 | 6 | 7 | class Metrics(Base): 8 | 9 | def submit_performance_report( 10 | self, 11 | version: str, 12 | start: int, 13 | end: int, 14 | client_id: str | None = None, 15 | labels: list[str] | None = None, 16 | counters: list[dict[str, Any]] | None = None, 17 | histograms: list[dict[str, Any]] | None = None, 18 | ): 19 | """Report client performance metrics 20 | 21 | version: An identifier for the schema of the data being submitted which currently must be "0.1.0" 22 | client_id: Not currently used 23 | labels: Labels to be applied to all metrics when recorded by the metrics backend 24 | start: The time in milliseconds of the first metric in this report 25 | end: The time in milliseconds of the last metric in this report 26 | counters: An array of counter metrics to be reported 27 | histograms: An array of histogram measurements to be reported 28 | 29 | `Read in Mattermost API docs (metrics - SubmitPerformanceReport) `_ 30 | 31 | """ 32 | __options = { 33 | "version": version, 34 | "client_id": client_id, 35 | "labels": labels, 36 | "start": start, 37 | "end": end, 38 | "counters": counters, 39 | "histograms": histograms, 40 | } 41 | return self.client.post("""/api/v4/client_perf""", options=__options) 42 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/reactions.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Reactions"] 4 | 5 | 6 | class Reactions(Base): 7 | 8 | def save_reaction(self, options): 9 | """Create a reaction 10 | `Read in Mattermost API docs (reactions - SaveReaction) `_ 11 | 12 | """ 13 | return self.client.post("""/api/v4/reactions""", options=options) 14 | 15 | def get_reactions(self, post_id): 16 | """Get a list of reactions to a post 17 | 18 | post_id: ID of a post 19 | 20 | `Read in Mattermost API docs (reactions - GetReactions) `_ 21 | 22 | """ 23 | return self.client.get(f"/api/v4/posts/{post_id}/reactions") 24 | 25 | def delete_reaction(self, user_id, post_id, emoji_name): 26 | """Remove a reaction from a post 27 | 28 | user_id: ID of the user 29 | post_id: ID of the post 30 | emoji_name: emoji name 31 | 32 | `Read in Mattermost API docs (reactions - DeleteReaction) `_ 33 | 34 | """ 35 | return self.client.delete(f"/api/v4/users/{user_id}/posts/{post_id}/reactions/{emoji_name}") 36 | 37 | def get_bulk_reactions(self, options): 38 | """Bulk get the reaction for posts 39 | `Read in Mattermost API docs (reactions - GetBulkReactions) `_ 40 | 41 | """ 42 | return self.client.post("""/api/v4/posts/ids/reactions""", options=options) 43 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/compliance.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Compliance"] 4 | 5 | 6 | class Compliance(Base): 7 | 8 | def create_compliance_report(self): 9 | """Create report 10 | `Read in Mattermost API docs (compliance - CreateComplianceReport) `_ 11 | 12 | """ 13 | return self.client.post("""/api/v4/compliance/reports""") 14 | 15 | def get_compliance_reports(self, params=None): 16 | """Get reports 17 | 18 | page: The page to select. 19 | per_page: The number of reports per page. 20 | 21 | `Read in Mattermost API docs (compliance - GetComplianceReports) `_ 22 | 23 | """ 24 | return self.client.get("""/api/v4/compliance/reports""", params=params) 25 | 26 | def get_compliance_report(self, report_id): 27 | """Get a report 28 | 29 | report_id: Compliance report GUID 30 | 31 | `Read in Mattermost API docs (compliance - GetComplianceReport) `_ 32 | 33 | """ 34 | return self.client.get(f"/api/v4/compliance/reports/{report_id}") 35 | 36 | def download_compliance_report(self, report_id): 37 | """Download a report 38 | 39 | report_id: Compliance report GUID 40 | 41 | `Read in Mattermost API docs (compliance - DownloadComplianceReport) `_ 42 | 43 | """ 44 | return self.client.get(f"/api/v4/compliance/reports/{report_id}/download") 45 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/reactions.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Reactions"] 5 | 6 | 7 | class Reactions(Base): 8 | 9 | def save_reaction(self, options: Any): 10 | """Create a reaction 11 | `Read in Mattermost API docs (reactions - SaveReaction) `_ 12 | 13 | """ 14 | return self.client.post("""/api/v4/reactions""", options=options) 15 | 16 | def get_reactions(self, post_id: str): 17 | """Get a list of reactions to a post 18 | 19 | post_id: ID of a post 20 | 21 | `Read in Mattermost API docs (reactions - GetReactions) `_ 22 | 23 | """ 24 | return self.client.get(f"/api/v4/posts/{post_id}/reactions") 25 | 26 | def delete_reaction(self, user_id: str, post_id: str, emoji_name: str): 27 | """Remove a reaction from a post 28 | 29 | user_id: ID of the user 30 | post_id: ID of the post 31 | emoji_name: emoji name 32 | 33 | `Read in Mattermost API docs (reactions - DeleteReaction) `_ 34 | 35 | """ 36 | return self.client.delete(f"/api/v4/users/{user_id}/posts/{post_id}/reactions/{emoji_name}") 37 | 38 | def get_bulk_reactions(self, options: list[str]): 39 | """Bulk get the reaction for posts 40 | `Read in Mattermost API docs (reactions - GetBulkReactions) `_ 41 | 42 | """ 43 | return self.client.post("""/api/v4/posts/ids/reactions""", options=options) 44 | -------------------------------------------------------------------------------- /docs/sample_sync_connection.py: -------------------------------------------------------------------------------- 1 | from mattermostautodriver import TypedDriver 2 | from multiprocessing import Process 3 | import time 4 | 5 | 6 | async def my_event_handler(message): 7 | print(repr(message)) 8 | 9 | 10 | class Handler: 11 | def __init__(self): 12 | self.driver = TypedDriver({ 13 | "url": "127.0.0.1", 14 | "token": "e691u15hajdebcnqpfdceqihcc", 15 | "scheme": 'http', 16 | "port": 8065, 17 | "verify": False, 18 | # "debug": True, 19 | }) 20 | 21 | def login(self): 22 | print(">>> Login:", self.driver.login()) 23 | 24 | def main(self): 25 | self.driver.init_websocket(my_event_handler) 26 | 27 | def requests(self): 28 | print(">>> Get Admin:", self.driver.users.get_user_by_username('admin')) 29 | 30 | print(">>> Get my own details:", self.driver.users.get_user(user_id='me')) 31 | 32 | print(">>> Get all teams:", self.driver.teams.get_all_teams()) 33 | 34 | 35 | def main(handler): 36 | handler.main() 37 | 38 | 39 | 40 | handler = Handler() 41 | 42 | handler.login() 43 | 44 | p = Process(target=main, args=(handler,)) 45 | p.start() 46 | 47 | handler.requests() 48 | 49 | print("Websocket connected, closing main thread in 5 seconds") 50 | time.sleep(5) 51 | print("Disconnecting") 52 | 53 | # Use `disconnect()` to disconnect the websocket 54 | handler.driver.disconnect() 55 | 56 | # Shutdown the handler process as gracefully as possible 57 | # After disconnect the socket will eventually close bit needs to receive 58 | # an event from the Mattermost server as the driver blocks listening for events 59 | 60 | for signal in (p.terminate, p.kill): 61 | p.join(timeout=5) 62 | 63 | if p.is_alive(): 64 | signal() 65 | else: 66 | break 67 | 68 | p.close() 69 | 70 | print("Disconnected") 71 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/roles.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Roles"] 4 | 5 | 6 | class Roles(Base): 7 | 8 | def get_all_roles(self): 9 | """Get a list of all the roles 10 | `Read in Mattermost API docs (roles - GetAllRoles) `_ 11 | 12 | """ 13 | return self.client.get("""/api/v4/roles""") 14 | 15 | def get_role(self, role_id): 16 | """Get a role 17 | 18 | role_id: Role GUID 19 | 20 | `Read in Mattermost API docs (roles - GetRole) `_ 21 | 22 | """ 23 | return self.client.get(f"/api/v4/roles/{role_id}") 24 | 25 | def get_role_by_name(self, role_name): 26 | """Get a role 27 | 28 | role_name: Role Name 29 | 30 | `Read in Mattermost API docs (roles - GetRoleByName) `_ 31 | 32 | """ 33 | return self.client.get(f"/api/v4/roles/name/{role_name}") 34 | 35 | def patch_role(self, role_id, options): 36 | """Patch a role 37 | 38 | role_id: Role GUID 39 | permissions: The permissions the role should grant. 40 | 41 | `Read in Mattermost API docs (roles - PatchRole) `_ 42 | 43 | """ 44 | return self.client.put(f"/api/v4/roles/{role_id}/patch", options=options) 45 | 46 | def get_roles_by_names(self, options): 47 | """Get a list of roles by name 48 | `Read in Mattermost API docs (roles - GetRolesByNames) `_ 49 | 50 | """ 51 | return self.client.post("""/api/v4/roles/names""", options=options) 52 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/compliance.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Compliance"] 5 | 6 | 7 | class Compliance(Base): 8 | 9 | def create_compliance_report(self): 10 | """Create report 11 | `Read in Mattermost API docs (compliance - CreateComplianceReport) `_ 12 | 13 | """ 14 | return self.client.post("""/api/v4/compliance/reports""") 15 | 16 | def get_compliance_reports(self, page: int | None = 0, per_page: int | None = 60): 17 | """Get reports 18 | 19 | page: The page to select. 20 | per_page: The number of reports per page. 21 | 22 | `Read in Mattermost API docs (compliance - GetComplianceReports) `_ 23 | 24 | """ 25 | __params = {"page": page, "per_page": per_page} 26 | return self.client.get("""/api/v4/compliance/reports""", params=__params) 27 | 28 | def get_compliance_report(self, report_id: str): 29 | """Get a report 30 | 31 | report_id: Compliance report GUID 32 | 33 | `Read in Mattermost API docs (compliance - GetComplianceReport) `_ 34 | 35 | """ 36 | return self.client.get(f"/api/v4/compliance/reports/{report_id}") 37 | 38 | def download_compliance_report(self, report_id: str): 39 | """Download a report 40 | 41 | report_id: Compliance report GUID 42 | 43 | `Read in Mattermost API docs (compliance - DownloadComplianceReport) `_ 44 | 45 | """ 46 | return self.client.get(f"/api/v4/compliance/reports/{report_id}/download") 47 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/terms_of_service.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["TermsOfService"] 4 | 5 | 6 | class TermsOfService(Base): 7 | 8 | def register_terms_of_service_action(self, user_id, options): 9 | """Records user action when they accept or decline custom terms of service 10 | 11 | user_id: User GUID 12 | serviceTermsId: terms of service ID on which the user is acting on 13 | accepted: true or false, indicates whether the user accepted or rejected the terms of service. 14 | 15 | `Read in Mattermost API docs (terms_of_service - RegisterTermsOfServiceAction) `_ 16 | 17 | """ 18 | return self.client.post(f"/api/v4/users/{user_id}/terms_of_service", options=options) 19 | 20 | def get_user_terms_of_service(self, user_id): 21 | """Fetches user's latest terms of service action if the latest action was for acceptance. 22 | 23 | user_id: User GUID 24 | 25 | `Read in Mattermost API docs (terms_of_service - GetUserTermsOfService) `_ 26 | 27 | """ 28 | return self.client.get(f"/api/v4/users/{user_id}/terms_of_service") 29 | 30 | def get_terms_of_service(self): 31 | """Get latest terms of service 32 | `Read in Mattermost API docs (terms_of_service - GetTermsOfService) `_ 33 | 34 | """ 35 | return self.client.get("""/api/v4/terms_of_service""") 36 | 37 | def create_terms_of_service(self): 38 | """Creates a new terms of service 39 | `Read in Mattermost API docs (terms_of_service - CreateTermsOfService) `_ 40 | 41 | """ 42 | return self.client.post("""/api/v4/terms_of_service""") 43 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. mattermostautodriver documentation master file, created by 2 | sphinx-quickstart on Thu Jun 29 10:38:30 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | mattermostautodriver documentation 7 | ================================== 8 | 9 | .. toctree:: 10 | :hidden: 11 | :maxdepth: 1 12 | :caption: Contents: 13 | 14 | endpoints 15 | api_deprecation 16 | changelog 17 | contributing 18 | 19 | 20 | See https://github.com/embl-bio-it/python-mattermost-autodriver for the github repository. 21 | 22 | You interact with this module mainly by using the ``TypedDriver`` class. 23 | If you want to access information about the logged in user, like the user id, 24 | you can access them by using ``TypedDriver.client.userid``. 25 | 26 | Installation 27 | '''''''''''' 28 | .. include:: ../README.rst 29 | :start-after: inclusion-marker-start-install 30 | :end-before: inclusion-marker-end-install 31 | 32 | Usage 33 | ''''' 34 | .. include:: ../README.rst 35 | :start-after: inclusion-marker-start-usage 36 | :end-before: inclusion-marker-end-usage 37 | 38 | .. include:: auth.rst 39 | 40 | Classes 41 | ''''''' 42 | 43 | .. automodule:: mattermostautodriver 44 | .. autoclass:: TypedDriver 45 | :members: 46 | :undoc-members: 47 | 48 | .. autoclass:: Client 49 | :members: 50 | 51 | Exceptions that api requests can throw 52 | '''''''''''''''''''''''''''''''''''''' 53 | 54 | .. automodule:: mattermostautodriver.exceptions 55 | 56 | .. autoclass:: InvalidMattermostError 57 | 58 | .. autoclass:: UnknownMattermostError 59 | 60 | .. autoclass:: InvalidOrMissingParameters 61 | 62 | .. autoclass:: NoAccessTokenProvided 63 | 64 | .. autoclass:: NotEnoughPermissions 65 | 66 | .. autoclass:: ResourceNotFound 67 | 68 | .. autoclass:: ContentTooLarge 69 | 70 | .. autoclass:: FeatureDisabled 71 | 72 | 73 | Indices and tables 74 | ================== 75 | 76 | * :ref:`genindex` 77 | * :ref:`modindex` 78 | * :ref:`search` 79 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/roles.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Roles"] 5 | 6 | 7 | class Roles(Base): 8 | 9 | def get_all_roles(self): 10 | """Get a list of all the roles 11 | `Read in Mattermost API docs (roles - GetAllRoles) `_ 12 | 13 | """ 14 | return self.client.get("""/api/v4/roles""") 15 | 16 | def get_role(self, role_id: str): 17 | """Get a role 18 | 19 | role_id: Role GUID 20 | 21 | `Read in Mattermost API docs (roles - GetRole) `_ 22 | 23 | """ 24 | return self.client.get(f"/api/v4/roles/{role_id}") 25 | 26 | def get_role_by_name(self, role_name: str): 27 | """Get a role 28 | 29 | role_name: Role Name 30 | 31 | `Read in Mattermost API docs (roles - GetRoleByName) `_ 32 | 33 | """ 34 | return self.client.get(f"/api/v4/roles/name/{role_name}") 35 | 36 | def patch_role(self, role_id: str, permissions: list[str] | None = None): 37 | """Patch a role 38 | 39 | role_id: Role GUID 40 | permissions: The permissions the role should grant. 41 | 42 | `Read in Mattermost API docs (roles - PatchRole) `_ 43 | 44 | """ 45 | __options = {"permissions": permissions} 46 | return self.client.put(f"/api/v4/roles/{role_id}/patch", options=__options) 47 | 48 | def get_roles_by_names(self, options: list[str]): 49 | """Get a list of roles by name 50 | `Read in Mattermost API docs (roles - GetRolesByNames) `_ 51 | 52 | """ 53 | return self.client.post("""/api/v4/roles/names""", options=options) 54 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/terms_of_service.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["TermsOfService"] 5 | 6 | 7 | class TermsOfService(Base): 8 | 9 | def register_terms_of_service_action(self, user_id: str, serviceTermsId: str, accepted: str): 10 | """Records user action when they accept or decline custom terms of service 11 | 12 | user_id: User GUID 13 | serviceTermsId: terms of service ID on which the user is acting on 14 | accepted: true or false, indicates whether the user accepted or rejected the terms of service. 15 | 16 | `Read in Mattermost API docs (terms_of_service - RegisterTermsOfServiceAction) `_ 17 | 18 | """ 19 | __options = {"serviceTermsId": serviceTermsId, "accepted": accepted} 20 | return self.client.post(f"/api/v4/users/{user_id}/terms_of_service", options=__options) 21 | 22 | def get_user_terms_of_service(self, user_id: str): 23 | """Fetches user's latest terms of service action if the latest action was for acceptance. 24 | 25 | user_id: User GUID 26 | 27 | `Read in Mattermost API docs (terms_of_service - GetUserTermsOfService) `_ 28 | 29 | """ 30 | return self.client.get(f"/api/v4/users/{user_id}/terms_of_service") 31 | 32 | def get_terms_of_service(self): 33 | """Get latest terms of service 34 | `Read in Mattermost API docs (terms_of_service - GetTermsOfService) `_ 35 | 36 | """ 37 | return self.client.get("""/api/v4/terms_of_service""") 38 | 39 | def create_terms_of_service(self): 40 | """Creates a new terms of service 41 | `Read in Mattermost API docs (terms_of_service - CreateTermsOfService) `_ 42 | 43 | """ 44 | return self.client.post("""/api/v4/terms_of_service""") 45 | -------------------------------------------------------------------------------- /docs/api_deprecation.rst: -------------------------------------------------------------------------------- 1 | API Deprecation 2 | =============== 3 | 4 | For historical context refer to `pull request #23 `_. 5 | 6 | The new API exposes all arguments explicitly instead of encapsulated in a dictionary. 7 | This change affects most endpoints that accept optional arguments including file uploads. 8 | 9 | You won't need to modify your code for calls such as these: 10 | 11 | .. code:: python 12 | 13 | dri = Driver({ 14 | "scheme": "https", 15 | "url": "mattermost.server.com", 16 | "port": 443, 17 | "token": "YourPersonalAccessToken", 18 | 19 | dri.login() 20 | team_id = dri.teams.get_team_by_name("default")["id"] 21 | channel_id = dri.channels.get_channel_by_name(team_id, "town-square") 22 | 23 | but for endpoint calls with options the **old syntax**: 24 | 25 | .. code:: python 26 | 27 | dri.channels.create_channel(options={ 28 | "team_id": team_id, 29 | "name": "awesome-channel", 30 | "display_name": "Awesome Channel", 31 | "type": "O", 32 | }) 33 | 34 | requires an expansion of the options dictionary: 35 | 36 | .. code:: python 37 | 38 | dri.channels.create_channel(**{ 39 | "team_id": team_id, 40 | "name": "awesome-channel", 41 | "display_name": "Awesome Channel", 42 | "type": "O", 43 | }) 44 | 45 | This shortcut works so long as none of the arguments clashes with python keywords. 46 | Examples from clashes include ``from`` 47 | 48 | or that arguments are passed explicitly: 49 | 50 | .. code:: python 51 | 52 | dri.channels.create_channel( 53 | team_id=team_id, 54 | name="awesome-channel", 55 | display_name="Awesome Channel", 56 | type="O", 57 | ) 58 | 59 | I want to continue using the old API 60 | ------------------------------------ 61 | 62 | If you want to continue using the deprecated API you can do so by using ``Driver`` instead of the new ``TypedDriver`` which will allow you to use the old interface but will raise a ``DeprecationWarning``. 63 | 64 | Please note that this interface will be removed in the future so we recommend that you update your code as soon as possible. 65 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/search.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Search"] 4 | 5 | 6 | class Search(Base): 7 | 8 | def search_files(self, team_id, data): 9 | """Search files in a team 10 | 11 | team_id: Team GUID 12 | terms: The search terms as inputed by the user. To search for files from a user include ``from:someusername``, using a user's username. To search in a specific channel include ``in:somechannel``, using the channel name (not the display name). To search for specific extensions include ``ext:extension``. 13 | is_or_search: Set to true if an Or search should be performed vs an And search. 14 | time_zone_offset: Offset from UTC of user timezone for date searches. 15 | include_deleted_channels: Set to true if deleted channels should be included in the search. (archived channels) 16 | page: The page to select. (Only works with Elasticsearch) 17 | per_page: The number of posts per page. (Only works with Elasticsearch) 18 | 19 | `Read in Mattermost API docs (search - SearchFiles) `_ 20 | 21 | """ 22 | return self.client.post(f"/api/v4/teams/{team_id}/files/search", data=data) 23 | 24 | def search_files(self, data): 25 | """Search files across the teams of the current user 26 | 27 | terms: The search terms as entered by the user. To search for files from a user include ``from:someusername``, using a user's username. To search in a specific channel include ``in:somechannel``, using the channel name (not the display name). To search for specific extensions include ``ext:extension``. 28 | is_or_search: Set to true if an Or search should be performed vs an And search. 29 | time_zone_offset: Offset from UTC of user timezone for date searches. 30 | include_deleted_channels: Set to true if deleted channels should be included in the search. (archived channels) 31 | page: The page to select. (Only works with Elasticsearch) 32 | per_page: The number of posts per page. (Only works with Elasticsearch) 33 | 34 | `Read in Mattermost API docs (search - SearchFiles) `_ 35 | 36 | """ 37 | return self.client.post("""/api/v4/files/search""", data=data) 38 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/integration_actions.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["IntegrationActions"] 4 | 5 | 6 | class IntegrationActions(Base): 7 | 8 | def open_interactive_dialog(self, options): 9 | """Open a dialog 10 | 11 | trigger_id: Trigger ID provided by other action 12 | url: The URL to send the submitted dialog payload to 13 | dialog: Post object to create 14 | 15 | `Read in Mattermost API docs (integration_actions - OpenInteractiveDialog) `_ 16 | 17 | """ 18 | return self.client.post("""/api/v4/actions/dialogs/open""", options=options) 19 | 20 | def submit_interactive_dialog(self, options): 21 | """Submit a dialog 22 | 23 | url: The URL to send the submitted dialog payload to 24 | channel_id: Channel ID the user submitted the dialog from 25 | team_id: Team ID the user submitted the dialog from 26 | submission: String map where keys are element names and values are the element input values 27 | callback_id: Callback ID sent when the dialog was opened 28 | state: State sent when the dialog was opened 29 | cancelled: Set to true if the dialog was cancelled 30 | 31 | `Read in Mattermost API docs (integration_actions - SubmitInteractiveDialog) `_ 32 | 33 | """ 34 | return self.client.post("""/api/v4/actions/dialogs/submit""", options=options) 35 | 36 | def lookup_interactive_dialog(self, options): 37 | """Lookup dialog elements 38 | 39 | url: The URL to send the lookup request to 40 | channel_id: Channel ID the user is performing the lookup from 41 | team_id: Team ID the user is performing the lookup from 42 | submission: String map where keys are element names and values are the element input values 43 | callback_id: Callback ID sent when the dialog was opened 44 | state: State sent when the dialog was opened 45 | 46 | `Read in Mattermost API docs (integration_actions - LookupInteractiveDialog) `_ 47 | 48 | """ 49 | return self.client.post("""/api/v4/actions/dialogs/lookup""", options=options) 50 | -------------------------------------------------------------------------------- /src/mattermostautodriver/driver/base.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import warnings 3 | 4 | from ..client import Client 5 | 6 | log = logging.getLogger("mattermostautodriver.api") 7 | log.setLevel(logging.INFO) 8 | 9 | 10 | class BaseDriver: 11 | """ 12 | Contains the client, api and provides you with functions for 13 | login, logout and initializing a websocket connection. 14 | """ 15 | 16 | default_options = { 17 | "scheme": "https", 18 | "url": "localhost", 19 | "port": 8065, 20 | "verify": True, 21 | "timeout": 30, 22 | "request_timeout": None, 23 | "login_id": None, 24 | "password": None, 25 | "token": None, 26 | "mfa_token": None, 27 | "auth": None, 28 | "keepalive": False, 29 | "keepalive_delay": 5, 30 | "websocket_kw_args": None, 31 | "debug": False, 32 | "http2": False, 33 | "proxy": None, 34 | } 35 | """ 36 | Required options 37 | - url 38 | 39 | Either 40 | - login_id 41 | - password 42 | 43 | Or 44 | - token (https://docs.mattermost.com/developer/personal-access-tokens.html) 45 | 46 | Optional 47 | - scheme ('https') 48 | - port (8065) 49 | - verify (True) 50 | - timeout (30) 51 | - request_timeout (None) 52 | - mfa_token (None) 53 | - auth (None) 54 | - debug (False) 55 | """ 56 | 57 | def __init__(self, options=None, client_cls=Client, *args, **kwargs): 58 | """ 59 | :param options: A dict with the values from `default_options` 60 | :type options: dict 61 | """ 62 | self.options = self.default_options.copy() 63 | if options is not None: 64 | self.options.update(options) 65 | self.driver = self.options 66 | if self.options["debug"]: 67 | log.setLevel(logging.DEBUG) 68 | log.warning( 69 | "Careful!!\nSetting debug to True, will reveal your password in the log output if you do driver.login()!\nThis is NOT for production!" 70 | ) 71 | self.client = client_cls(self.options) 72 | self.websocket = None 73 | 74 | def disconnect(self): 75 | """Disconnects the driver from the server, stopping the websocket event loop.""" 76 | if self.websocket is not None: 77 | self.websocket.disconnect() 78 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | mattermost 3 | 4 | ### Python template 5 | # Byte-compiled / optimized / DLL files 6 | __pycache__/ 7 | *.py[cod] 8 | *$py.class 9 | 10 | # C extensions 11 | *.so 12 | 13 | # Distribution / packaging 14 | .Python 15 | env/ 16 | build/ 17 | develop-eggs/ 18 | dist/ 19 | downloads/ 20 | eggs/ 21 | .eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | wheels/ 28 | *.egg-info/ 29 | .installed.cfg 30 | *.egg 31 | 32 | # PyInstaller 33 | # Usually these files are written by a python script from a template 34 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 35 | *.manifest 36 | *.spec 37 | 38 | # Installer logs 39 | pip-log.txt 40 | pip-delete-this-directory.txt 41 | 42 | # Unit test / coverage reports 43 | htmlcov/ 44 | .tox/ 45 | .coverage 46 | .coverage.* 47 | .cache 48 | nosetests.xml 49 | coverage.xml 50 | *,cover 51 | .hypothesis/ 52 | 53 | # Translations 54 | *.mo 55 | *.pot 56 | 57 | # Django stuff: 58 | *.log 59 | local_settings.py 60 | 61 | # Flask stuff: 62 | instance/ 63 | .webassets-cache 64 | 65 | # Scrapy stuff: 66 | .scrapy 67 | 68 | # Sphinx documentation 69 | docs/_build/ 70 | 71 | # PyBuilder 72 | target/ 73 | 74 | # Jupyter Notebook 75 | .ipynb_checkpoints 76 | 77 | # pyenv 78 | .python-version 79 | 80 | # celery beat schedule file 81 | celerybeat-schedule 82 | 83 | # SageMath parsed files 84 | *.sage.py 85 | 86 | # dotenv 87 | .env 88 | 89 | # virtualenv 90 | .venv 91 | venv/ 92 | ENV/ 93 | 94 | # Spyder project settings 95 | .spyderproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | ### JetBrains template 100 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 101 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 102 | 103 | # User-specific stuff: 104 | .idea 105 | 106 | ## File-based project format: 107 | *.iws 108 | 109 | ## Plugin-specific files: 110 | 111 | # IntelliJ 112 | /out/ 113 | 114 | # mpeltonen/sbt-idea plugin 115 | .idea_modules/ 116 | 117 | # JIRA plugin 118 | atlassian-ide-plugin.xml 119 | 120 | # Crashlytics plugin (for Android Studio and IntelliJ) 121 | com_crashlytics_export_strings.xml 122 | crashlytics.properties 123 | crashlytics-build.properties 124 | fabric.properties 125 | 126 | # vscode ide 127 | *.code-workspace 128 | .vscode 129 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/preferences.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Preferences"] 4 | 5 | 6 | class Preferences(Base): 7 | 8 | def get_preferences(self, user_id): 9 | """Get the user's preferences 10 | 11 | user_id: User GUID 12 | 13 | `Read in Mattermost API docs (preferences - GetPreferences) `_ 14 | 15 | """ 16 | return self.client.get(f"/api/v4/users/{user_id}/preferences") 17 | 18 | def update_preferences(self, user_id, options): 19 | """Save the user's preferences 20 | 21 | user_id: User GUID 22 | 23 | `Read in Mattermost API docs (preferences - UpdatePreferences) `_ 24 | 25 | """ 26 | return self.client.put(f"/api/v4/users/{user_id}/preferences", options=options) 27 | 28 | def delete_preferences(self, user_id, options): 29 | """Delete user's preferences 30 | 31 | user_id: User GUID 32 | 33 | `Read in Mattermost API docs (preferences - DeletePreferences) `_ 34 | 35 | """ 36 | return self.client.post(f"/api/v4/users/{user_id}/preferences/delete", options=options) 37 | 38 | def get_preferences_by_category(self, user_id, category): 39 | """List a user's preferences by category 40 | 41 | user_id: User GUID 42 | category: The category of a group of preferences 43 | 44 | `Read in Mattermost API docs (preferences - GetPreferencesByCategory) `_ 45 | 46 | """ 47 | return self.client.get(f"/api/v4/users/{user_id}/preferences/{category}") 48 | 49 | def get_preferences_by_category_by_name(self, user_id, category, preference_name): 50 | """Get a specific user preference 51 | 52 | user_id: User GUID 53 | category: The category of a group of preferences 54 | preference_name: The name of the preference 55 | 56 | `Read in Mattermost API docs (preferences - GetPreferencesByCategoryByName) `_ 57 | 58 | """ 59 | return self.client.get(f"/api/v4/users/{user_id}/preferences/{category}/name/{preference_name}") 60 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/internal.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Internal"] 4 | 5 | 6 | class Internal(Base): 7 | 8 | def create_playbook_run_from_dialog(self, options=None): 9 | """Create a new playbook run from dialog 10 | 11 | type: 12 | url: 13 | callback_id: Callback ID provided by the integration. 14 | state: Stringified JSON with the post_id and the client_id. 15 | user_id: ID of the user who submitted the dialog. 16 | channel_id: ID of the channel the user was in when submitting the dialog. 17 | team_id: ID of the team the user was on when submitting the dialog. 18 | submission: Map of the dialog fields to their values 19 | cancelled: If the dialog was cancelled. 20 | 21 | `Read in Mattermost API docs (internal - createPlaybookRunFromDialog) `_ 22 | 23 | """ 24 | return self.client.post("""/plugins/playbooks/api/v0/runs/dialog""", options=options) 25 | 26 | def get_checklist_autocomplete(self, params=None): 27 | """Get autocomplete data for /playbook check 28 | 29 | channel_ID: ID of the channel the user is in. 30 | 31 | `Read in Mattermost API docs (internal - getChecklistAutocomplete) `_ 32 | 33 | """ 34 | return self.client.get("""/plugins/playbooks/api/v0/runs/checklist-autocomplete""", params=params) 35 | 36 | def end_playbook_run_dialog(self, id): 37 | """End a playbook run from dialog 38 | 39 | id: ID of the playbook run to end. 40 | 41 | `Read in Mattermost API docs (internal - endPlaybookRunDialog) `_ 42 | 43 | """ 44 | return self.client.post(f"/plugins/playbooks/api/v0/runs/{id}/end") 45 | 46 | def next_stage_dialog(self, id, options=None): 47 | """Go to next stage from dialog 48 | 49 | id: The PlaybookRun ID 50 | state: String representation of the zero-based index of the stage to go to. 51 | 52 | `Read in Mattermost API docs (internal - nextStageDialog) `_ 53 | 54 | """ 55 | return self.client.post(f"/plugins/playbooks/api/v0/runs/{id}/next-stage-dialog", options=options) 56 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/preferences.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Preferences"] 5 | 6 | 7 | class Preferences(Base): 8 | 9 | def get_preferences(self, user_id: str): 10 | """Get the user's preferences 11 | 12 | user_id: User GUID 13 | 14 | `Read in Mattermost API docs (preferences - GetPreferences) `_ 15 | 16 | """ 17 | return self.client.get(f"/api/v4/users/{user_id}/preferences") 18 | 19 | def update_preferences(self, user_id: str, options: list[Any]): 20 | """Save the user's preferences 21 | 22 | user_id: User GUID 23 | 24 | `Read in Mattermost API docs (preferences - UpdatePreferences) `_ 25 | 26 | """ 27 | return self.client.put(f"/api/v4/users/{user_id}/preferences", options=options) 28 | 29 | def delete_preferences(self, user_id: str, options: list[Any]): 30 | """Delete user's preferences 31 | 32 | user_id: User GUID 33 | 34 | `Read in Mattermost API docs (preferences - DeletePreferences) `_ 35 | 36 | """ 37 | return self.client.post(f"/api/v4/users/{user_id}/preferences/delete", options=options) 38 | 39 | def get_preferences_by_category(self, user_id: str, category: str): 40 | """List a user's preferences by category 41 | 42 | user_id: User GUID 43 | category: The category of a group of preferences 44 | 45 | `Read in Mattermost API docs (preferences - GetPreferencesByCategory) `_ 46 | 47 | """ 48 | return self.client.get(f"/api/v4/users/{user_id}/preferences/{category}") 49 | 50 | def get_preferences_by_category_by_name(self, user_id: str, category: str, preference_name: str): 51 | """Get a specific user preference 52 | 53 | user_id: User GUID 54 | category: The category of a group of preferences 55 | preference_name: The name of the preference 56 | 57 | `Read in Mattermost API docs (preferences - GetPreferencesByCategoryByName) `_ 58 | 59 | """ 60 | return self.client.get(f"/api/v4/users/{user_id}/preferences/{category}/name/{preference_name}") 61 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/oauth.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Oauth"] 4 | 5 | 6 | class Oauth(Base): 7 | 8 | def list_outgoing_o_auth_connections(self, params=None): 9 | """List all connections 10 | 11 | team_id: Current Team ID in integrations backstage 12 | 13 | `Read in Mattermost API docs (oauth - ListOutgoingOAuthConnections) `_ 14 | 15 | """ 16 | return self.client.get("""/api/v4/oauth/outgoing_connections""", params=params) 17 | 18 | def create_outgoing_o_auth_connection(self, options=None): 19 | """Create a connection 20 | `Read in Mattermost API docs (oauth - CreateOutgoingOAuthConnection) `_ 21 | 22 | """ 23 | return self.client.post("""/api/v4/oauth/outgoing_connections""", options=options) 24 | 25 | def get_outgoing_o_auth_connection(self, params=None): 26 | """Get a connection 27 | 28 | team_id: Current Team ID in integrations backstage 29 | 30 | `Read in Mattermost API docs (oauth - GetOutgoingOAuthConnection) `_ 31 | 32 | """ 33 | return self.client.get(f"/api/v4/oauth/outgoing_connections/{connection_id}", params=params) 34 | 35 | def update_outgoing_o_auth_connection(self, options=None): 36 | """Update a connection 37 | `Read in Mattermost API docs (oauth - UpdateOutgoingOAuthConnection) `_ 38 | 39 | """ 40 | return self.client.put(f"/api/v4/oauth/outgoing_connections/{connection_id}", options=options) 41 | 42 | def delete_outgoing_o_auth_connection(self): 43 | """Delete a connection 44 | `Read in Mattermost API docs (oauth - DeleteOutgoingOAuthConnection) `_ 45 | 46 | """ 47 | return self.client.delete(f"/api/v4/oauth/outgoing_connections/{connection_id}") 48 | 49 | def validate_outgoing_o_auth_connection(self, options=None): 50 | """Validate a connection configuration 51 | `Read in Mattermost API docs (oauth - ValidateOutgoingOAuthConnection) `_ 52 | 53 | """ 54 | return self.client.post("""/api/v4/oauth/outgoing_connections/validate""", options=options) 55 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/outgoing_connections.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["OutgoingConnections"] 4 | 5 | 6 | class OutgoingConnections(Base): 7 | 8 | def list_outgoing_o_auth_connections(self, params=None): 9 | """List all connections 10 | 11 | team_id: Current Team ID in integrations backstage 12 | 13 | `Read in Mattermost API docs (outgoing_connections - ListOutgoingOAuthConnections) `_ 14 | 15 | """ 16 | return self.client.get("""/api/v4/oauth/outgoing_connections""", params=params) 17 | 18 | def create_outgoing_o_auth_connection(self, options=None): 19 | """Create a connection 20 | `Read in Mattermost API docs (outgoing_connections - CreateOutgoingOAuthConnection) `_ 21 | 22 | """ 23 | return self.client.post("""/api/v4/oauth/outgoing_connections""", options=options) 24 | 25 | def get_outgoing_o_auth_connection(self, params=None): 26 | """Get a connection 27 | 28 | team_id: Current Team ID in integrations backstage 29 | 30 | `Read in Mattermost API docs (outgoing_connections - GetOutgoingOAuthConnection) `_ 31 | 32 | """ 33 | return self.client.get(f"/api/v4/oauth/outgoing_connections/{connection_id}", params=params) 34 | 35 | def update_outgoing_o_auth_connection(self, options=None): 36 | """Update a connection 37 | `Read in Mattermost API docs (outgoing_connections - UpdateOutgoingOAuthConnection) `_ 38 | 39 | """ 40 | return self.client.put(f"/api/v4/oauth/outgoing_connections/{connection_id}", options=options) 41 | 42 | def delete_outgoing_o_auth_connection(self): 43 | """Delete a connection 44 | `Read in Mattermost API docs (outgoing_connections - DeleteOutgoingOAuthConnection) `_ 45 | 46 | """ 47 | return self.client.delete(f"/api/v4/oauth/outgoing_connections/{connection_id}") 48 | 49 | def validate_outgoing_o_auth_connection(self, options=None): 50 | """Validate a connection configuration 51 | `Read in Mattermost API docs (outgoing_connections - ValidateOutgoingOAuthConnection) `_ 52 | 53 | """ 54 | return self.client.post("""/api/v4/oauth/outgoing_connections/validate""", options=options) 55 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/conditions.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Conditions"] 4 | 5 | 6 | class Conditions(Base): 7 | 8 | def get_playbook_conditions(self, id, params=None): 9 | """List playbook conditions 10 | 11 | id: ID of the playbook to retrieve conditions from. 12 | page: Zero-based index of the page to request. 13 | per_page: Number of conditions to return per page. 14 | 15 | `Read in Mattermost API docs (conditions - getPlaybookConditions) `_ 16 | 17 | """ 18 | return self.client.get(f"/plugins/playbooks/api/v0/playbooks/{id}/conditions", params=params) 19 | 20 | def create_playbook_condition(self, id, options=None): 21 | """Create a playbook condition 22 | 23 | id: ID of the playbook to create a condition for. 24 | 25 | `Read in Mattermost API docs (conditions - createPlaybookCondition) `_ 26 | 27 | """ 28 | return self.client.post(f"/plugins/playbooks/api/v0/playbooks/{id}/conditions", options=options) 29 | 30 | def update_playbook_condition(self, id, conditionID, options=None): 31 | """Update a playbook condition 32 | 33 | id: ID of the playbook. 34 | conditionID: ID of the condition to update. 35 | 36 | `Read in Mattermost API docs (conditions - updatePlaybookCondition) `_ 37 | 38 | """ 39 | return self.client.put(f"/plugins/playbooks/api/v0/playbooks/{id}/conditions/{conditionID}", options=options) 40 | 41 | def delete_playbook_condition(self, id, conditionID): 42 | """Delete a playbook condition 43 | 44 | id: ID of the playbook. 45 | conditionID: ID of the condition to delete. 46 | 47 | `Read in Mattermost API docs (conditions - deletePlaybookCondition) `_ 48 | 49 | """ 50 | return self.client.delete(f"/plugins/playbooks/api/v0/playbooks/{id}/conditions/{conditionID}") 51 | 52 | def get_run_conditions(self, id, params=None): 53 | """List run conditions 54 | 55 | id: ID of the run to retrieve conditions from. 56 | page: Zero-based index of the page to request. 57 | per_page: Number of conditions to return per page. 58 | 59 | `Read in Mattermost API docs (conditions - getRunConditions) `_ 60 | 61 | """ 62 | return self.client.get(f"/plugins/playbooks/api/v0/runs/{id}/conditions", params=params) 63 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/scheduled_post.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["ScheduledPost"] 4 | 5 | 6 | class ScheduledPost(Base): 7 | 8 | def create_scheduled_post(self, options=None): 9 | """Creates a scheduled post 10 | 11 | scheduled_at: UNIX timestamp in milliseconds of the time when the scheduled post should be sent 12 | channel_id: The channel ID to post in 13 | message: The message contents, can be formatted with Markdown 14 | root_id: The post ID to comment on 15 | file_ids: A list of file IDs to associate with the post. Note that posts are limited to 5 files maximum. Please use additional posts for more files. 16 | props: A general JSON property bag to attach to the post 17 | 18 | `Read in Mattermost API docs (scheduled_post - CreateScheduledPost) `_ 19 | 20 | """ 21 | return self.client.post("""/api/v4/posts/schedule""", options=options) 22 | 23 | def get_user_scheduled_posts(self, params=None): 24 | """Gets all scheduled posts for a user for the specified team.. 25 | 26 | includeDirectChannels: Whether to include scheduled posts from DMs an GMs or not. Default is false 27 | 28 | `Read in Mattermost API docs (scheduled_post - GetUserScheduledPosts) `_ 29 | 30 | """ 31 | return self.client.get(f"/api/v4/posts/scheduled/team/{team_id}", params=params) 32 | 33 | def update_scheduled_post(self, scheduled_post_id, options=None): 34 | """Update a scheduled post 35 | 36 | scheduled_post_id: ID of the scheduled post to update 37 | id: ID of the scheduled post to update 38 | channel_id: The channel ID to post in 39 | user_id: The current user ID 40 | scheduled_at: UNIX timestamp in milliseconds of the time when the scheduled post should be sent 41 | message: The message contents, can be formatted with Markdown 42 | 43 | `Read in Mattermost API docs (scheduled_post - UpdateScheduledPost) `_ 44 | 45 | """ 46 | return self.client.put(f"/api/v4/posts/schedule/{scheduled_post_id}", options=options) 47 | 48 | def delete_scheduled_post(self, scheduled_post_id): 49 | """Delete a scheduled post 50 | 51 | scheduled_post_id: ID of the scheduled post to delete 52 | 53 | `Read in Mattermost API docs (scheduled_post - DeleteScheduledPost) `_ 54 | 55 | """ 56 | return self.client.delete(f"/api/v4/posts/schedule/{scheduled_post_id}") 57 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/oauth.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Oauth"] 5 | 6 | 7 | class Oauth(Base): 8 | 9 | def list_outgoing_o_auth_connections(self, team_id: str): 10 | """List all connections 11 | 12 | team_id: Current Team ID in integrations backstage 13 | 14 | `Read in Mattermost API docs (oauth - ListOutgoingOAuthConnections) `_ 15 | 16 | """ 17 | __params = {"team_id": team_id} 18 | return self.client.get("""/api/v4/oauth/outgoing_connections""", params=__params) 19 | 20 | def create_outgoing_o_auth_connection(self, options: Any | None = None): 21 | """Create a connection 22 | `Read in Mattermost API docs (oauth - CreateOutgoingOAuthConnection) `_ 23 | 24 | """ 25 | return self.client.post("""/api/v4/oauth/outgoing_connections""", options=options) 26 | 27 | def get_outgoing_o_auth_connection(self, team_id: str): 28 | """Get a connection 29 | 30 | team_id: Current Team ID in integrations backstage 31 | 32 | `Read in Mattermost API docs (oauth - GetOutgoingOAuthConnection) `_ 33 | 34 | """ 35 | __params = {"team_id": team_id} 36 | return self.client.get(f"/api/v4/oauth/outgoing_connections/{connection_id}", params=__params) 37 | 38 | def update_outgoing_o_auth_connection(self, options: Any | None = None): 39 | """Update a connection 40 | `Read in Mattermost API docs (oauth - UpdateOutgoingOAuthConnection) `_ 41 | 42 | """ 43 | return self.client.put(f"/api/v4/oauth/outgoing_connections/{connection_id}", options=options) 44 | 45 | def delete_outgoing_o_auth_connection(self): 46 | """Delete a connection 47 | `Read in Mattermost API docs (oauth - DeleteOutgoingOAuthConnection) `_ 48 | 49 | """ 50 | return self.client.delete(f"/api/v4/oauth/outgoing_connections/{connection_id}") 51 | 52 | def validate_outgoing_o_auth_connection(self, options: Any | None = None): 53 | """Validate a connection configuration 54 | `Read in Mattermost API docs (oauth - ValidateOutgoingOAuthConnection) `_ 55 | 56 | """ 57 | return self.client.post("""/api/v4/oauth/outgoing_connections/validate""", options=options) 58 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/outgoing_oauth_connections.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["OutgoingOauthConnections"] 4 | 5 | 6 | class OutgoingOauthConnections(Base): 7 | 8 | def list_outgoing_o_auth_connections(self, params=None): 9 | """List all connections 10 | 11 | team_id: Current Team ID in integrations backstage 12 | 13 | `Read in Mattermost API docs (outgoing_oauth_connections - ListOutgoingOAuthConnections) `_ 14 | 15 | """ 16 | return self.client.get("""/api/v4/oauth/outgoing_connections""", params=params) 17 | 18 | def create_outgoing_o_auth_connection(self, options=None): 19 | """Create a connection 20 | `Read in Mattermost API docs (outgoing_oauth_connections - CreateOutgoingOAuthConnection) `_ 21 | 22 | """ 23 | return self.client.post("""/api/v4/oauth/outgoing_connections""", options=options) 24 | 25 | def get_outgoing_o_auth_connection(self, params=None): 26 | """Get a connection 27 | 28 | team_id: Current Team ID in integrations backstage 29 | 30 | `Read in Mattermost API docs (outgoing_oauth_connections - GetOutgoingOAuthConnection) `_ 31 | 32 | """ 33 | return self.client.get(f"/api/v4/oauth/outgoing_connections/{connection_id}", params=params) 34 | 35 | def update_outgoing_o_auth_connection(self, options=None): 36 | """Update a connection 37 | `Read in Mattermost API docs (outgoing_oauth_connections - UpdateOutgoingOAuthConnection) `_ 38 | 39 | """ 40 | return self.client.put(f"/api/v4/oauth/outgoing_connections/{connection_id}", options=options) 41 | 42 | def delete_outgoing_o_auth_connection(self): 43 | """Delete a connection 44 | `Read in Mattermost API docs (outgoing_oauth_connections - DeleteOutgoingOAuthConnection) `_ 45 | 46 | """ 47 | return self.client.delete(f"/api/v4/oauth/outgoing_connections/{connection_id}") 48 | 49 | def validate_outgoing_o_auth_connection(self, options=None): 50 | """Validate a connection configuration 51 | `Read in Mattermost API docs (outgoing_oauth_connections - ValidateOutgoingOAuthConnection) `_ 52 | 53 | """ 54 | return self.client.post("""/api/v4/oauth/outgoing_connections/validate""", options=options) 55 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/outgoing_connections.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["OutgoingConnections"] 5 | 6 | 7 | class OutgoingConnections(Base): 8 | 9 | def list_outgoing_o_auth_connections(self, team_id: str): 10 | """List all connections 11 | 12 | team_id: Current Team ID in integrations backstage 13 | 14 | `Read in Mattermost API docs (outgoing_connections - ListOutgoingOAuthConnections) `_ 15 | 16 | """ 17 | __params = {"team_id": team_id} 18 | return self.client.get("""/api/v4/oauth/outgoing_connections""", params=__params) 19 | 20 | def create_outgoing_o_auth_connection(self, options: Any | None = None): 21 | """Create a connection 22 | `Read in Mattermost API docs (outgoing_connections - CreateOutgoingOAuthConnection) `_ 23 | 24 | """ 25 | return self.client.post("""/api/v4/oauth/outgoing_connections""", options=options) 26 | 27 | def get_outgoing_o_auth_connection(self, team_id: str): 28 | """Get a connection 29 | 30 | team_id: Current Team ID in integrations backstage 31 | 32 | `Read in Mattermost API docs (outgoing_connections - GetOutgoingOAuthConnection) `_ 33 | 34 | """ 35 | __params = {"team_id": team_id} 36 | return self.client.get(f"/api/v4/oauth/outgoing_connections/{connection_id}", params=__params) 37 | 38 | def update_outgoing_o_auth_connection(self, options: Any | None = None): 39 | """Update a connection 40 | `Read in Mattermost API docs (outgoing_connections - UpdateOutgoingOAuthConnection) `_ 41 | 42 | """ 43 | return self.client.put(f"/api/v4/oauth/outgoing_connections/{connection_id}", options=options) 44 | 45 | def delete_outgoing_o_auth_connection(self): 46 | """Delete a connection 47 | `Read in Mattermost API docs (outgoing_connections - DeleteOutgoingOAuthConnection) `_ 48 | 49 | """ 50 | return self.client.delete(f"/api/v4/oauth/outgoing_connections/{connection_id}") 51 | 52 | def validate_outgoing_o_auth_connection(self, options: Any | None = None): 53 | """Validate a connection configuration 54 | `Read in Mattermost API docs (outgoing_connections - ValidateOutgoingOAuthConnection) `_ 55 | 56 | """ 57 | return self.client.post("""/api/v4/oauth/outgoing_connections/validate""", options=options) 58 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/outgoing_oauth_connections.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["OutgoingOauthConnections"] 5 | 6 | 7 | class OutgoingOauthConnections(Base): 8 | 9 | def list_outgoing_o_auth_connections(self, team_id: str): 10 | """List all connections 11 | 12 | team_id: Current Team ID in integrations backstage 13 | 14 | `Read in Mattermost API docs (outgoing_oauth_connections - ListOutgoingOAuthConnections) `_ 15 | 16 | """ 17 | __params = {"team_id": team_id} 18 | return self.client.get("""/api/v4/oauth/outgoing_connections""", params=__params) 19 | 20 | def create_outgoing_o_auth_connection(self, options: Any | None = None): 21 | """Create a connection 22 | `Read in Mattermost API docs (outgoing_oauth_connections - CreateOutgoingOAuthConnection) `_ 23 | 24 | """ 25 | return self.client.post("""/api/v4/oauth/outgoing_connections""", options=options) 26 | 27 | def get_outgoing_o_auth_connection(self, team_id: str): 28 | """Get a connection 29 | 30 | team_id: Current Team ID in integrations backstage 31 | 32 | `Read in Mattermost API docs (outgoing_oauth_connections - GetOutgoingOAuthConnection) `_ 33 | 34 | """ 35 | __params = {"team_id": team_id} 36 | return self.client.get(f"/api/v4/oauth/outgoing_connections/{connection_id}", params=__params) 37 | 38 | def update_outgoing_o_auth_connection(self, options: Any | None = None): 39 | """Update a connection 40 | `Read in Mattermost API docs (outgoing_oauth_connections - UpdateOutgoingOAuthConnection) `_ 41 | 42 | """ 43 | return self.client.put(f"/api/v4/oauth/outgoing_connections/{connection_id}", options=options) 44 | 45 | def delete_outgoing_o_auth_connection(self): 46 | """Delete a connection 47 | `Read in Mattermost API docs (outgoing_oauth_connections - DeleteOutgoingOAuthConnection) `_ 48 | 49 | """ 50 | return self.client.delete(f"/api/v4/oauth/outgoing_connections/{connection_id}") 51 | 52 | def validate_outgoing_o_auth_connection(self, options: Any | None = None): 53 | """Validate a connection configuration 54 | `Read in Mattermost API docs (outgoing_oauth_connections - ValidateOutgoingOAuthConnection) `_ 55 | 56 | """ 57 | return self.client.post("""/api/v4/oauth/outgoing_connections/validate""", options=options) 58 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/jobs.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Jobs"] 4 | 5 | 6 | class Jobs(Base): 7 | 8 | def get_jobs(self, params=None): 9 | """Get the jobs. 10 | 11 | page: The page to select. 12 | per_page: The number of jobs per page. 13 | job_type: The type of jobs to fetch. 14 | status: The status of jobs to fetch. 15 | 16 | `Read in Mattermost API docs (jobs - GetJobs) `_ 17 | 18 | """ 19 | return self.client.get("""/api/v4/jobs""", params=params) 20 | 21 | def create_job(self, options): 22 | """Create a new job. 23 | 24 | type: The type of job to create 25 | data: An object containing any additional data required for this job type 26 | 27 | `Read in Mattermost API docs (jobs - CreateJob) `_ 28 | 29 | """ 30 | return self.client.post("""/api/v4/jobs""", options=options) 31 | 32 | def get_job(self, job_id): 33 | """Get a job. 34 | 35 | job_id: Job GUID 36 | 37 | `Read in Mattermost API docs (jobs - GetJob) `_ 38 | 39 | """ 40 | return self.client.get(f"/api/v4/jobs/{job_id}") 41 | 42 | def download_job(self, job_id): 43 | """Download the results of a job. 44 | 45 | job_id: Job GUID 46 | 47 | `Read in Mattermost API docs (jobs - DownloadJob) `_ 48 | 49 | """ 50 | return self.client.get(f"/api/v4/jobs/{job_id}/download") 51 | 52 | def cancel_job(self, job_id): 53 | """Cancel a job. 54 | 55 | job_id: Job GUID 56 | 57 | `Read in Mattermost API docs (jobs - CancelJob) `_ 58 | 59 | """ 60 | return self.client.post(f"/api/v4/jobs/{job_id}/cancel") 61 | 62 | def get_jobs_by_type(self, type, params=None): 63 | """Get the jobs of the given type. 64 | 65 | type: Job type 66 | page: The page to select. 67 | per_page: The number of jobs per page. 68 | 69 | `Read in Mattermost API docs (jobs - GetJobsByType) `_ 70 | 71 | """ 72 | return self.client.get(f"/api/v4/jobs/type/{type}", params=params) 73 | 74 | def update_job_status(self, job_id, options): 75 | """Update the status of a job 76 | 77 | job_id: Job GUID 78 | status: The status you want to set 79 | force: Set this to true to bypass status restrictions 80 | 81 | `Read in Mattermost API docs (jobs - UpdateJobStatus) `_ 82 | 83 | """ 84 | return self.client.patch(f"/api/v4/jobs/{job_id}/status", options=options) 85 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/conditions.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Conditions"] 5 | 6 | 7 | class Conditions(Base): 8 | 9 | def get_playbook_conditions(self, id: str, page: int | None = 0, per_page: int | None = 20): 10 | """List playbook conditions 11 | 12 | id: ID of the playbook to retrieve conditions from. 13 | page: Zero-based index of the page to request. 14 | per_page: Number of conditions to return per page. 15 | 16 | `Read in Mattermost API docs (conditions - getPlaybookConditions) `_ 17 | 18 | """ 19 | __params = {"page": page, "per_page": per_page} 20 | return self.client.get(f"/plugins/playbooks/api/v0/playbooks/{id}/conditions", params=__params) 21 | 22 | def create_playbook_condition(self, id: str, options: Any | None = None): 23 | """Create a playbook condition 24 | 25 | id: ID of the playbook to create a condition for. 26 | 27 | `Read in Mattermost API docs (conditions - createPlaybookCondition) `_ 28 | 29 | """ 30 | return self.client.post(f"/plugins/playbooks/api/v0/playbooks/{id}/conditions", options=options) 31 | 32 | def update_playbook_condition(self, id: str, conditionID: str, options: Any | None = None): 33 | """Update a playbook condition 34 | 35 | id: ID of the playbook. 36 | conditionID: ID of the condition to update. 37 | 38 | `Read in Mattermost API docs (conditions - updatePlaybookCondition) `_ 39 | 40 | """ 41 | return self.client.put(f"/plugins/playbooks/api/v0/playbooks/{id}/conditions/{conditionID}", options=options) 42 | 43 | def delete_playbook_condition(self, id: str, conditionID: str): 44 | """Delete a playbook condition 45 | 46 | id: ID of the playbook. 47 | conditionID: ID of the condition to delete. 48 | 49 | `Read in Mattermost API docs (conditions - deletePlaybookCondition) `_ 50 | 51 | """ 52 | return self.client.delete(f"/plugins/playbooks/api/v0/playbooks/{id}/conditions/{conditionID}") 53 | 54 | def get_run_conditions(self, id: str, page: int | None = 0, per_page: int | None = 20): 55 | """List run conditions 56 | 57 | id: ID of the run to retrieve conditions from. 58 | page: Zero-based index of the page to request. 59 | per_page: Number of conditions to return per page. 60 | 61 | `Read in Mattermost API docs (conditions - getRunConditions) `_ 62 | 63 | """ 64 | __params = {"page": page, "per_page": per_page} 65 | return self.client.get(f"/plugins/playbooks/api/v0/runs/{id}/conditions", params=__params) 66 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/internal.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Internal"] 5 | 6 | 7 | class Internal(Base): 8 | 9 | def create_playbook_run_from_dialog( 10 | self, 11 | type: str | None = None, 12 | url: str | None = None, 13 | callback_id: str | None = None, 14 | state: str | None = None, 15 | user_id: str | None = None, 16 | channel_id: str | None = None, 17 | team_id: str | None = None, 18 | submission: dict[str, Any] | None = None, 19 | cancelled: bool | None = None, 20 | ): 21 | """Create a new playbook run from dialog 22 | 23 | type: 24 | url: 25 | callback_id: Callback ID provided by the integration. 26 | state: Stringified JSON with the post_id and the client_id. 27 | user_id: ID of the user who submitted the dialog. 28 | channel_id: ID of the channel the user was in when submitting the dialog. 29 | team_id: ID of the team the user was on when submitting the dialog. 30 | submission: Map of the dialog fields to their values 31 | cancelled: If the dialog was cancelled. 32 | 33 | `Read in Mattermost API docs (internal - createPlaybookRunFromDialog) `_ 34 | 35 | """ 36 | __options = { 37 | "type": type, 38 | "url": url, 39 | "callback_id": callback_id, 40 | "state": state, 41 | "user_id": user_id, 42 | "channel_id": channel_id, 43 | "team_id": team_id, 44 | "submission": submission, 45 | "cancelled": cancelled, 46 | } 47 | return self.client.post("""/plugins/playbooks/api/v0/runs/dialog""", options=__options) 48 | 49 | def get_checklist_autocomplete(self, channel_ID: str): 50 | """Get autocomplete data for /playbook check 51 | 52 | channel_ID: ID of the channel the user is in. 53 | 54 | `Read in Mattermost API docs (internal - getChecklistAutocomplete) `_ 55 | 56 | """ 57 | __params = {"channel_ID": channel_ID} 58 | return self.client.get("""/plugins/playbooks/api/v0/runs/checklist-autocomplete""", params=__params) 59 | 60 | def end_playbook_run_dialog(self, id: str): 61 | """End a playbook run from dialog 62 | 63 | id: ID of the playbook run to end. 64 | 65 | `Read in Mattermost API docs (internal - endPlaybookRunDialog) `_ 66 | 67 | """ 68 | return self.client.post(f"/plugins/playbooks/api/v0/runs/{id}/end") 69 | 70 | def next_stage_dialog(self, id: str, state: str | None = None): 71 | """Go to next stage from dialog 72 | 73 | id: The PlaybookRun ID 74 | state: String representation of the zero-based index of the stage to go to. 75 | 76 | `Read in Mattermost API docs (internal - nextStageDialog) `_ 77 | 78 | """ 79 | __options = {"state": state} 80 | return self.client.post(f"/plugins/playbooks/api/v0/runs/{id}/next-stage-dialog", options=__options) 81 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/schemes.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Schemes"] 4 | 5 | 6 | class Schemes(Base): 7 | 8 | def get_schemes(self, params=None): 9 | """Get the schemes. 10 | 11 | scope: Limit the results returned to the provided scope, either ``team`` or ``channel``. 12 | page: The page to select. 13 | per_page: The number of schemes per page. 14 | 15 | `Read in Mattermost API docs (schemes - GetSchemes) `_ 16 | 17 | """ 18 | return self.client.get("""/api/v4/schemes""", params=params) 19 | 20 | def create_scheme(self, options): 21 | """Create a scheme 22 | 23 | name: The name of the scheme 24 | display_name: The display name of the scheme 25 | description: The description of the scheme 26 | scope: The scope of the scheme ("team" or "channel") 27 | 28 | `Read in Mattermost API docs (schemes - CreateScheme) `_ 29 | 30 | """ 31 | return self.client.post("""/api/v4/schemes""", options=options) 32 | 33 | def get_scheme(self, scheme_id): 34 | """Get a scheme 35 | 36 | scheme_id: Scheme GUID 37 | 38 | `Read in Mattermost API docs (schemes - GetScheme) `_ 39 | 40 | """ 41 | return self.client.get(f"/api/v4/schemes/{scheme_id}") 42 | 43 | def delete_scheme(self, scheme_id): 44 | """Delete a scheme 45 | 46 | scheme_id: ID of the scheme to delete 47 | 48 | `Read in Mattermost API docs (schemes - DeleteScheme) `_ 49 | 50 | """ 51 | return self.client.delete(f"/api/v4/schemes/{scheme_id}") 52 | 53 | def patch_scheme(self, scheme_id, options): 54 | """Patch a scheme 55 | 56 | scheme_id: Scheme GUID 57 | name: The human readable name of the scheme 58 | description: The description of the scheme 59 | 60 | `Read in Mattermost API docs (schemes - PatchScheme) `_ 61 | 62 | """ 63 | return self.client.put(f"/api/v4/schemes/{scheme_id}/patch", options=options) 64 | 65 | def get_teams_for_scheme(self, scheme_id, params=None): 66 | """Get a page of teams which use this scheme. 67 | 68 | scheme_id: Scheme GUID 69 | page: The page to select. 70 | per_page: The number of teams per page. 71 | 72 | `Read in Mattermost API docs (schemes - GetTeamsForScheme) `_ 73 | 74 | """ 75 | return self.client.get(f"/api/v4/schemes/{scheme_id}/teams", params=params) 76 | 77 | def get_channels_for_scheme(self, scheme_id, params=None): 78 | """Get a page of channels which use this scheme. 79 | 80 | scheme_id: Scheme GUID 81 | page: The page to select. 82 | per_page: The number of channels per page. 83 | 84 | `Read in Mattermost API docs (schemes - GetChannelsForScheme) `_ 85 | 86 | """ 87 | return self.client.get(f"/api/v4/schemes/{scheme_id}/channels", params=params) 88 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/reports.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Reports"] 4 | 5 | 6 | class Reports(Base): 7 | 8 | def get_users_for_reporting(self, params=None): 9 | """Get a list of paged and sorted users for admin reporting purposes 10 | 11 | sort_column: The column to sort the users by. Must be one of ("CreateAt", "Username", "FirstName", "LastName", "Nickname", "Email") or the API will return an error. 12 | direction: The direction to accept paging values from. Will return values ahead of the cursor if "prev", and below the cursor if "next". Default is "next". 13 | sort_direction: The sorting direction. Must be one of ("asc", "desc"). Will default to 'asc' if not specified or the input is invalid. 14 | page_size: The maximum number of users to return. 15 | from_column_value: The value of the sorted column corresponding to the cursor to read from. Should be blank for the first page asked for. 16 | from_id: The value of the user id corresponding to the cursor to read from. Should be blank for the first page asked for. 17 | date_range: The date range of the post statistics to display. Must be one of ("last30days", "previousmonth", "last6months", "alltime"). Will default to 'alltime' if the input is not valid. 18 | role_filter: Filter users by their role. 19 | team_filter: Filter users by a specified team ID. 20 | has_no_team: If true, show only users that have no team. Will ignore provided "team_filter" if true. 21 | hide_active: If true, show only users that are inactive. Cannot be used at the same time as "hide_inactive" 22 | hide_inactive: If true, show only users that are active. Cannot be used at the same time as "hide_active" 23 | search_term: A filtering search term that allows filtering by Username, FirstName, LastName, Nickname or Email 24 | 25 | `Read in Mattermost API docs (reports - GetUsersForReporting) `_ 26 | 27 | """ 28 | return self.client.get("""/api/v4/reports/users""", params=params) 29 | 30 | def get_user_count_for_reporting(self, params=None): 31 | """Gets the full count of users that match the filter. 32 | 33 | role_filter: Filter users by their role. 34 | team_filter: Filter users by a specified team ID. 35 | has_no_team: If true, show only users that have no team. Will ignore provided "team_filter" if true. 36 | hide_active: If true, show only users that are inactive. Cannot be used at the same time as "hide_inactive" 37 | hide_inactive: If true, show only users that are active. Cannot be used at the same time as "hide_active" 38 | search_term: A filtering search term that allows filtering by Username, FirstName, LastName, Nickname or Email 39 | 40 | `Read in Mattermost API docs (reports - GetUserCountForReporting) `_ 41 | 42 | """ 43 | return self.client.get("""/api/v4/reports/users/count""", params=params) 44 | 45 | def start_batch_users_export(self): 46 | """Starts a job to export the users to a report file. 47 | `Read in Mattermost API docs (reports - StartBatchUsersExport) `_ 48 | 49 | """ 50 | return self.client.post("""/api/v4/reports/users/export""") 51 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/search.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Search"] 5 | 6 | 7 | class Search(Base): 8 | 9 | def search_files( 10 | self, 11 | team_id: str, 12 | terms: str, 13 | is_or_search: bool, 14 | time_zone_offset: int | None = 0, 15 | include_deleted_channels: bool | None = None, 16 | page: int | None = 0, 17 | per_page: int | None = 60, 18 | ): 19 | """Search files in a team 20 | 21 | team_id: Team GUID 22 | terms: The search terms as inputed by the user. To search for files from a user include ``from:someusername``, using a user's username. To search in a specific channel include ``in:somechannel``, using the channel name (not the display name). To search for specific extensions include ``ext:extension``. 23 | is_or_search: Set to true if an Or search should be performed vs an And search. 24 | time_zone_offset: Offset from UTC of user timezone for date searches. 25 | include_deleted_channels: Set to true if deleted channels should be included in the search. (archived channels) 26 | page: The page to select. (Only works with Elasticsearch) 27 | per_page: The number of posts per page. (Only works with Elasticsearch) 28 | 29 | `Read in Mattermost API docs (search - SearchFiles) `_ 30 | 31 | """ 32 | __data = { 33 | "terms": terms, 34 | "is_or_search": is_or_search, 35 | "time_zone_offset": time_zone_offset, 36 | "include_deleted_channels": include_deleted_channels, 37 | "page": page, 38 | "per_page": per_page, 39 | } 40 | return self.client.post(f"/api/v4/teams/{team_id}/files/search", data=__data) 41 | 42 | def search_files( 43 | self, 44 | terms: str, 45 | is_or_search: bool, 46 | time_zone_offset: int | None = 0, 47 | include_deleted_channels: bool | None = None, 48 | page: int | None = 0, 49 | per_page: int | None = 60, 50 | ): 51 | """Search files across the teams of the current user 52 | 53 | terms: The search terms as entered by the user. To search for files from a user include ``from:someusername``, using a user's username. To search in a specific channel include ``in:somechannel``, using the channel name (not the display name). To search for specific extensions include ``ext:extension``. 54 | is_or_search: Set to true if an Or search should be performed vs an And search. 55 | time_zone_offset: Offset from UTC of user timezone for date searches. 56 | include_deleted_channels: Set to true if deleted channels should be included in the search. (archived channels) 57 | page: The page to select. (Only works with Elasticsearch) 58 | per_page: The number of posts per page. (Only works with Elasticsearch) 59 | 60 | `Read in Mattermost API docs (search - SearchFiles) `_ 61 | 62 | """ 63 | __data = { 64 | "terms": terms, 65 | "is_or_search": is_or_search, 66 | "time_zone_offset": time_zone_offset, 67 | "include_deleted_channels": include_deleted_channels, 68 | "page": page, 69 | "per_page": per_page, 70 | } 71 | return self.client.post("""/api/v4/files/search""", data=__data) 72 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/integration_actions.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["IntegrationActions"] 5 | 6 | 7 | class IntegrationActions(Base): 8 | 9 | def open_interactive_dialog(self, trigger_id: str, url: str, dialog: dict[str, Any]): 10 | """Open a dialog 11 | 12 | trigger_id: Trigger ID provided by other action 13 | url: The URL to send the submitted dialog payload to 14 | dialog: Post object to create 15 | 16 | `Read in Mattermost API docs (integration_actions - OpenInteractiveDialog) `_ 17 | 18 | """ 19 | __options = {"trigger_id": trigger_id, "url": url, "dialog": dialog} 20 | return self.client.post("""/api/v4/actions/dialogs/open""", options=__options) 21 | 22 | def submit_interactive_dialog( 23 | self, 24 | url: str, 25 | channel_id: str, 26 | team_id: str, 27 | submission: dict[str, Any], 28 | callback_id: str | None = None, 29 | state: str | None = None, 30 | cancelled: bool | None = None, 31 | ): 32 | """Submit a dialog 33 | 34 | url: The URL to send the submitted dialog payload to 35 | channel_id: Channel ID the user submitted the dialog from 36 | team_id: Team ID the user submitted the dialog from 37 | submission: String map where keys are element names and values are the element input values 38 | callback_id: Callback ID sent when the dialog was opened 39 | state: State sent when the dialog was opened 40 | cancelled: Set to true if the dialog was cancelled 41 | 42 | `Read in Mattermost API docs (integration_actions - SubmitInteractiveDialog) `_ 43 | 44 | """ 45 | __options = { 46 | "url": url, 47 | "channel_id": channel_id, 48 | "team_id": team_id, 49 | "submission": submission, 50 | "callback_id": callback_id, 51 | "state": state, 52 | "cancelled": cancelled, 53 | } 54 | return self.client.post("""/api/v4/actions/dialogs/submit""", options=__options) 55 | 56 | def lookup_interactive_dialog( 57 | self, 58 | url: str, 59 | channel_id: str, 60 | team_id: str, 61 | submission: dict[str, Any], 62 | callback_id: str | None = None, 63 | state: str | None = None, 64 | ): 65 | """Lookup dialog elements 66 | 67 | url: The URL to send the lookup request to 68 | channel_id: Channel ID the user is performing the lookup from 69 | team_id: Team ID the user is performing the lookup from 70 | submission: String map where keys are element names and values are the element input values 71 | callback_id: Callback ID sent when the dialog was opened 72 | state: State sent when the dialog was opened 73 | 74 | `Read in Mattermost API docs (integration_actions - LookupInteractiveDialog) `_ 75 | 76 | """ 77 | __options = { 78 | "url": url, 79 | "channel_id": channel_id, 80 | "team_id": team_id, 81 | "submission": submission, 82 | "callback_id": callback_id, 83 | "state": state, 84 | } 85 | return self.client.post("""/api/v4/actions/dialogs/lookup""", options=__options) 86 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/jobs.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Jobs"] 5 | 6 | 7 | class Jobs(Base): 8 | 9 | def get_jobs( 10 | self, page: int | None = 0, per_page: int | None = 5, job_type: str | None = None, status: str | None = None 11 | ): 12 | """Get the jobs. 13 | 14 | page: The page to select. 15 | per_page: The number of jobs per page. 16 | job_type: The type of jobs to fetch. 17 | status: The status of jobs to fetch. 18 | 19 | `Read in Mattermost API docs (jobs - GetJobs) `_ 20 | 21 | """ 22 | __params = {"page": page, "per_page": per_page, "job_type": job_type, "status": status} 23 | return self.client.get("""/api/v4/jobs""", params=__params) 24 | 25 | def create_job(self, type: str, data: dict[str, Any] | None = None): 26 | """Create a new job. 27 | 28 | type: The type of job to create 29 | data: An object containing any additional data required for this job type 30 | 31 | `Read in Mattermost API docs (jobs - CreateJob) `_ 32 | 33 | """ 34 | __options = {"type": type, "data": data} 35 | return self.client.post("""/api/v4/jobs""", options=__options) 36 | 37 | def get_job(self, job_id: str): 38 | """Get a job. 39 | 40 | job_id: Job GUID 41 | 42 | `Read in Mattermost API docs (jobs - GetJob) `_ 43 | 44 | """ 45 | return self.client.get(f"/api/v4/jobs/{job_id}") 46 | 47 | def download_job(self, job_id: str): 48 | """Download the results of a job. 49 | 50 | job_id: Job GUID 51 | 52 | `Read in Mattermost API docs (jobs - DownloadJob) `_ 53 | 54 | """ 55 | return self.client.get(f"/api/v4/jobs/{job_id}/download") 56 | 57 | def cancel_job(self, job_id: str): 58 | """Cancel a job. 59 | 60 | job_id: Job GUID 61 | 62 | `Read in Mattermost API docs (jobs - CancelJob) `_ 63 | 64 | """ 65 | return self.client.post(f"/api/v4/jobs/{job_id}/cancel") 66 | 67 | def get_jobs_by_type(self, type: str, page: int | None = 0, per_page: int | None = 60): 68 | """Get the jobs of the given type. 69 | 70 | type: Job type 71 | page: The page to select. 72 | per_page: The number of jobs per page. 73 | 74 | `Read in Mattermost API docs (jobs - GetJobsByType) `_ 75 | 76 | """ 77 | __params = {"page": page, "per_page": per_page} 78 | return self.client.get(f"/api/v4/jobs/type/{type}", params=__params) 79 | 80 | def update_job_status(self, job_id: str, status: str, force: bool | None = None): 81 | """Update the status of a job 82 | 83 | job_id: Job GUID 84 | status: The status you want to set 85 | force: Set this to true to bypass status restrictions 86 | 87 | `Read in Mattermost API docs (jobs - UpdateJobStatus) `_ 88 | 89 | """ 90 | __options = {"status": status, "force": force} 91 | return self.client.patch(f"/api/v4/jobs/{job_id}/status", options=__options) 92 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/custom_profile_attributes.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["CustomProfileAttributes"] 4 | 5 | 6 | class CustomProfileAttributes(Base): 7 | 8 | def list_all_cpa_fields(self): 9 | """List all the Custom Profile Attributes fields 10 | `Read in Mattermost API docs (custom_profile_attributes - ListAllCPAFields) `_ 11 | 12 | """ 13 | return self.client.get("""/api/v4/custom_profile_attributes/fields""") 14 | 15 | def create_cpa_field(self, options=None): 16 | """Create a Custom Profile Attribute field 17 | 18 | name: 19 | type: 20 | attrs: 21 | 22 | `Read in Mattermost API docs (custom_profile_attributes - CreateCPAField) `_ 23 | 24 | """ 25 | return self.client.post("""/api/v4/custom_profile_attributes/fields""", options=options) 26 | 27 | def patch_cpa_field(self, field_id, options): 28 | """Patch a Custom Profile Attribute field 29 | 30 | field_id: Custom Profile Attribute field GUID 31 | name: 32 | type: 33 | attrs: 34 | 35 | `Read in Mattermost API docs (custom_profile_attributes - PatchCPAField) `_ 36 | 37 | """ 38 | return self.client.patch(f"/api/v4/custom_profile_attributes/fields/{field_id}", options=options) 39 | 40 | def delete_cpa_field(self, field_id): 41 | """Delete a Custom Profile Attribute field 42 | 43 | field_id: Custom Profile Attribute field GUID 44 | 45 | `Read in Mattermost API docs (custom_profile_attributes - DeleteCPAField) `_ 46 | 47 | """ 48 | return self.client.delete(f"/api/v4/custom_profile_attributes/fields/{field_id}") 49 | 50 | def patch_cpa_values(self, options): 51 | """Patch Custom Profile Attribute values 52 | `Read in Mattermost API docs (custom_profile_attributes - PatchCPAValues) `_ 53 | 54 | """ 55 | return self.client.patch("""/api/v4/custom_profile_attributes/values""", options=options) 56 | 57 | def get_cpa_group(self): 58 | """Get Custom Profile Attribute property group data 59 | `Read in Mattermost API docs (custom_profile_attributes - GetCPAGroup) `_ 60 | 61 | """ 62 | return self.client.get("""/api/v4/custom_profile_attributes/group""") 63 | 64 | def list_cpa_values(self, user_id): 65 | """List Custom Profile Attribute values 66 | 67 | user_id: User GUID 68 | 69 | `Read in Mattermost API docs (custom_profile_attributes - ListCPAValues) `_ 70 | 71 | """ 72 | return self.client.get(f"/api/v4/users/{user_id}/custom_profile_attributes") 73 | 74 | def patch_cpa_values_for_user(self, user_id, options): 75 | """Update custom profile attribute values for a user 76 | 77 | user_id: User GUID 78 | 79 | `Read in Mattermost API docs (custom_profile_attributes - PatchCPAValuesForUser) `_ 80 | 81 | """ 82 | return self.client.patch(f"/api/v4/users/{user_id}/custom_profile_attributes", options=options) 83 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/scheduled_post.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["ScheduledPost"] 5 | 6 | 7 | class ScheduledPost(Base): 8 | 9 | def create_scheduled_post( 10 | self, 11 | scheduled_at: int, 12 | channel_id: str, 13 | message: str, 14 | root_id: str | None = None, 15 | file_ids: list[Any] | None = None, 16 | props: dict[str, Any] | None = None, 17 | ): 18 | """Creates a scheduled post 19 | 20 | scheduled_at: UNIX timestamp in milliseconds of the time when the scheduled post should be sent 21 | channel_id: The channel ID to post in 22 | message: The message contents, can be formatted with Markdown 23 | root_id: The post ID to comment on 24 | file_ids: A list of file IDs to associate with the post. Note that posts are limited to 5 files maximum. Please use additional posts for more files. 25 | props: A general JSON property bag to attach to the post 26 | 27 | `Read in Mattermost API docs (scheduled_post - CreateScheduledPost) `_ 28 | 29 | """ 30 | __options = { 31 | "scheduled_at": scheduled_at, 32 | "channel_id": channel_id, 33 | "message": message, 34 | "root_id": root_id, 35 | "file_ids": file_ids, 36 | "props": props, 37 | } 38 | return self.client.post("""/api/v4/posts/schedule""", options=__options) 39 | 40 | def get_user_scheduled_posts(self, includeDirectChannels: bool | None = False): 41 | """Gets all scheduled posts for a user for the specified team.. 42 | 43 | includeDirectChannels: Whether to include scheduled posts from DMs an GMs or not. Default is false 44 | 45 | `Read in Mattermost API docs (scheduled_post - GetUserScheduledPosts) `_ 46 | 47 | """ 48 | __params = {"includeDirectChannels": includeDirectChannels} 49 | return self.client.get(f"/api/v4/posts/scheduled/team/{team_id}", params=__params) 50 | 51 | def update_scheduled_post( 52 | self, scheduled_post_id: str, id: str, channel_id: str, user_id: str, scheduled_at: int, message: str 53 | ): 54 | """Update a scheduled post 55 | 56 | scheduled_post_id: ID of the scheduled post to update 57 | id: ID of the scheduled post to update 58 | channel_id: The channel ID to post in 59 | user_id: The current user ID 60 | scheduled_at: UNIX timestamp in milliseconds of the time when the scheduled post should be sent 61 | message: The message contents, can be formatted with Markdown 62 | 63 | `Read in Mattermost API docs (scheduled_post - UpdateScheduledPost) `_ 64 | 65 | """ 66 | __options = { 67 | "id": id, 68 | "channel_id": channel_id, 69 | "user_id": user_id, 70 | "scheduled_at": scheduled_at, 71 | "message": message, 72 | } 73 | return self.client.put(f"/api/v4/posts/schedule/{scheduled_post_id}", options=__options) 74 | 75 | def delete_scheduled_post(self, scheduled_post_id: str): 76 | """Delete a scheduled post 77 | 78 | scheduled_post_id: ID of the scheduled post to delete 79 | 80 | `Read in Mattermost API docs (scheduled_post - DeleteScheduledPost) `_ 81 | 82 | """ 83 | return self.client.delete(f"/api/v4/posts/schedule/{scheduled_post_id}") 84 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/emoji.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Emoji"] 4 | 5 | 6 | class Emoji(Base): 7 | 8 | def create_emoji(self, files, data=None): 9 | """Create a custom emoji 10 | 11 | image: A file to be uploaded 12 | emoji: A JSON object containing a ``name`` field with the name of the emoji and a ``creator_id`` field with the id of the authenticated user. 13 | 14 | `Read in Mattermost API docs (emoji - CreateEmoji) `_ 15 | 16 | """ 17 | return self.client.post("""/api/v4/emoji""", files=files, data=data) 18 | 19 | def get_emoji_list(self, params=None): 20 | """Get a list of custom emoji 21 | 22 | page: The page to select. 23 | per_page: The number of emojis per page. 24 | sort: Either blank for no sorting or "name" to sort by emoji names. Minimum server version for sorting is 4.7. 25 | 26 | `Read in Mattermost API docs (emoji - GetEmojiList) `_ 27 | 28 | """ 29 | return self.client.get("""/api/v4/emoji""", params=params) 30 | 31 | def get_emoji(self, emoji_id): 32 | """Get a custom emoji 33 | 34 | emoji_id: Emoji GUID 35 | 36 | `Read in Mattermost API docs (emoji - GetEmoji) `_ 37 | 38 | """ 39 | return self.client.get(f"/api/v4/emoji/{emoji_id}") 40 | 41 | def delete_emoji(self, emoji_id): 42 | """Delete a custom emoji 43 | 44 | emoji_id: Emoji GUID 45 | 46 | `Read in Mattermost API docs (emoji - DeleteEmoji) `_ 47 | 48 | """ 49 | return self.client.delete(f"/api/v4/emoji/{emoji_id}") 50 | 51 | def get_emoji_by_name(self, emoji_name): 52 | """Get a custom emoji by name 53 | 54 | emoji_name: Emoji name 55 | 56 | `Read in Mattermost API docs (emoji - GetEmojiByName) `_ 57 | 58 | """ 59 | return self.client.get(f"/api/v4/emoji/name/{emoji_name}") 60 | 61 | def get_emoji_image(self, emoji_id): 62 | """Get custom emoji image 63 | 64 | emoji_id: Emoji GUID 65 | 66 | `Read in Mattermost API docs (emoji - GetEmojiImage) `_ 67 | 68 | """ 69 | return self.client.get(f"/api/v4/emoji/{emoji_id}/image") 70 | 71 | def search_emoji(self, options): 72 | """Search custom emoji 73 | 74 | term: The term to match against the emoji name. 75 | prefix_only: Set to only search for names starting with the search term. 76 | 77 | `Read in Mattermost API docs (emoji - SearchEmoji) `_ 78 | 79 | """ 80 | return self.client.post("""/api/v4/emoji/search""", options=options) 81 | 82 | def autocomplete_emoji(self, params=None): 83 | """Autocomplete custom emoji 84 | 85 | name: The emoji name to search. 86 | 87 | `Read in Mattermost API docs (emoji - AutocompleteEmoji) `_ 88 | 89 | """ 90 | return self.client.get("""/api/v4/emoji/autocomplete""", params=params) 91 | 92 | def get_emojis_by_names(self, options): 93 | """Get custom emojis by name 94 | `Read in Mattermost API docs (emoji - GetEmojisByNames) `_ 95 | 96 | """ 97 | return self.client.post("""/api/v4/emoji/names""", options=options) 98 | -------------------------------------------------------------------------------- /docs/mmDriverTokenAuthExample.py: -------------------------------------------------------------------------------- 1 | 2 | # A simple example to retrieve all users for a team while using a _token_ 3 | # from the .netrc file instead of a password (as requests assumes by default) 4 | 5 | import logging 6 | import requests 7 | import netrc 8 | 9 | from mattermostautodriver import TypedDriver 10 | 11 | logging.basicConfig( format='%(levelname)s - %(name)s - %(asctime)s - %(message)s' ) 12 | logger = logging.getLogger( 'MattermostManager' ) 13 | logger.setLevel( logging.INFO ) 14 | 15 | # requests overrides the simple authentication token header if it finds the entry in 16 | # the ~/.netrc file. Since we want to use ~/.netrc to retrieve the _token_, we need 17 | # to provide our own Authenticator class: 18 | 19 | class TokenAuth( requests.auth.AuthBase ) : 20 | def __call__( self, r ) : 21 | # Implement my authentication 22 | mmHost = 'mattermost.host.in.netrc' 23 | (login, account, password) = netrc.netrc().authenticators( mmHost ) 24 | r.headers[ 'Authorization' ] = "Bearer %s" % password 25 | return r 26 | 27 | 28 | class MattermostManager( object ) : 29 | 30 | def __init__( self ) : 31 | 32 | # Get the _token_ (as "password") from the ~/.netrc file. 33 | # the corresponding line in the file should look like: 34 | # foo foo 35 | # The "login" and "account" (both set to "foo" in the example are ignored) 36 | 37 | mmHost = 'mattermost.host.in.netrc' 38 | (login, account, password) = netrc.netrc().authenticators( mmHost ) 39 | logger.debug( "Going to set up driver for connection to %s " % (mmHost,) ) 40 | 41 | self.mmDriver = TypedDriver( options={ 42 | 'url' : mmHost, 43 | 'scheme' : 'https', 44 | 'port' : 443, 45 | 'auth' : TokenAuth, # use the new Authenticator class defined above 46 | } ) 47 | 48 | self.mmDriver.users.get_user( user_id='me' ) 49 | 50 | def getTeamMembers( self, teamName ) : 51 | 52 | # for restricted teams, we need to get the ID first, and 53 | # for this, we need to have the "name" (as in the URL), not 54 | # the "display name", as shown in the GUIs: 55 | 56 | team0 = self.mmDriver.teams.get_team_by_name( teamName ) 57 | logger.debug( 'team by name %s : %s' % (teamName, team0) ) 58 | teamId = team0[ 'id' ] 59 | 60 | team = self.mmDriver.teams.check_team_exists( teamName ) 61 | logger.debug( 'team %s - exists: %s' % (teamName, team[ 'exists' ]) ) 62 | if not team[ 'exists' ] : 63 | logger.error( 'no team with name %s found' % teamName ) 64 | return 65 | 66 | logger.debug( 'found team %s: %s' % (teamName, self.mmDriver.teams.get_team( teamId )) ) 67 | 68 | users = self._getAllUsersForTeam( teamId ) 69 | logger.debug( 'found %s users for team "%s"' % (len( users ), teamName) ) 70 | 71 | return users 72 | 73 | def _getAllUsersForTeam( self, teamId ) : 74 | 75 | # get all users for a team 76 | # with the max of 200 per page, we need to iterate a bit over the pages 77 | 78 | users = [ ] 79 | pgNo = 0 80 | teamUsers = self.mmDriver.users.get_users(in_team= teamId, 81 | page= pgNo, 82 | per_page = 200, 83 | ) 84 | while teamUsers : 85 | users += teamUsers 86 | pgNo += 1 87 | teamUsers = self.mmDriver.users.get_users(in_team=teamId, 88 | per_page=200, 89 | page=pgNo, 90 | ) 91 | return users 92 | 93 | if __name__ == '__main__' : 94 | mmM = MattermostManager() 95 | mmM.getTeamMembers( 'myTeam' ) 96 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/custom_profile_attributes.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["CustomProfileAttributes"] 5 | 6 | 7 | class CustomProfileAttributes(Base): 8 | 9 | def list_all_cpa_fields(self): 10 | """List all the Custom Profile Attributes fields 11 | `Read in Mattermost API docs (custom_profile_attributes - ListAllCPAFields) `_ 12 | 13 | """ 14 | return self.client.get("""/api/v4/custom_profile_attributes/fields""") 15 | 16 | def create_cpa_field(self, name: str, type: str, attrs: dict[str, Any] | None = None): 17 | """Create a Custom Profile Attribute field 18 | 19 | name: 20 | type: 21 | attrs: 22 | 23 | `Read in Mattermost API docs (custom_profile_attributes - CreateCPAField) `_ 24 | 25 | """ 26 | __options = {"name": name, "type": type, "attrs": attrs} 27 | return self.client.post("""/api/v4/custom_profile_attributes/fields""", options=__options) 28 | 29 | def patch_cpa_field( 30 | self, field_id: str, name: str | None = None, type: str | None = None, attrs: dict[str, Any] | None = None 31 | ): 32 | """Patch a Custom Profile Attribute field 33 | 34 | field_id: Custom Profile Attribute field GUID 35 | name: 36 | type: 37 | attrs: 38 | 39 | `Read in Mattermost API docs (custom_profile_attributes - PatchCPAField) `_ 40 | 41 | """ 42 | __options = {"name": name, "type": type, "attrs": attrs} 43 | return self.client.patch(f"/api/v4/custom_profile_attributes/fields/{field_id}", options=__options) 44 | 45 | def delete_cpa_field(self, field_id: str): 46 | """Delete a Custom Profile Attribute field 47 | 48 | field_id: Custom Profile Attribute field GUID 49 | 50 | `Read in Mattermost API docs (custom_profile_attributes - DeleteCPAField) `_ 51 | 52 | """ 53 | return self.client.delete(f"/api/v4/custom_profile_attributes/fields/{field_id}") 54 | 55 | def patch_cpa_values(self, options: list[dict[str, Any]]): 56 | """Patch Custom Profile Attribute values 57 | `Read in Mattermost API docs (custom_profile_attributes - PatchCPAValues) `_ 58 | 59 | """ 60 | return self.client.patch("""/api/v4/custom_profile_attributes/values""", options=options) 61 | 62 | def get_cpa_group(self): 63 | """Get Custom Profile Attribute property group data 64 | `Read in Mattermost API docs (custom_profile_attributes - GetCPAGroup) `_ 65 | 66 | """ 67 | return self.client.get("""/api/v4/custom_profile_attributes/group""") 68 | 69 | def list_cpa_values(self, user_id: str): 70 | """List Custom Profile Attribute values 71 | 72 | user_id: User GUID 73 | 74 | `Read in Mattermost API docs (custom_profile_attributes - ListCPAValues) `_ 75 | 76 | """ 77 | return self.client.get(f"/api/v4/users/{user_id}/custom_profile_attributes") 78 | 79 | def patch_cpa_values_for_user(self, user_id: str, options: list[dict[str, Any]]): 80 | """Update custom profile attribute values for a user 81 | 82 | user_id: User GUID 83 | 84 | `Read in Mattermost API docs (custom_profile_attributes - PatchCPAValuesForUser) `_ 85 | 86 | """ 87 | return self.client.patch(f"/api/v4/users/{user_id}/custom_profile_attributes", options=options) 88 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/bookmarks.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Bookmarks"] 4 | 5 | 6 | class Bookmarks(Base): 7 | 8 | def list_channel_bookmarks_for_channel(self, channel_id, params=None): 9 | """Get channel bookmarks for Channel 10 | 11 | channel_id: Channel GUID 12 | bookmarks_since: Timestamp to filter the bookmarks with. If set, the 13 | endpoint returns bookmarks that have been added, updated 14 | or deleted since its value 15 | 16 | 17 | `Read in Mattermost API docs (bookmarks - ListChannelBookmarksForChannel) `_ 18 | 19 | """ 20 | return self.client.get(f"/api/v4/channels/{channel_id}/bookmarks", params=params) 21 | 22 | def create_channel_bookmark(self, channel_id, options): 23 | """Create channel bookmark 24 | 25 | channel_id: Channel GUID 26 | file_id: The ID of the file associated with the channel bookmark. Required for bookmarks of type 'file' 27 | display_name: The name of the channel bookmark 28 | link_url: The URL associated with the channel bookmark. Required for bookmarks of type 'link' 29 | image_url: The URL of the image associated with the channel bookmark. Optional, only applies for bookmarks of type 'link' 30 | emoji: The emoji of the channel bookmark 31 | type: * ``link`` for channel bookmarks that reference a link. ``link_url`` is requied 32 | * ``file`` for channel bookmarks that reference a file. ``file_id`` is required 33 | 34 | 35 | `Read in Mattermost API docs (bookmarks - CreateChannelBookmark) `_ 36 | 37 | """ 38 | return self.client.post(f"/api/v4/channels/{channel_id}/bookmarks", options=options) 39 | 40 | def update_channel_bookmark(self, channel_id, bookmark_id, options): 41 | """Update channel bookmark 42 | 43 | channel_id: Channel GUID 44 | bookmark_id: Bookmark GUID 45 | file_id: The ID of the file associated with the channel bookmark. Required for bookmarks of type 'file' 46 | display_name: The name of the channel bookmark 47 | sort_order: The order of the channel bookmark 48 | link_url: The URL associated with the channel bookmark. Required for type bookmarks of type 'link' 49 | image_url: The URL of the image associated with the channel bookmark 50 | emoji: The emoji of the channel bookmark 51 | type: * ``link`` for channel bookmarks that reference a link. ``link_url`` is requied 52 | * ``file`` for channel bookmarks that reference a file. ``file_id`` is required 53 | 54 | 55 | `Read in Mattermost API docs (bookmarks - UpdateChannelBookmark) `_ 56 | 57 | """ 58 | return self.client.patch(f"/api/v4/channels/{channel_id}/bookmarks/{bookmark_id}", options=options) 59 | 60 | def delete_channel_bookmark(self, channel_id, bookmark_id): 61 | """Delete channel bookmark 62 | 63 | channel_id: Channel GUID 64 | bookmark_id: Bookmark GUID 65 | 66 | `Read in Mattermost API docs (bookmarks - DeleteChannelBookmark) `_ 67 | 68 | """ 69 | return self.client.delete(f"/api/v4/channels/{channel_id}/bookmarks/{bookmark_id}") 70 | 71 | def update_channel_bookmark_sort_order(self, channel_id, bookmark_id, options=None): 72 | """Update channel bookmark's order 73 | 74 | channel_id: Channel GUID 75 | bookmark_id: Bookmark GUID 76 | 77 | `Read in Mattermost API docs (bookmarks - UpdateChannelBookmarkSortOrder) `_ 78 | 79 | """ 80 | return self.client.post(f"/api/v4/channels/{channel_id}/bookmarks/{bookmark_id}/sort_order", options=options) 81 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/status.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Status"] 4 | 5 | 6 | class Status(Base): 7 | 8 | def get_user_status(self, user_id): 9 | """Get user status 10 | 11 | user_id: User ID 12 | 13 | `Read in Mattermost API docs (status - GetUserStatus) `_ 14 | 15 | """ 16 | return self.client.get(f"/api/v4/users/{user_id}/status") 17 | 18 | def update_user_status(self, user_id, options): 19 | """Update user status 20 | 21 | user_id: User ID 22 | user_id: User ID 23 | status: User status, can be ``online``, ``away``, ``offline`` and ``dnd`` 24 | dnd_end_time: Time in epoch seconds at which a dnd status would be unset. 25 | 26 | `Read in Mattermost API docs (status - UpdateUserStatus) `_ 27 | 28 | """ 29 | return self.client.put(f"/api/v4/users/{user_id}/status", options=options) 30 | 31 | def get_users_statuses_by_ids(self, options): 32 | """Get user statuses by id 33 | `Read in Mattermost API docs (status - GetUsersStatusesByIds) `_ 34 | 35 | """ 36 | return self.client.post("""/api/v4/users/status/ids""", options=options) 37 | 38 | def update_user_custom_status(self, user_id, options): 39 | """Update user custom status 40 | 41 | user_id: User ID 42 | emoji: Any emoji 43 | text: Any custom status text 44 | duration: Duration of custom status, can be ``thirty_minutes``, ``one_hour``, ``four_hours``, ``today``, ``this_week`` or ``date_and_time`` 45 | expires_at: The time at which custom status should be expired. It should be in ISO format. 46 | 47 | `Read in Mattermost API docs (status - UpdateUserCustomStatus) `_ 48 | 49 | """ 50 | return self.client.put(f"/api/v4/users/{user_id}/status/custom", options=options) 51 | 52 | def unset_user_custom_status(self, user_id): 53 | """Unsets user custom status 54 | 55 | user_id: User ID 56 | 57 | `Read in Mattermost API docs (status - UnsetUserCustomStatus) `_ 58 | 59 | """ 60 | return self.client.delete(f"/api/v4/users/{user_id}/status/custom") 61 | 62 | def remove_recent_custom_status(self, user_id, params): 63 | """Delete user's recent custom status 64 | 65 | user_id: User ID 66 | emoji: Any emoji 67 | text: Any custom status text 68 | duration: Duration of custom status, can be ``thirty_minutes``, ``one_hour``, ``four_hours``, ``today``, ``this_week`` or ``date_and_time`` 69 | expires_at: The time at which custom status should be expired. It should be in ISO format. 70 | 71 | `Read in Mattermost API docs (status - RemoveRecentCustomStatus) `_ 72 | 73 | """ 74 | return self.client.delete(f"/api/v4/users/{user_id}/status/custom/recent", params=params) 75 | 76 | def post_user_recent_custom_status_delete(self, user_id, options): 77 | """Delete user's recent custom status 78 | 79 | user_id: User ID 80 | emoji: Any emoji 81 | text: Any custom status text 82 | duration: Duration of custom status, can be ``thirty_minutes``, ``one_hour``, ``four_hours``, ``today``, ``this_week`` or ``date_and_time`` 83 | expires_at: The time at which custom status should be expired. It should be in ISO format. 84 | 85 | `Read in Mattermost API docs (status - PostUserRecentCustomStatusDelete) `_ 86 | 87 | """ 88 | return self.client.post(f"/api/v4/users/{user_id}/status/custom/recent/delete", options=options) 89 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/schemes.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Schemes"] 5 | 6 | 7 | class Schemes(Base): 8 | 9 | def get_schemes(self, scope: str | None = "", page: int | None = 0, per_page: int | None = 60): 10 | """Get the schemes. 11 | 12 | scope: Limit the results returned to the provided scope, either ``team`` or ``channel``. 13 | page: The page to select. 14 | per_page: The number of schemes per page. 15 | 16 | `Read in Mattermost API docs (schemes - GetSchemes) `_ 17 | 18 | """ 19 | __params = {"scope": scope, "page": page, "per_page": per_page} 20 | return self.client.get("""/api/v4/schemes""", params=__params) 21 | 22 | def create_scheme(self, display_name: str, scope: str, name: str | None = None, description: str | None = None): 23 | """Create a scheme 24 | 25 | name: The name of the scheme 26 | display_name: The display name of the scheme 27 | description: The description of the scheme 28 | scope: The scope of the scheme ("team" or "channel") 29 | 30 | `Read in Mattermost API docs (schemes - CreateScheme) `_ 31 | 32 | """ 33 | __options = {"name": name, "display_name": display_name, "description": description, "scope": scope} 34 | return self.client.post("""/api/v4/schemes""", options=__options) 35 | 36 | def get_scheme(self, scheme_id: str): 37 | """Get a scheme 38 | 39 | scheme_id: Scheme GUID 40 | 41 | `Read in Mattermost API docs (schemes - GetScheme) `_ 42 | 43 | """ 44 | return self.client.get(f"/api/v4/schemes/{scheme_id}") 45 | 46 | def delete_scheme(self, scheme_id: str): 47 | """Delete a scheme 48 | 49 | scheme_id: ID of the scheme to delete 50 | 51 | `Read in Mattermost API docs (schemes - DeleteScheme) `_ 52 | 53 | """ 54 | return self.client.delete(f"/api/v4/schemes/{scheme_id}") 55 | 56 | def patch_scheme(self, scheme_id: str, name: str | None = None, description: str | None = None): 57 | """Patch a scheme 58 | 59 | scheme_id: Scheme GUID 60 | name: The human readable name of the scheme 61 | description: The description of the scheme 62 | 63 | `Read in Mattermost API docs (schemes - PatchScheme) `_ 64 | 65 | """ 66 | __options = {"name": name, "description": description} 67 | return self.client.put(f"/api/v4/schemes/{scheme_id}/patch", options=__options) 68 | 69 | def get_teams_for_scheme(self, scheme_id: str, page: int | None = 0, per_page: int | None = 60): 70 | """Get a page of teams which use this scheme. 71 | 72 | scheme_id: Scheme GUID 73 | page: The page to select. 74 | per_page: The number of teams per page. 75 | 76 | `Read in Mattermost API docs (schemes - GetTeamsForScheme) `_ 77 | 78 | """ 79 | __params = {"page": page, "per_page": per_page} 80 | return self.client.get(f"/api/v4/schemes/{scheme_id}/teams", params=__params) 81 | 82 | def get_channels_for_scheme(self, scheme_id: str, page: int | None = 0, per_page: int | None = 60): 83 | """Get a page of channels which use this scheme. 84 | 85 | scheme_id: Scheme GUID 86 | page: The page to select. 87 | per_page: The number of channels per page. 88 | 89 | `Read in Mattermost API docs (schemes - GetChannelsForScheme) `_ 90 | 91 | """ 92 | __params = {"page": page, "per_page": per_page} 93 | return self.client.get(f"/api/v4/schemes/{scheme_id}/channels", params=__params) 94 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/remote_clusters.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["RemoteClusters"] 4 | 5 | 6 | class RemoteClusters(Base): 7 | 8 | def get_remote_clusters(self, params=None): 9 | """Get a list of remote clusters. 10 | 11 | page: The page to select 12 | per_page: The number of remote clusters per page 13 | exclude_offline: Exclude offline remote clusters 14 | in_channel: Select remote clusters in channel 15 | not_in_channel: Select remote clusters not in this channel 16 | only_confirmed: Select only remote clusters already confirmed 17 | only_plugins: Select only remote clusters that belong to a plugin 18 | exclude_plugins: Select only remote clusters that don't belong to a plugin 19 | include_deleted: Include those remote clusters that have been deleted 20 | 21 | `Read in Mattermost API docs (remote_clusters - GetRemoteClusters) `_ 22 | 23 | """ 24 | return self.client.get("""/api/v4/remotecluster""", params=params) 25 | 26 | def create_remote_cluster(self, options=None): 27 | """Create a new remote cluster. 28 | 29 | name: 30 | display_name: 31 | default_team_id: 32 | password: The password to use in the invite code. If empty, 33 | the server will generate one and it will be part 34 | of the response 35 | 36 | 37 | `Read in Mattermost API docs (remote_clusters - CreateRemoteCluster) `_ 38 | 39 | """ 40 | return self.client.post("""/api/v4/remotecluster""", options=options) 41 | 42 | def get_remote_cluster(self, remote_id): 43 | """Get a remote cluster. 44 | 45 | remote_id: Remote Cluster GUID 46 | 47 | `Read in Mattermost API docs (remote_clusters - GetRemoteCluster) `_ 48 | 49 | """ 50 | return self.client.get(f"/api/v4/remotecluster/{remote_id}") 51 | 52 | def patch_remote_cluster(self, remote_id, options=None): 53 | """Patch a remote cluster. 54 | 55 | remote_id: Remote Cluster GUID 56 | display_name: 57 | default_team_id: The team where channels from invites are created 58 | 59 | `Read in Mattermost API docs (remote_clusters - PatchRemoteCluster) `_ 60 | 61 | """ 62 | return self.client.patch(f"/api/v4/remotecluster/{remote_id}", options=options) 63 | 64 | def delete_remote_cluster(self, remote_id): 65 | """Delete a remote cluster. 66 | 67 | remote_id: Remote Cluster GUID 68 | 69 | `Read in Mattermost API docs (remote_clusters - DeleteRemoteCluster) `_ 70 | 71 | """ 72 | return self.client.delete(f"/api/v4/remotecluster/{remote_id}") 73 | 74 | def generate_remote_cluster_invite(self, options=None): 75 | """Generate invite code. 76 | 77 | password: The password to encrypt the invite code with. 78 | 79 | `Read in Mattermost API docs (remote_clusters - GenerateRemoteClusterInvite) `_ 80 | 81 | """ 82 | return self.client.post(f"/api/v4/remotecluster/{remote_id}/generate_invite", options=options) 83 | 84 | def accept_remote_cluster_invite(self, options=None): 85 | """Accept a remote cluster invite code. 86 | 87 | invite: 88 | name: 89 | display_name: 90 | default_team_id: 91 | password: The password to decrypt the invite code. 92 | 93 | `Read in Mattermost API docs (remote_clusters - AcceptRemoteClusterInvite) `_ 94 | 95 | """ 96 | return self.client.post("""/api/v4/remotecluster/accept_invite""", options=options) 97 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/shared_channels.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["SharedChannels"] 4 | 5 | 6 | class SharedChannels(Base): 7 | 8 | def get_shared_channel_remotes(self, channel_id): 9 | """Get remote clusters for a shared channel 10 | 11 | channel_id: Channel GUID 12 | 13 | `Read in Mattermost API docs (shared_channels - GetSharedChannelRemotes) `_ 14 | 15 | """ 16 | return self.client.get(f"/api/v4/sharedchannels/{channel_id}/remotes") 17 | 18 | def get_all_shared_channels(self, team_id, params=None): 19 | """Get all shared channels for team. 20 | 21 | team_id: Team Id 22 | page: The page to select. 23 | per_page: The number of sharedchannels per page. 24 | 25 | `Read in Mattermost API docs (shared_channels - GetAllSharedChannels) `_ 26 | 27 | """ 28 | return self.client.get(f"/api/v4/sharedchannels/{team_id}", params=params) 29 | 30 | def get_shared_channel_remotes_by_remote_cluster(self, remote_id, params=None): 31 | """Get shared channel remotes by remote cluster. 32 | 33 | remote_id: The remote cluster GUID 34 | include_unconfirmed: Include those Shared channel remotes that are unconfirmed 35 | exclude_confirmed: Show only those Shared channel remotes that are not confirmed yet 36 | exclude_home: Show only those Shared channel remotes that were shared with this server 37 | exclude_remote: Show only those Shared channel remotes that were shared from this server 38 | include_deleted: Include those Shared channel remotes that have been deleted 39 | page: The page to select 40 | per_page: The number of shared channels per page 41 | 42 | `Read in Mattermost API docs (shared_channels - GetSharedChannelRemotesByRemoteCluster) `_ 43 | 44 | """ 45 | return self.client.get(f"/api/v4/remotecluster/{remote_id}/sharedchannelremotes", params=params) 46 | 47 | def get_remote_cluster_info(self, remote_id): 48 | """Get remote cluster info by ID for user. 49 | 50 | remote_id: Remote Cluster GUID 51 | 52 | `Read in Mattermost API docs (shared_channels - GetRemoteClusterInfo) `_ 53 | 54 | """ 55 | return self.client.get(f"/api/v4/sharedchannels/remote_info/{remote_id}") 56 | 57 | def invite_remote_cluster_to_channel(self, remote_id, channel_id): 58 | """Invites a remote cluster to a channel. 59 | 60 | remote_id: The remote cluster GUID 61 | channel_id: The channel GUID to invite the remote cluster to 62 | 63 | `Read in Mattermost API docs (shared_channels - InviteRemoteClusterToChannel) `_ 64 | 65 | """ 66 | return self.client.post(f"/api/v4/remotecluster/{remote_id}/channels/{channel_id}/invite") 67 | 68 | def uninvite_remote_cluster_to_channel(self, remote_id, channel_id): 69 | """Uninvites a remote cluster to a channel. 70 | 71 | remote_id: The remote cluster GUID 72 | channel_id: The channel GUID to uninvite the remote cluster to 73 | 74 | `Read in Mattermost API docs (shared_channels - UninviteRemoteClusterToChannel) `_ 75 | 76 | """ 77 | return self.client.post(f"/api/v4/remotecluster/{remote_id}/channels/{channel_id}/uninvite") 78 | 79 | def can_user_direct_message(self, user_id, other_user_id): 80 | """Check if user can DM another user in shared channels context 81 | 82 | user_id: User GUID 83 | other_user_id: Other user GUID 84 | 85 | `Read in Mattermost API docs (shared_channels - CanUserDirectMessage) `_ 86 | 87 | """ 88 | return self.client.get(f"/api/v4/sharedchannels/users/{user_id}/can_dm/{other_user_id}") 89 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/emoji.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Emoji"] 5 | 6 | 7 | class Emoji(Base): 8 | 9 | def create_emoji(self, image: BinaryIO, emoji: str): 10 | """Create a custom emoji 11 | 12 | image: A file to be uploaded 13 | emoji: A JSON object containing a ``name`` field with the name of the emoji and a ``creator_id`` field with the id of the authenticated user. 14 | 15 | `Read in Mattermost API docs (emoji - CreateEmoji) `_ 16 | 17 | """ 18 | __files = {"image": image} 19 | __data = {"emoji": emoji} 20 | return self.client.post("""/api/v4/emoji""", files=__files, data=__data) 21 | 22 | def get_emoji_list(self, page: int | None = 0, per_page: int | None = 60, sort: str | None = ""): 23 | """Get a list of custom emoji 24 | 25 | page: The page to select. 26 | per_page: The number of emojis per page. 27 | sort: Either blank for no sorting or "name" to sort by emoji names. Minimum server version for sorting is 4.7. 28 | 29 | `Read in Mattermost API docs (emoji - GetEmojiList) `_ 30 | 31 | """ 32 | __params = {"page": page, "per_page": per_page, "sort": sort} 33 | return self.client.get("""/api/v4/emoji""", params=__params) 34 | 35 | def get_emoji(self, emoji_id: str): 36 | """Get a custom emoji 37 | 38 | emoji_id: Emoji GUID 39 | 40 | `Read in Mattermost API docs (emoji - GetEmoji) `_ 41 | 42 | """ 43 | return self.client.get(f"/api/v4/emoji/{emoji_id}") 44 | 45 | def delete_emoji(self, emoji_id: str): 46 | """Delete a custom emoji 47 | 48 | emoji_id: Emoji GUID 49 | 50 | `Read in Mattermost API docs (emoji - DeleteEmoji) `_ 51 | 52 | """ 53 | return self.client.delete(f"/api/v4/emoji/{emoji_id}") 54 | 55 | def get_emoji_by_name(self, emoji_name: str): 56 | """Get a custom emoji by name 57 | 58 | emoji_name: Emoji name 59 | 60 | `Read in Mattermost API docs (emoji - GetEmojiByName) `_ 61 | 62 | """ 63 | return self.client.get(f"/api/v4/emoji/name/{emoji_name}") 64 | 65 | def get_emoji_image(self, emoji_id: str): 66 | """Get custom emoji image 67 | 68 | emoji_id: Emoji GUID 69 | 70 | `Read in Mattermost API docs (emoji - GetEmojiImage) `_ 71 | 72 | """ 73 | return self.client.get(f"/api/v4/emoji/{emoji_id}/image") 74 | 75 | def search_emoji(self, term: str, prefix_only: str | None = None): 76 | """Search custom emoji 77 | 78 | term: The term to match against the emoji name. 79 | prefix_only: Set to only search for names starting with the search term. 80 | 81 | `Read in Mattermost API docs (emoji - SearchEmoji) `_ 82 | 83 | """ 84 | __options = {"term": term, "prefix_only": prefix_only} 85 | return self.client.post("""/api/v4/emoji/search""", options=__options) 86 | 87 | def autocomplete_emoji(self, name: str): 88 | """Autocomplete custom emoji 89 | 90 | name: The emoji name to search. 91 | 92 | `Read in Mattermost API docs (emoji - AutocompleteEmoji) `_ 93 | 94 | """ 95 | __params = {"name": name} 96 | return self.client.get("""/api/v4/emoji/autocomplete""", params=__params) 97 | 98 | def get_emojis_by_names(self, options: list[str]): 99 | """Get custom emojis by name 100 | `Read in Mattermost API docs (emoji - GetEmojisByNames) `_ 101 | 102 | """ 103 | return self.client.post("""/api/v4/emoji/names""", options=options) 104 | -------------------------------------------------------------------------------- /src/mattermostautodriver/exceptions.py: -------------------------------------------------------------------------------- 1 | from httpx import HTTPError 2 | 3 | 4 | class InvalidMattermostError(Exception): 5 | """ 6 | Raised when mattermost returns an invalid error 7 | """ 8 | 9 | def __init__(self, message: str, status_code: int): 10 | super().__init__(message) 11 | self.status_code: int = status_code 12 | 13 | 14 | class MattermostError(HTTPError): 15 | """ 16 | Base class for all known mattermost errors 17 | """ 18 | 19 | def __init__( 20 | self, 21 | message: str, 22 | status_code: int, 23 | error_id: str, 24 | request_id: str, 25 | is_oauth_error: bool, 26 | ): 27 | super().__init__(message) 28 | self.status_code: int = status_code 29 | self.error_id: str = error_id 30 | self.request_id: str = request_id 31 | self.is_oauth_error: bool = is_oauth_error 32 | 33 | 34 | class UnknownMattermostError(MattermostError): 35 | """ 36 | Raised when mattermost returns a status code that is not known 37 | """ 38 | 39 | 40 | class InvalidOrMissingParameters(MattermostError): 41 | """ 42 | Raised when mattermost returns a 43 | 400 Invalid or missing parameters in URL or request body 44 | """ 45 | 46 | def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool): 47 | super().__init__( 48 | message=message, 49 | status_code=400, 50 | error_id=error_id, 51 | request_id=request_id, 52 | is_oauth_error=is_oauth_error, 53 | ) 54 | 55 | 56 | class NoAccessTokenProvided(MattermostError): 57 | """ 58 | Raised when mattermost returns a 59 | 401 No access token provided 60 | """ 61 | 62 | def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool): 63 | super().__init__( 64 | message=message, 65 | status_code=401, 66 | error_id=error_id, 67 | request_id=request_id, 68 | is_oauth_error=is_oauth_error, 69 | ) 70 | 71 | 72 | class NotEnoughPermissions(MattermostError): 73 | """ 74 | Raised when mattermost returns a 75 | 403 Do not have appropriate permissions 76 | """ 77 | 78 | def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool): 79 | super().__init__( 80 | message=message, 81 | status_code=403, 82 | error_id=error_id, 83 | request_id=request_id, 84 | is_oauth_error=is_oauth_error, 85 | ) 86 | 87 | 88 | class ResourceNotFound(MattermostError): 89 | """ 90 | Raised when mattermost returns a 91 | 404 Resource not found 92 | """ 93 | 94 | def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool): 95 | super().__init__( 96 | message=message, 97 | status_code=404, 98 | error_id=error_id, 99 | request_id=request_id, 100 | is_oauth_error=is_oauth_error, 101 | ) 102 | 103 | 104 | class MethodNotAllowed(MattermostError): 105 | """ 106 | Raised when mattermost returns a 107 | 405 Method Not Allowed 108 | """ 109 | 110 | def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool): 111 | super().__init__( 112 | message=message, 113 | status_code=405, 114 | error_id=error_id, 115 | request_id=request_id, 116 | is_oauth_error=is_oauth_error, 117 | ) 118 | 119 | 120 | class ContentTooLarge(MattermostError): 121 | """ 122 | Raised when mattermost returns a 123 | 413 Content too large 124 | """ 125 | 126 | def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool): 127 | super().__init__( 128 | message=message, 129 | status_code=413, 130 | error_id=error_id, 131 | request_id=request_id, 132 | is_oauth_error=is_oauth_error, 133 | ) 134 | 135 | 136 | class FeatureDisabled(MattermostError): 137 | """ 138 | Raised when mattermost returns a 139 | 501 Feature is disabled 140 | """ 141 | 142 | def __init__(self, message: str, error_id: str, request_id: str, is_oauth_error: bool): 143 | super().__init__( 144 | message=message, 145 | status_code=501, 146 | error_id=error_id, 147 | request_id=request_id, 148 | is_oauth_error=is_oauth_error, 149 | ) 150 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/plugins.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Plugins"] 4 | 5 | 6 | class Plugins(Base): 7 | 8 | def upload_plugin(self, files, data=None): 9 | """Upload plugin 10 | 11 | plugin: The plugin image to be uploaded 12 | force: Set to 'true' to overwrite a previously installed plugin with the same ID, if any 13 | 14 | `Read in Mattermost API docs (plugins - UploadPlugin) `_ 15 | 16 | """ 17 | return self.client.post("""/api/v4/plugins""", files=files, data=data) 18 | 19 | def get_plugins(self): 20 | """Get plugins 21 | `Read in Mattermost API docs (plugins - GetPlugins) `_ 22 | 23 | """ 24 | return self.client.get("""/api/v4/plugins""") 25 | 26 | def install_plugin_from_url(self): 27 | """Install plugin from url 28 | `Read in Mattermost API docs (plugins - InstallPluginFromUrl) `_ 29 | 30 | """ 31 | return self.client.post("""/api/v4/plugins/install_from_url""") 32 | 33 | def remove_plugin(self, plugin_id): 34 | """Remove plugin 35 | 36 | plugin_id: Id of the plugin to be removed 37 | 38 | `Read in Mattermost API docs (plugins - RemovePlugin) `_ 39 | 40 | """ 41 | return self.client.delete(f"/api/v4/plugins/{plugin_id}") 42 | 43 | def enable_plugin(self, plugin_id): 44 | """Enable plugin 45 | 46 | plugin_id: Id of the plugin to be enabled 47 | 48 | `Read in Mattermost API docs (plugins - EnablePlugin) `_ 49 | 50 | """ 51 | return self.client.post(f"/api/v4/plugins/{plugin_id}/enable") 52 | 53 | def disable_plugin(self, plugin_id): 54 | """Disable plugin 55 | 56 | plugin_id: Id of the plugin to be disabled 57 | 58 | `Read in Mattermost API docs (plugins - DisablePlugin) `_ 59 | 60 | """ 61 | return self.client.post(f"/api/v4/plugins/{plugin_id}/disable") 62 | 63 | def get_webapp_plugins(self): 64 | """Get webapp plugins 65 | `Read in Mattermost API docs (plugins - GetWebappPlugins) `_ 66 | 67 | """ 68 | return self.client.get("""/api/v4/plugins/webapp""") 69 | 70 | def get_plugin_statuses(self): 71 | """Get plugins status 72 | `Read in Mattermost API docs (plugins - GetPluginStatuses) `_ 73 | 74 | """ 75 | return self.client.get("""/api/v4/plugins/statuses""") 76 | 77 | def install_marketplace_plugin(self, options): 78 | """Installs a marketplace plugin 79 | 80 | id: The ID of the plugin to install. 81 | version: The version of the plugin to install. 82 | 83 | `Read in Mattermost API docs (plugins - InstallMarketplacePlugin) `_ 84 | 85 | """ 86 | return self.client.post("""/api/v4/plugins/marketplace""", options=options) 87 | 88 | def get_marketplace_plugins(self, params=None): 89 | """Gets all the marketplace plugins 90 | 91 | page: Page number to be fetched. (not yet implemented) 92 | per_page: Number of item per page. (not yet implemented) 93 | filter: Set to filter plugins by ID, name, or description. 94 | server_version: Set to filter minimum plugin server version. (not yet implemented) 95 | local_only: Set true to only retrieve local plugins. 96 | 97 | `Read in Mattermost API docs (plugins - GetMarketplacePlugins) `_ 98 | 99 | """ 100 | return self.client.get("""/api/v4/plugins/marketplace""", params=params) 101 | 102 | def get_marketplace_visited_by_admin(self): 103 | """Get if the Plugin Marketplace has been visited by at least an admin. 104 | `Read in Mattermost API docs (plugins - GetMarketplaceVisitedByAdmin) `_ 105 | 106 | """ 107 | return self.client.get("""/api/v4/plugins/marketplace/first_admin_visit""") 108 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints/status.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | from typing import Any, BinaryIO 3 | 4 | __all__ = ["Status"] 5 | 6 | 7 | class Status(Base): 8 | 9 | def get_user_status(self, user_id: str): 10 | """Get user status 11 | 12 | user_id: User ID 13 | 14 | `Read in Mattermost API docs (status - GetUserStatus) `_ 15 | 16 | """ 17 | return self.client.get(f"/api/v4/users/{user_id}/status") 18 | 19 | def update_user_status(self, user_id: str, status: str, dnd_end_time: int | None = None): 20 | """Update user status 21 | 22 | user_id: User ID 23 | user_id: User ID 24 | status: User status, can be ``online``, ``away``, ``offline`` and ``dnd`` 25 | dnd_end_time: Time in epoch seconds at which a dnd status would be unset. 26 | 27 | `Read in Mattermost API docs (status - UpdateUserStatus) `_ 28 | 29 | """ 30 | __options = {"user_id": user_id, "status": status, "dnd_end_time": dnd_end_time} 31 | return self.client.put(f"/api/v4/users/{user_id}/status", options=__options) 32 | 33 | def get_users_statuses_by_ids(self, options: list[str]): 34 | """Get user statuses by id 35 | `Read in Mattermost API docs (status - GetUsersStatusesByIds) `_ 36 | 37 | """ 38 | return self.client.post("""/api/v4/users/status/ids""", options=options) 39 | 40 | def update_user_custom_status( 41 | self, user_id: str, emoji: str, text: str, duration: str | None = None, expires_at: str | None = None 42 | ): 43 | """Update user custom status 44 | 45 | user_id: User ID 46 | emoji: Any emoji 47 | text: Any custom status text 48 | duration: Duration of custom status, can be ``thirty_minutes``, ``one_hour``, ``four_hours``, ``today``, ``this_week`` or ``date_and_time`` 49 | expires_at: The time at which custom status should be expired. It should be in ISO format. 50 | 51 | `Read in Mattermost API docs (status - UpdateUserCustomStatus) `_ 52 | 53 | """ 54 | __options = {"emoji": emoji, "text": text, "duration": duration, "expires_at": expires_at} 55 | return self.client.put(f"/api/v4/users/{user_id}/status/custom", options=__options) 56 | 57 | def unset_user_custom_status(self, user_id: str): 58 | """Unsets user custom status 59 | 60 | user_id: User ID 61 | 62 | `Read in Mattermost API docs (status - UnsetUserCustomStatus) `_ 63 | 64 | """ 65 | return self.client.delete(f"/api/v4/users/{user_id}/status/custom") 66 | 67 | def remove_recent_custom_status(self, user_id: str, emoji: str, text: str, duration: str, expires_at: str): 68 | """Delete user's recent custom status 69 | 70 | user_id: User ID 71 | emoji: Any emoji 72 | text: Any custom status text 73 | duration: Duration of custom status, can be ``thirty_minutes``, ``one_hour``, ``four_hours``, ``today``, ``this_week`` or ``date_and_time`` 74 | expires_at: The time at which custom status should be expired. It should be in ISO format. 75 | 76 | `Read in Mattermost API docs (status - RemoveRecentCustomStatus) `_ 77 | 78 | """ 79 | __params = {"emoji": emoji, "text": text, "duration": duration, "expires_at": expires_at} 80 | return self.client.delete(f"/api/v4/users/{user_id}/status/custom/recent", params=__params) 81 | 82 | def post_user_recent_custom_status_delete( 83 | self, user_id: str, emoji: str, text: str, duration: str, expires_at: str 84 | ): 85 | """Delete user's recent custom status 86 | 87 | user_id: User ID 88 | emoji: Any emoji 89 | text: Any custom status text 90 | duration: Duration of custom status, can be ``thirty_minutes``, ``one_hour``, ``four_hours``, ``today``, ``this_week`` or ``date_and_time`` 91 | expires_at: The time at which custom status should be expired. It should be in ISO format. 92 | 93 | `Read in Mattermost API docs (status - PostUserRecentCustomStatusDelete) `_ 94 | 95 | """ 96 | __options = {"emoji": emoji, "text": text, "duration": duration, "expires_at": expires_at} 97 | return self.client.post(f"/api/v4/users/{user_id}/status/custom/recent/delete", options=__options) 98 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/commands.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Commands"] 4 | 5 | 6 | class Commands(Base): 7 | 8 | def create_command(self, options): 9 | """Create a command 10 | 11 | team_id: Team ID to where the command should be created 12 | method: ``'P'`` for post request, ``'G'`` for get request 13 | trigger: Activation word to trigger the command 14 | url: The URL that the command will make the request 15 | 16 | `Read in Mattermost API docs (commands - CreateCommand) `_ 17 | 18 | """ 19 | return self.client.post("""/api/v4/commands""", options=options) 20 | 21 | def list_commands(self, params=None): 22 | """List commands for a team 23 | 24 | team_id: The team id. 25 | custom_only: To get only the custom commands. If set to false will get the custom 26 | if the user have access plus the system commands, otherwise just the system commands. 27 | 28 | 29 | `Read in Mattermost API docs (commands - ListCommands) `_ 30 | 31 | """ 32 | return self.client.get("""/api/v4/commands""", params=params) 33 | 34 | def list_autocomplete_commands(self, team_id): 35 | """List autocomplete commands 36 | 37 | team_id: Team GUID 38 | 39 | `Read in Mattermost API docs (commands - ListAutocompleteCommands) `_ 40 | 41 | """ 42 | return self.client.get(f"/api/v4/teams/{team_id}/commands/autocomplete") 43 | 44 | def list_command_autocomplete_suggestions(self, team_id, params=None): 45 | """List commands' autocomplete data 46 | 47 | team_id: Team GUID 48 | user_input: String inputted by the user. 49 | 50 | `Read in Mattermost API docs (commands - ListCommandAutocompleteSuggestions) `_ 51 | 52 | """ 53 | return self.client.get(f"/api/v4/teams/{team_id}/commands/autocomplete_suggestions", params=params) 54 | 55 | def get_command_by_id(self, command_id): 56 | """Get a command 57 | 58 | command_id: ID of the command to get 59 | 60 | `Read in Mattermost API docs (commands - GetCommandById) `_ 61 | 62 | """ 63 | return self.client.get(f"/api/v4/commands/{command_id}") 64 | 65 | def update_command(self, command_id, options): 66 | """Update a command 67 | 68 | command_id: ID of the command to update 69 | 70 | `Read in Mattermost API docs (commands - UpdateCommand) `_ 71 | 72 | """ 73 | return self.client.put(f"/api/v4/commands/{command_id}", options=options) 74 | 75 | def delete_command(self, command_id): 76 | """Delete a command 77 | 78 | command_id: ID of the command to delete 79 | 80 | `Read in Mattermost API docs (commands - DeleteCommand) `_ 81 | 82 | """ 83 | return self.client.delete(f"/api/v4/commands/{command_id}") 84 | 85 | def move_command(self, command_id, options): 86 | """Move a command 87 | 88 | command_id: ID of the command to move 89 | team_id: Destination teamId 90 | 91 | `Read in Mattermost API docs (commands - MoveCommand) `_ 92 | 93 | """ 94 | return self.client.put(f"/api/v4/commands/{command_id}/move", options=options) 95 | 96 | def regen_command_token(self, command_id): 97 | """Generate a new token 98 | 99 | command_id: ID of the command to generate the new token 100 | 101 | `Read in Mattermost API docs (commands - RegenCommandToken) `_ 102 | 103 | """ 104 | return self.client.put(f"/api/v4/commands/{command_id}/regen_token") 105 | 106 | def execute_command(self, options): 107 | """Execute a command 108 | 109 | channel_id: Channel Id where the command will execute 110 | command: The slash command to execute, including parameters. Eg, ``'/echo bounces around the room'`` 111 | 112 | `Read in Mattermost API docs (commands - ExecuteCommand) `_ 113 | 114 | """ 115 | return self.client.post("""/api/v4/commands/execute""", options=options) 116 | -------------------------------------------------------------------------------- /src/mattermostautodriver/endpoints_old/saml.py: -------------------------------------------------------------------------------- 1 | from ._base import Base 2 | 3 | __all__ = ["Saml"] 4 | 5 | 6 | class Saml(Base): 7 | 8 | def migrate_auth_to_saml(self, options=None): 9 | """Migrate user accounts authentication type to SAML. 10 | 11 | from: The current authentication type for the matched users. 12 | matches: Users map. 13 | auto: 14 | 15 | `Read in Mattermost API docs (saml - MigrateAuthToSaml) `_ 16 | 17 | """ 18 | return self.client.post("""/api/v4/users/migrate_auth/saml""", options=options) 19 | 20 | def get_saml_metadata(self): 21 | """Get metadata 22 | `Read in Mattermost API docs (saml - GetSamlMetadata) `_ 23 | 24 | """ 25 | return self.client.get("""/api/v4/saml/metadata""") 26 | 27 | def get_saml_metadata_from_idp(self, options=None): 28 | """Get metadata from Identity Provider 29 | 30 | saml_metadata_url: The URL from which to retrieve the SAML IDP data. 31 | 32 | `Read in Mattermost API docs (saml - GetSamlMetadataFromIdp) `_ 33 | 34 | """ 35 | return self.client.post("""/api/v4/saml/metadatafromidp""", options=options) 36 | 37 | def upload_saml_idp_certificate(self, files, data=None): 38 | """Upload IDP certificate 39 | 40 | certificate: The IDP certificate file 41 | 42 | `Read in Mattermost API docs (saml - UploadSamlIdpCertificate) `_ 43 | 44 | """ 45 | return self.client.post("""/api/v4/saml/certificate/idp""", files=files, data=data) 46 | 47 | def delete_saml_idp_certificate(self): 48 | """Remove IDP certificate 49 | `Read in Mattermost API docs (saml - DeleteSamlIdpCertificate) `_ 50 | 51 | """ 52 | return self.client.delete("""/api/v4/saml/certificate/idp""") 53 | 54 | def upload_saml_public_certificate(self, files, data=None): 55 | """Upload public certificate 56 | 57 | certificate: The public certificate file 58 | 59 | `Read in Mattermost API docs (saml - UploadSamlPublicCertificate) `_ 60 | 61 | """ 62 | return self.client.post("""/api/v4/saml/certificate/public""", files=files, data=data) 63 | 64 | def delete_saml_public_certificate(self): 65 | """Remove public certificate 66 | `Read in Mattermost API docs (saml - DeleteSamlPublicCertificate) `_ 67 | 68 | """ 69 | return self.client.delete("""/api/v4/saml/certificate/public""") 70 | 71 | def upload_saml_private_certificate(self, files, data=None): 72 | """Upload private key 73 | 74 | certificate: The private key file 75 | 76 | `Read in Mattermost API docs (saml - UploadSamlPrivateCertificate) `_ 77 | 78 | """ 79 | return self.client.post("""/api/v4/saml/certificate/private""", files=files, data=data) 80 | 81 | def delete_saml_private_certificate(self): 82 | """Remove private key 83 | `Read in Mattermost API docs (saml - DeleteSamlPrivateCertificate) `_ 84 | 85 | """ 86 | return self.client.delete("""/api/v4/saml/certificate/private""") 87 | 88 | def get_saml_certificate_status(self): 89 | """Get certificate status 90 | `Read in Mattermost API docs (saml - GetSamlCertificateStatus) `_ 91 | 92 | """ 93 | return self.client.get("""/api/v4/saml/certificate/status""") 94 | 95 | def reset_saml_auth_data_to_email(self, options=None): 96 | """Reset AuthData to Email 97 | 98 | include_deleted: Whether to include deleted users. 99 | dry_run: If set to true, the number of users who would be affected is returned. 100 | user_ids: If set to a non-empty array, then users whose IDs are not in the array will be excluded. 101 | 102 | `Read in Mattermost API docs (saml - ResetSamlAuthDataToEmail) `_ 103 | 104 | """ 105 | return self.client.post("""/api/v4/saml/reset_auth_data""", options=options) 106 | -------------------------------------------------------------------------------- /.github/workflows/check_mattermost_new_release_and_self_update.yml: -------------------------------------------------------------------------------- 1 | name: Check new Mattermost releases and self update preparing for package release 2 | 3 | on: 4 | schedule: 5 | - cron: '0 8 * * 1' # Runs weekly on Monday at 08:00 6 | workflow_dispatch: # Allows manual trigger 7 | 8 | jobs: 9 | check-and-release: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout current repo 14 | uses: actions/checkout@v4 15 | with: 16 | fetch-depth: 0 # Ensure all tags are available 17 | 18 | - name: Set up initial dependencies 19 | run: | 20 | sudo apt-get update 21 | sudo apt-get install -y jq 22 | 23 | - name: Check for latest Mattermost Server tag and MMAutoDriver PyPI version 24 | id: version_check 25 | run: | 26 | if ! TAGS_JSON="$(curl -s -f https://api.github.com/repos/mattermost/mattermost/tags)"; then 27 | echo "GitHub API call failed" 28 | exit 1 29 | fi 30 | 31 | LATEST_TAG="$(echo "$TAGS_JSON" | jq -r '.[].name' | grep -Eo '^v[0-9]+\.[0-9]+\.[0-9]+$'| sort -V | tail -n 1)" 32 | if [ -z "$LATEST_TAG" ]; then 33 | echo "No tags found" 34 | exit 1 35 | fi 36 | 37 | echo "Latest Mattermost Server tag: $LATEST_TAG" 38 | 39 | MM_VERSION="${LATEST_TAG#v}" 40 | 41 | OUR_TAG="$(git tag | sort -V | tail -n 1)" 42 | if [ -z "$OUR_TAG" ]; then 43 | echo "No tags found" 44 | exit 1 45 | fi 46 | 47 | echo "Latest MattermostAutoDriver git tag: $OUR_TAG" 48 | 49 | if [ "$OUR_TAG" = "$MM_VERSION" ]; then 50 | echo "MattermostAutoDriver and Mattermost Server versions match! We are up-to-date" 51 | exit 0 52 | fi 53 | 54 | if ! PYPI_VERSIONS="$(curl -s -f https://pypi.org/pypi/mattermostautodriver/json)"; then 55 | echo "Failed to retrieve versions from PyPI" 56 | exit 1 57 | fi 58 | 59 | if echo "$PYPI_VERSIONS" | jq -e --arg ver "$MM_VERSION" '.releases[$ver]' > /dev/null; then 60 | echo "Version $MM_VERSION already on PyPI - Unexpected! Not tagged but released?" 61 | exit 1 62 | fi 63 | 64 | echo "version=$LATEST_TAG" >> $GITHUB_OUTPUT 65 | echo "tag=$MM_VERSION" >> $GITHUB_OUTPUT 66 | 67 | - name: Set up additional dependencies for the entire check 68 | if: steps.version_check.outputs.version != '' 69 | run: | 70 | sudo apt-get update 71 | sudo apt-get install -y make npm python3 python3-pip git 72 | 73 | - name: Clone Mattermost server files matching tagged version 74 | if: steps.version_check.outputs.version != '' 75 | run: | 76 | git clone --depth 1 --branch "${{ steps.version_check.outputs.version }}" https://github.com/mattermost/mattermost mattermost 77 | 78 | - name: Build OpenAPI JSON specification 79 | if: steps.version_check.outputs.version != '' 80 | run: | 81 | cd mattermost/api 82 | make build 83 | ./node_modules/.bin/swagger-cli bundle --outfile openapi.json v4/html/static/mattermost-openapi-v4.yaml 84 | 85 | - name: Generate endpoints from API specification 86 | if: steps.version_check.outputs.version != '' 87 | run: | 88 | python3 -m venv .venv 89 | source .venv/bin/activate 90 | pip install --upgrade pip 91 | pip install -r requirements.txt 92 | ./scripts/generate_endpoints.sh 93 | 94 | - name: "Update our version file: src/mattermostautodriver/version.py" 95 | if: steps.version_check.outputs.version != '' 96 | run: | 97 | sed -i 's/full_version =.*/full_version = "${{ steps.version_check.outputs.tag }}"/' src/mattermostautodriver/version.py 98 | 99 | - name: Commit endpoint changes and tag new version 100 | if: steps.version_check.outputs.version != '' 101 | run: | 102 | git config user.name "Github-Actions" 103 | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" 104 | git add . 105 | if ! git commit -m "Prepare release ${{ steps.version_check.outputs.version }}"; then 106 | echo "No changes done, we are likely up-to-date so nothing to release. Stopping gracefuly" 107 | fi 108 | # Tag even if there were no changes so we avoid re-running this in the future 109 | git tag "${{ steps.version_check.outputs.tag }}" 110 | 111 | - name: Push changes and tag to mattermostautodriver repo 112 | if: steps.version_check.outputs.version != '' 113 | env: 114 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 115 | run: | 116 | git push origin HEAD 117 | git push origin "${{ steps.version_check.outputs.tag }}" 118 | 119 | --------------------------------------------------------------------------------