Beispiel #1
0
def main():
    """Method called from the main entry point of the script to do the required logic."""
    args = parse_args()

    portal_name = args.portal
    configuration_path = args.file
    org_name = args.org
    username = args.username
    password = args.password
    refresh_token = args.refresh_token

    # Retrieve an access token using the refresh token provided. This ensures
    # that we always have a valid access token.
    if refresh_token is not None:
        access_token = apigee_auth.refresh_access_token(refresh_token)
    else:
        access_token = apigee_auth.get_access_token(username, password)

    # Add Auth Header by default to all requests.
    REQUEST.headers.update({
        'Authorization': 'Bearer {}'.format(access_token),
        'Content-Type': 'application/json'
    })

    # Check portal and add it if not present
    portal = apigee_portal.get_portal(REQUEST, org_name, portal_name)

    new_theme = load_local_theme(configuration_path)

    if new_theme is not None:
        apigee_customcss.update_theme(REQUEST, portal.id, new_theme)
        apigee_customcss.publish_theme(REQUEST, portal.id, org_name)
Beispiel #2
0
def main():
    """Method called from the main entry point of the script to do the required logic."""
    args = parse_args()

    spec_name = args.name
    spec_path = args.file
    org_name = args.org
    username = args.username
    password = args.password
    refresh_token = args.refresh_token

    # Retrieve an access token using the refresh token provided. This ensures
    # that we always have a valid access token.
    if refresh_token is not None:
        access_token = apigee_auth.refresh_access_token(refresh_token)
    else:
        access_token = apigee_auth.get_access_token(username, password)

    # Add Auth Header by default to all requests.
    REQUEST.headers.update({'Authorization': 'Bearer {}'.format(access_token)})

    # Retrieve all the API specs
    folder = get_specs_folder(org_name)

    # Check if there already is an OpenAPI spec with the same name.
    spec = spec_exists(spec_name, folder.specs)

    # Create a new file for the OpenApi spec on Apigee if there isn't an
    # existing one.
    if not spec:
        print('Spec does not exist - creating it on Apigee')
        spec = create_empty_spec(org_name, folder.folder_id, spec_name)

    # Fill the file with the OpenAPI spec.
    update_spec(org_name, spec.spec_id, spec_path)
Beispiel #3
0
def main():
    """Method called from the main entry point of the script to do the required  logic."""
    args = parse_args()

    config_file = args.file
    org_name = args.org
    username = args.username
    password = args.password
    portal_name = args.portal
    refresh_token = args.refresh_token

    # Retrieve an access token using the refresh token provided. This ensures
    # that we always have a valid access token.
    if refresh_token is not None:
        access_token = apigee_auth.refresh_access_token(refresh_token)
    else:
        access_token = apigee_auth.get_access_token(username, password)

    # Add Auth Header by default to all requests.
    REQUEST.headers.update({'Authorization': 'Bearer {}'.format(access_token), 'Content-Type': 'application/json'})

    # Load portal configuration ... add or update it.
    data = open(config_file, 'r').read()
    config = json.loads(data)

    # Override if portal name was passed as a switch.
    if portal_name:
        config['name'] = portal_name

    # Get portal and add it if not present
    portal = apigee_portal.add_or_get_portal(REQUEST, org_name, config['name'], config['description'])

    # Update portal description and analytics
    apigee_portal.update_portal(REQUEST, portal, config)
