How to use the tableauserverclient.TableauAuth function in tableauserverclient

To help you get started, we’ve selected a few tableauserverclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tableau / server-client-python / test / test_auth.py View on Github external
def test_sign_in_impersonate(self):
        with open(SIGN_IN_IMPERSONATE_XML, 'rb') as f:
            response_xml = f.read().decode('utf-8')
        with requests_mock.mock() as m:
            m.post(self.baseurl + '/signin', text=response_xml)
            tableau_auth = TSC.TableauAuth('testuser', 'password',
                                           user_id_to_impersonate='dd2239f6-ddf1-4107-981a-4cf94e415794')
            self.server.auth.sign_in(tableau_auth)

        self.assertEqual('MJonFA6HDyy2C3oqR13fRGqE6cmgzwq3', self.server.auth_token)
        self.assertEqual('dad65087-b08b-4603-af4e-2887b8aafc67', self.server.site_id)
        self.assertEqual('dd2239f6-ddf1-4107-981a-4cf94e415794', self.server.user_id)
github tableau / server-client-python / samples / materialize_workbooks.py View on Github external
def update_project_by_path(args, materialized_views_config, password, site_content_url):
    if args.project_path is None:
        print("Use --project_path  to specify the path of the project")
        return False
    tableau_auth = TSC.TableauAuth(args.username, password, site_content_url)
    server = TSC.Server(args.server, use_server_version=True)
    project_name = args.project_path.split('/')[-1]
    with server.auth.sign_in(tableau_auth):
        if not assert_site_enabled_for_materialized_views(server, site_content_url):
            return False
        projects = [project for project in TSC.Pager(server.projects) if project.name == project_name]
        if not assert_project_valid(args.project_path, projects):
            return False

        possible_paths = get_project_paths(server, projects)
        update_project(possible_paths[args.project_path], server, materialized_views_config)
    return True
github tableau / server-client-python / samples / explore_webhooks.py View on Github external
help='desired logging level (set to error by default)')

    args = parser.parse_args()


    if args.p is None:
        password = getpass.getpass("Password: ")
    else:
        password = args.p

    # Set logging level based on user input, or error by default
    logging_level = getattr(logging, args.logging_level.upper())
    logging.basicConfig(level=logging_level)

    # SIGN IN
    tableau_auth = TSC.TableauAuth(args.username, password, args.site)
    print("Signing in to " + args.server + " [" + args.site + "] as " + args.username)
    server = TSC.Server(args.server)

    # Set http options to disable verifying SSL
    server.add_http_options({'verify': False})

    server.use_server_version()

    with server.auth.sign_in(tableau_auth):

        # Publish webhook if publish flag is set (-publish, -p)
        if args.create:

            new_webhook = TSC.WebhookItem()
            new_webhook.name = args.create
            new_webhook.url = "https://ifttt.com/maker-url"
github tableau / server-client-python / samples / filter_sort_groups.py View on Github external
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
    parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
                        help='desired logging level (set to error by default)')
    parser.add_argument('-p', default=None)
    args = parser.parse_args()

    if args.p is None:
        password = getpass.getpass("Password: ")
    else:
        password = args.p

    # Set logging level based on user input, or error by default
    logging_level = getattr(logging, args.logging_level.upper())
    logging.basicConfig(level=logging_level)

    tableau_auth = TSC.TableauAuth(args.username, password)
    server = TSC.Server(args.server)

    with server.auth.sign_in(tableau_auth):

        # Determine and use the highest api version for the server
        server.use_server_version()

        group_name = 'SALES NORTHWEST'
        # Try to create a group named "SALES NORTHWEST"
        create_example_group(group_name, server)

        group_name = 'SALES ROMANIA'
        # Try to create a group named "SALES ROMANIA"
        create_example_group(group_name, server)

        # URL Encode the name of the group that we want to filter on
github tableau / server-client-python / samples / set_http_options.py View on Github external
parser = argparse.ArgumentParser(description='List workbooks on site, with option set to ignore SSL verification.')
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
                    help='desired logging level (set to error by default)')
args = parser.parse_args()

password = getpass.getpass("Password: ")

# Set logging level based on user input, or error by default
logging_level = getattr(logging, args.logging_level.upper())
logging.basicConfig(level=logging_level)

# Step 1: Create required objects for sign in
tableau_auth = TSC.TableauAuth(args.username, password)
server = TSC.Server(args.server)

# Step 2: Set http options to disable verifying SSL
server.add_http_options({'verify': False})

with server.auth.sign_in(tableau_auth):

    # Step 3: Query all workbooks and list them
    all_workbooks, pagination_item = server.workbooks.get()
    print('{0} workbooks found. Showing {1}:'.format(pagination_item.total_available, pagination_item.page_size))
    for workbook in all_workbooks:
        print('\t{0} (ID: {1})'.format(workbook.name, workbook.id))
