Secure Share
Secure document sharing with minimal code, and no infrastructure management
Quickstart
Pangea’s Secure Share service is a file system that provides protected data storage for files and folders, as well as the ability to securely manage access and sharing.
Organizations can upload files to Pangea, generate shareable links, and choose to allow users to upload, download, or edit their files while managing access by number of views and length of time the URL is available. Shares can even require password authentication, or utilize One Time Passcodes (OTP) via email or SMS to prevent unauthorized access.
Configuring the Secure Share service
These steps are intended to help you get started with integrating Secure Share with your application. For a complete set of information, including how to configure Secure Share in your Pangea console and manage all shared files and folders, refer to the Overview page.
- Navigate to the Pangea User Console .
- Sign up to Pangea. As part of the sign up process, an Organization and initial token will be created.
- Configure the token for use with the Secure Share service.
- Set any desired settings in the Secure Share Settings.
Add Secure Share to your app
The steps below will walk you through the basics of utilizing Pangea’s Secure Share capabilities, including a complete code sample for uploading a file to our secure file management system, then generating a password-protected link to share.
The steps below will walk you through the basics of integrating Secure Share with a Python app, including a completed code sample for getting started with uploading a file to the service, creating a shareable link, and setting its parameters for user access. For a more in-depth explanation of the sample app, you can visit our Python SDK.
Set your environment variables
Before starting to code, it is necessary to export your token and domain variables to your project if you have not already added them to your environment.
- Open up a bash terminal window.
- Type the following commands, replacing 'yourServiceDomain' and 'yourAccessToken' with your Domain and Default Token copied from the Share page in the Pangea User Console.
export PANGEA_DOMAIN="yourServiceDomain"
export PANGEA_SHARE_TOKEN="yourAccessToken"
Writing the Secure Share code
- In order to be ready to code, you must first install the Pangea SDK. To add the Pangea Python SDK to your project, you will need to run one of the following commands in your project root directory based on your preferred installation method.
Install SDK via Pip:
pip3 install pangea-sdk==5.1.0
or
Install SDK via Poetry:
poetry add pangea-sdk==5.1.0
- Next, import the Pangea libraries into your code.
import datetime
import os
import pangea.exceptions as pe
from pangea.config import PangeaConfig
from pangea.response import TransferMethod
from pangea.services import Share
- The following loads the token and domain from your environment variables so you can authenticate with Pangea.
token = os.getenv("PANGEA_SHARE_TOKEN")
assert token
domain = os.getenv("PANGEA_DOMAIN")
assert domain
config = PangeaConfig(domain=domain)
- Create a path name and service object.
date = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
path = f"/sdk_example/files/{date}"
filepath_upload = "./share_examples/testfile.pdf"
share = Share(token, config=config)
- Create a folder and upload a file to be securely shared.
try:
print("\nCreating folder...")
resp_create = share.folder_create(path=path)
folder_id = resp_create.result.object.id
print(f"Folder create success. Folder ID: {folder_id}.")
print("\nUploading file with path...")
with open(filepath_upload, "rb") as f:
filepath_put = path + f"/{date}_file_multipart_1"
resp_put_path = share.put(file=f, path=filepath_put, transfer_method=TransferMethod.MULTIPART)
print(
f"Put success.\n\tItem ID: {resp_put_path.result.object.id}\n\tParent ID: {resp_put_path.result.object.parent_id}"
)
print(f"Metadata: {resp_put_path.result.object.metadata}. Tags: {resp_put_path.result.object.tags}")
- Finally, create the necessary authenticators, create the link list, then retrieve your Secure Share file link.
print("\nCreating share link...")
authenticators = [Authenticator(auth_type=AuthenticatorType.PASSWORD, auth_context="somepassword")]
link_list = [
ShareLinkCreateItem(
targets=[folder_id],
link_type=LinkType.EDITOR,
max_access_count=3,
authenticators=authenticators,
)
]
resp_create_link = share.share_link_create(links=link_list)
links = resp_create_link.result.share_link_objects
print(f"Created {len(links)} link(s)")
link = links[0]
print(f"Link ID: {link.id}. Link: {link.link}")
print("\nGetting already created link by id...")
resp_get_link = share.share_link_get(id=link.id)
print(
f"Got link ID: {resp_get_link.result.share_link_object.id}. Link: {resp_get_link.result.share_link_object.link}"
)
print("\nListing links...")
resp_list_link = share.share_link_list()
print(f"Got {resp_list_link.result.count} link(s).")
Completed code
Below is a complete code sample for this application. It can serve as a usable, copy & paste resource that will work on its own, provided you edit placeholder data such as ./share_examples/testfile.pdf
, somepassword
, etc. with your desired values.
import datetime
import os
import pangea.exceptions as pe
from pangea.config import PangeaConfig
from pangea.response import TransferMethod
from pangea.services import Share
token = os.getenv("PANGEA_SHARE_TOKEN")
assert token
domain = os.getenv("PANGEA_DOMAIN")
assert domain
config = PangeaConfig(domain=domain)
# Create a path name
date = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
path = f"/sdk_example/files/{date}"
filepath_upload = "./share_examples/testfile.pdf"
# Create service object
share = Share(token, config=config)
def main():
try:
# Create a folder
print("\nCreating folder...")
resp_create = share.folder_create(path=path)
folder_id = resp_create.result.object.id
print(f"Folder create success. Folder ID: {folder_id}.")
# Upload a file with path as unique param
print("\nUploading file with path...")
with open(filepath_upload, "rb") as f:
filepath_put = path + f"/{date}_file_multipart_1"
resp_put_path = share.put(file=f, path=filepath_put, transfer_method=TransferMethod.MULTIPART)
print(
f"Put success.\n\tItem ID: {resp_put_path.result.object.id}\n\tParent ID: {resp_put_path.result.object.parent_id}"
)
print(f"Metadata: {resp_put_path.result.object.metadata}. Tags: {resp_put_path.result.object.tags}")
# Create share link
print("\nCreating share link...")
# Need to create allowed authenticators to access share link
authenticators = [Authenticator(auth_type=AuthenticatorType.PASSWORD, auth_context="somepassword")]
# Create share link list, including all the items to share
link_list = [
ShareLinkCreateItem(
targets=[folder_id],
link_type=LinkType.EDITOR,
max_access_count=3,
authenticators=authenticators,
)
]
# Send request to create links
resp_create_link = share.share_link_create(links=link_list)
links = resp_create_link.result.share_link_objects
print(f"Created {len(links)} link(s)")
link = links[0]
print(f"Link ID: {link.id}. Link: {link.link}")
# Get share link
print("\nGetting already created link by id...")
resp_get_link = share.share_link_get(id=link.id)
print(
f"Got link ID: {resp_get_link.result.share_link_object.id}. Link: {resp_get_link.result.share_link_object.link}"
)
# List share link
print("\nListing links...")
resp_list_link = share.share_link_list()
print(f"Got {resp_list_link.result.count} link(s).")
if __name__ == "__main__":
main()
Improving your app
The purpose of this guide is to provide the minimum steps required to start coding with our Secure Share service, however there are additional features that can be explored, such as monitoring all actively shared files within your console, or integrating Secure Share with our Vault service to add even more encryption security and provide key rotation. Read more about the capabilities on our Secure Share Overview page.
Pangea has based Secure Share on years of experience building compliant enterprise applications. This service helps to ensure that builders have the necessary tools to meet the security needs of their application’s users.
Next steps
- Check out our Admin Guide if you have a specific task you would like to complete
- If you are feeling confident, you can browse our APIs or explore our Github repo, which has libraries for supported languages, SDKs, sample apps, etc.
- For any questions, you can connect with our Pangea Slack for Builders or continue exploring our Secure Share documentation
Was this article helpful?