Skip to main content

PyPi unittest status Coverage License Issues Stars

This repository contains addons to allow integration with MS Sharepoint via Open Task Framework (OTF)

Open Task Framework (OTF) is a Python based framework to make it easy to run predefined file transfers and scripts/commands on remote machines.

This addons allows filewatches and pushes of files to Sharepoint Sites.

O365 Credentials

This package uses msal to get OAuth2.0 creds for the MS Graph API. This includes access_token and refresh_token.

For tests to work, a .env file containing the following needs to be created at the root of this repo containing the following:

SHAREPOINT_HOST=
SHAREPOINT_SITE=
CLIENT_ID=
TENANT_ID=

An Enterprise Application needs to be configured within EntraID to allow the app to access the Sharepoint API using delegated permissions. These should be set up as follows:

App Registration

Under Authentication, the following needs to be enabled:

Auth

Once your app is set up, copy the "Application (client) ID" and "Directory (tenant) ID" into the .env file. The SHAREPOINT_HOST should be the hostname of your sharepoint instance , and the SHAREPOINT_SITE should be name of the Sharepoint site itself.

You will need a "service account" user to authenticate with. This user should have access to the Sharepoint site you want to interact with, and OTF will act on behalf of this user for any interactions with Sharepoint. Any files created will be owned by this user.

Once this is done, you can trigger OTF to perform a task, or run the test under tests. The test will cache a refresh_token.txt locally, after going through the login flow.

You will see a message in the logs stating that you need to log into your account in a web browser, along with a code to enter. Follow the instructions (logging in with your service account) to complete the process flow and get the credentials.

When using in a real environment, you'll want to make use of cacheable variables to ensure that the refresh_token is updated after each login. See the test_taskhandler_transfer_sharepoint.py file for an example of how this is done. The task definition in your .json.j2 task definition will need to use the equivalent lookup plugin to obtain the refresh_token from the cache on startup.

Transfers

Transfers require a few additional arguments to normal. These are:

  • siteHostname: The hostname of the Sharepoint site
  • siteName: The name of the Sharepoint site

As part of the upload, the bucket-owner-full-control ACL flag is applied to all files. This can be disabled by setting disableBucketOwnerControlACL to true in the protocol definition

Supported features

  • Plain file watch
  • File watch/transfer with file size and age constraints

Configuration

JSON configs for transfers can be defined as follows:

Handling of document libraries

If you have a document library in your Sharepoint site, you can specify the name of the document library as part of the path. By default, if the destination path does not start with a /, then the file will be uploaded to the root of the site (The default Document Library), otherwise it will be uploaded to the document library specified in the first component of the path.

Example File Watch Only

"source": {
        "siteHostname": "mydomain.sharepoint.com",
        "siteName": "mysitename",
        "directory": "src",
        "fileRegex": ".*\\.txt",
        "protocol": {
            "name": "opentaskpy.addons.o365.remotehandlers.sharepoint.SharepointTransfer",
            "refreshToken": "{{ SOME LOOKUP DEFINITION }}",
            "clientId": "my-application-id",
            "tenantId": "my-tenant-id"
        },
        "fileWatch": {
            "timeout": 2
        },
        "cacheableVariables": [
            {
                "variableName": "protocol.refreshToken",
                "cachingPlugin": "file",
                "cacheArgs": {
                    "file": "some-file.txt"
                }
            }
        ]
    }

Example file upload

"source": {
    "siteHostname": "mydomain.sharepoint.com",
        "siteName": "mysitename",
    "directory": "dest",
    "protocol": {
        "name": "opentaskpy.addons.o365.remotehandlers.sharepoint.SharepointTransfer",
        "refreshToken": "{{ SOME LOOKUP DEFINITION }}",
        "clientId": "my-application-id",
        "tenantId": "my-tenant-id"
    },
    "cacheableVariables": [
        {
            "variableName": "protocol.refreshToken",
            "cachingPlugin": "file",
            "cacheArgs": {
                "file": "some-file.txt",
            },
        }
    ],
}

Release files for otf-addons-o365 26.16.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for otf-addons-o365 26.16.1
File Size Uploaded
otf_addons_o365-26.16.1.tar.gz 36.6 kB Details

Release files / otf_addons_o365-26.16.1.tar.gz

Download URL otf_addons_o365-26.16.1.tar.gz
Size 36.6 kB
Tags Source
SHA-256 checksum
How to use checksums
aaa0a203fb8d0ed2f8ae8fdd4f88b548b7b7be642eae2b03055fe56ec5835e0d
BLAKE2b-256 checksum
How to use checksums
c8de692d4f9c6a7f1fb0e55bb672873864fab7a90e95b6328bd25d17b1723da3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

26.16.1 This release

1 release file

26.10.3

1 release file

26.10.2

1 release file

26.8.0

1 release file

26.6.0

1 release file

25.34.0

1 release file

25.27.0

1 release file

25.9.0

1 release file

24.44.0

1 release file

24.30.0

1 release file

24.29.0

1 release file

24.25.2

1 release file

24.25.1

1 release file

24.25.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page