def main():
    """Method called from the main entry point of the script to do the required logic."""
    args = parse_args()

    doc_path = args.file
    spec_name = args.spec_name
    portal = args.portal
    org_name = args.org
    username = args.username
    password = args.password
    refresh_token = args.refresh_token

    data = open(doc_path, 'r').read()
    doc = json.loads(data)

    # Organization name might change according to the environment. so update the json
    # with the organization name given as an argument. Spec name also needs to be provided
    # as an argument for ease of use when using this script along with upload_spec.py.
    doc.update({'orgname': org_name, 'specId': spec_name})

    # Retrieve an access token using the refresh token provided. This ensures
    # that we always have a valid access token.
    if refresh_token is not None:
        access_token = apigee_auth.refresh_access_token(refresh_token)
    else:
        access_token = apigee_auth.get_access_token(username, password)

    # Add Auth Header by default to all requests.
    REQUEST.headers.update({'Authorization': 'Bearer {}'.format(access_token)})

    #Check portal and add it if not present
    current_portal = apigee_portal.get_portal(REQUEST, org_name, portal)

    # We do not want to create portal documentation if the spec given does not
    # exist on Apigee.
    spec_id = spec_exists(org_name, spec_name)
    if not spec_id:
        raise RestException(
            "Spec with name '{}' does not exist in Apigee.".format(spec_name))

    # Spec IDs might change all the time, and we use the name as our ID.
    # Therefore, use the spec name specified in the JSON file and fetch
    # the spec ID dynamically.
    doc.update({'specContent': spec_id})

    api_doc = documentation_exists(spec_name, current_portal.id)
    if api_doc:
        print("API Doc already exists.")
        try:
            update_api_documentation(api_doc, doc, current_portal.id)
        except RestException:
            # Retry since this call fails intermittently
            print("First put call failed ... retrying")
            time.sleep(5)
            update_api_documentation(api_doc, doc, current_portal.id)
    else:
        print("API Doc does not currently exist.")
        create_api_documentation(doc, current_portal.id)
Beispiel #5
0
def main():
    """Method called from the main entry point of the script to do the required logic."""
    args = parse_args()

    portal_name = args.portal
    pages_folder = args.folder
    org_name = args.org
    username = args.username
    password = args.password
    refresh_token = args.refresh_token
    menu_items_config = args.menu

    # Retrieve an access token using the refresh token provided. This ensures
    # that we always have a valid access token.
    if refresh_token is not None:
        access_token = apigee_auth.refresh_access_token(refresh_token)
    else:
        access_token = apigee_auth.get_access_token(username, password)

    # Add Auth Header by default to all requests.
    REQUEST.headers.update({
        'Authorization': 'Bearer {}'.format(access_token),
        'Content-Type': 'application/json'
    })

    # Check portal and add it if not present
    portal = apigee_portal.get_portal(REQUEST, org_name, portal_name)

    # Get remote and local pages
    remote_pages = apigee_pages.get_remote_pages(REQUEST, portal.id)
    local_pages = get_local_pages(pages_folder)

    # Get differences between local and remote pages
    to_add = set(local_pages.keys()) - set(remote_pages.keys())
    to_delete = set(remote_pages.keys()) - set(local_pages.keys())
    to_update = set(remote_pages.keys()).intersection(set(local_pages.keys()))

    for friendly_id in to_delete:
        apigee_pages.delete_remote_page(REQUEST, portal.id,
                                        remote_pages[friendly_id].id)

    for add in to_add:
        apigee_pages.add_update_remote_page(REQUEST, portal.id, org_name, None,
                                            add, local_pages[add])

    for update in to_update:
        apigee_pages.add_update_remote_page(REQUEST, portal.id, org_name,
                                            remote_pages[update].id, update,
                                            local_pages[update])

    # Refresh menu items
    refresh_menu_items(REQUEST, portal.id, org_name, menu_items_config)
def main():
    """Method called from the main entry point of the script to do the required logic."""
    args = parse_args()

    query_path = args.file
    org_name = args.org
    env = args.env
    output_path = args.output
    start_date = args.startdate
    end_date = args.enddate
    username = args.username
    password = args.password
    refresh_token = args.refresh_token

    # Retrieve an access token using the refresh token provided. This ensures
    # that we always have a valid access token.
    if refresh_token is not None:
        access_token = apigee_auth.refresh_access_token(refresh_token)
    else:
        access_token = apigee_auth.get_access_token(username, password)

    # Add Auth Header by default to all requests.
    REQUEST.headers.update({'Authorization': 'Bearer {}'.format(access_token)})

    # Read JSON file containing analytics query setup information.
    data = open(query_path, 'r').read()
    query = json.loads(data)

    # Set the start and aed date for the report in the given JSON.
    # This is so that the dates can be modified flexibly without modifying the JSON.
    query.update({'timeRange': {'start': start_date, 'end': end_date}})
    query = apigee_reports.generate_async_query(REQUEST, org_name, env, query)

    print('Please wait while report finishes compiling.')
    while query.state != 'completed':
        # Wait 5 seconds before checking if the query has completed.
        time.sleep(5)
        query = apigee_reports.get_query_status(REQUEST, query.url)

    # If the output path is specified, save the result there.
    if not output_path:
        apigee_reports.get_query_result(REQUEST, query.url)
    else:
        apigee_reports.get_query_result(REQUEST, query.url, output_path)