github tableau / server-client-python / samples / publish_workbook.py View on Github external
parser.add_argument('--server', '-s', required=True, help='server address')
    parser.add_argument('--username', '-u', required=True, help='username to sign into server')
    parser.add_argument('--filepath', '-f', required=True, help='filepath to the workbook to publish')
    parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
                        help='desired logging level (set to error by default)')

    args = parser.parse_args()

    password = getpass.getpass("Password: ")

    # Set logging level based on user input, or error by default
    logging_level = getattr(logging, args.logging_level.upper())
    logging.basicConfig(level=logging_level)

    # Step 1: Sign in to server.
    tableau_auth = TSC.TableauAuth(args.username, password)
    server = TSC.Server(args.server)
    server.use_server_version()

    overwrite_true = TSC.Server.PublishMode.Overwrite

    with server.auth.sign_in(tableau_auth):

        default_project = server.projects.get_default()

        # Step 3: If default project is found, form a new workbook item and publish.
        if default_project is not None:
            new_workbook = TSC.WorkbookItem(default_project.id)
            new_workbook = server.workbooks.publish(new_workbook, args.filepath, overwrite_true)
            print("Workbook published. ID: {0}".format(new_workbook.id))
        else:
            error = "The default project could not be found."
github tableau / server-client-python / samples / explore_datasource.py View on Github external
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
    parser.add_argument('--publish', '-p', metavar='FILEPATH', help='path to datasource to publish')
    parser.add_argument('--download', '-d', metavar='FILEPATH', help='path to save downloaded datasource')
    parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
                        help='desired logging level (set to error by default)')

    args = parser.parse_args()

    password = getpass.getpass("Password: ")

    # Set logging level based on user input, or error by default
    logging_level = getattr(logging, args.logging_level.upper())
    logging.basicConfig(level=logging_level)

    # SIGN IN
    tableau_auth = TSC.TableauAuth(args.username, password)
    server = TSC.Server(args.server)
    server.use_highest_version()
    with server.auth.sign_in(tableau_auth):
        # Query projects for use when demonstrating publishing and updating
        all_projects, pagination_item = server.projects.get()
        default_project = next((project for project in all_projects if project.is_default()), None)

        # Publish datasource if publish flag is set (-publish, -p)
        if args.publish:
            if default_project is not None:
                new_datasource = TSC.DatasourceItem(default_project.id)
                new_datasource = server.datasources.publish(
                    new_datasource, args.publish, TSC.Server.PublishMode.Overwrite)
                print("Datasource published. ID: {}".format(new_datasource.id))
            else:
                print("Publish failed. Could not find the default project.")
github tableau / server-client-python / samples / download_view_image.py View on Github external
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
                        help='desired logging level (set to error by default)')

    args = parser.parse_args()

    password = getpass.getpass("Password: ")

    # Set logging level based on user input, or error by default
    logging_level = getattr(logging, args.logging_level.upper())
    logging.basicConfig(level=logging_level)

    # Step 1: Sign in to server.
    site_id = args.site_id
    if not site_id:
        site_id = ""
    tableau_auth = TSC.TableauAuth(args.username, password, site_id=site_id)
    server = TSC.Server(args.server)
    # The new endpoint was introduced in Version 2.5
    server.version = "2.5"

    with server.auth.sign_in(tableau_auth):
        # Step 2: Query for the view that we want an image of
        req_option = TSC.RequestOptions()
        req_option.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
                                         TSC.RequestOptions.Operator.Equals, args.view_name))
        all_views, pagination_item = server.views.get(req_option)
        if not all_views:
            raise LookupError("View with the specified name was not found.")
        view_item = all_views[0]

        # Step 3: Query the image endpoint and save the image to the specified location
        image_req_option = TSC.ImageRequestOptions(imageresolution=TSC.ImageRequestOptions.Resolution.High)
github tableau / server-client-python / samples / materialize_workbooks.py View on Github external
with server.auth.sign_in(tableau_auth):
        # For server admin, this will prints all the materialized views enabled sites
        # For other users, this only prints the status of the site they belong to
        print("Materialized views is enabled on sites:")
        # only server admins can get all the sites in the server
        # other users can only get the site they are in
        for site in TSC.Pager(server.sites):
            if site.materialized_views_mode != "disable":
                enabled_sites.add(site)
                print("Site name: {}".format(site.name))
        print('\n')

    print("Materialized views is enabled on workbooks:")
    # Individual workbooks can be enabled only when the sites they belong to are enabled too
    for site in enabled_sites:
        site_auth = TSC.TableauAuth(args.username, password, site.content_url)
        with server.auth.sign_in(site_auth):
            for workbook in TSC.Pager(server.workbooks):
                if workbook.materialized_views_config['materialized_views_enabled']:
                    print("Workbook: {} from site: {}".format(workbook.name, site.name))