Beispiel #7
0
def main():
    """Method called from the main entry point of the script to do the required logic."""
    args = parse_args()

    portal_name = args.portal
    assets_folder = args.folder
    org_name = args.org
    username = args.username
    password = args.password
    refresh_token = args.refresh_token
    clean = args.clean

    # Retrieve an access token using the refresh token provided. This ensures
    # that we always have a valid access token.
    if refresh_token is not None:
        access_token = apigee_auth.refresh_access_token(refresh_token)
    else:
        access_token = apigee_auth.get_access_token(username, password)

    # Add Auth Header by default to all requests.
    REQUEST.headers.update({'Authorization': 'Bearer {}'.format(access_token)})

    # Check portal and add it if not present
    portal = apigee_portal.get_portal(REQUEST, org_name, portal_name)

    # Get remote and local assets
    remote_assets = apigee_assets.get_remote_assets(REQUEST, portal.id)
    local_assets = get_local_assets(assets_folder)

    #get differences between sets
    to_add = set(local_assets.keys()) - set(remote_assets.keys())
    to_delete = set(remote_assets.keys()) - set(local_assets.keys())
    to_update = set(remote_assets.keys()).intersection(set(local_assets.keys()))

    for add in to_add:
        apigee_assets.add_remote_asset(REQUEST, portal.id, local_assets[add].path)

    for update in to_update:
        apigee_assets.add_remote_asset(REQUEST, portal.id, local_assets[update].path)

    if clean:
        for path in to_delete:
            apigee_assets.delete_remote_asset(REQUEST, portal.id, org_name, path)
def main():
    """Method called from the main entry point of the script to do the required logic."""
    args = parse_args()

    product_path = args.file
    org_name = args.org
    username = args.username
    password = args.password
    refresh_token = args.refresh_token

    # Retrieve an access token using the refresh token provided. This ensures
    # that we always have a valid access token.
    if refresh_token is not None:
        access_token = apigee_auth.refresh_access_token(refresh_token)
    else:
        access_token = apigee_auth.get_access_token(username, password)

    # Add Auth Header by default to all requests.
    REQUEST.headers.update({'Authorization': 'Bearer {}'.format(access_token)})

    # Read JSON file containing API Product setup information.
    data = open(product_path, 'r').read()
    product = json.loads(data)
    product_name: str = product['name']

    # Name is mandatory in the JSON file, otherwise we would not know
    # whether we want to create or update.
    if 'name' not in product:
        raise Exception(
            print_error('API Product name not specified in JSON file.'))

    exists: bool = product_exists(product_name, org_name)

    if exists:
        print(
            "API Product with name '{}' already exists. Performing an update.".
            format(product_name))
        update_api_product(org_name, product)
    else:
        print(
            "API Product with name '{}' does not exist. Creating it in Apigee."
            .format(product_name))
        create_api_product(org_name, product)
Beispiel #9
0
def main():
    """Method called from the main entry point of the script to do the required logic."""
    args = parse_args()

    portal_name = args.portal
    file = args.file
    org_name = args.org
    username = args.username
    password = args.password
    refresh_token = args.refresh_token

    # Retrieve an access token using the refresh token provided. This ensures
    # that we always have a valid access token.
    if refresh_token is not None:
        access_token = apigee_auth.refresh_access_token(refresh_token)
    else:
        access_token = apigee_auth.get_access_token(username, password)

    # Add Auth Header by default to all requests.
    REQUEST.headers.update({'Authorization': 'Bearer {}'.format(access_token)})

    # Check portal and add it if not present
    portal = apigee_portal.get_portal(REQUEST, org_name, portal_name)
    apigee_assets.add_remote_asset(REQUEST, portal.id, file)