Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support REST v2 API Calls #913

Merged
merged 19 commits into from
Mar 18, 2024
Merged

Support REST v2 API Calls #913

merged 19 commits into from
Mar 18, 2024

Conversation

jdknight
Copy link
Member

@jdknight jdknight commented Mar 5, 2024

Providing support for Confluence Cloud REST v2 APIs.

  • This moves the API path prefix logic from a Rest class into a Publisher class.
  • Introduces a new configuration option confluence_api_mode to configure which mode to use; otherwise it defaults to using v2 for Confluence Cloud variants, or v1 for everything else.
  • The option confluence_publish_disable_api_prefix has been deprecated over a new option confluence_publish_override_api_prefix, allowing API version-specific prefix overrides.
  • Updating a series of deprecated API calls with their new v2 compatible calls.

@jdknight jdknight added this to the 2.5 milestone Mar 5, 2024
@jdknight jdknight self-assigned this Mar 5, 2024
Reduce the length of the member variable for publisher's reference to
the REST client entity.

Signed-off-by: James Knight <james.d.knight@live.com>
This commit refactors the logic used when building API URLs to query.
The original "bind path"/path-prefix logic would be added inside a Rest
client whenever a request was prepared. However, to use Confluence's v2
API, this prefix varies (instead of `rest/api`, it is `api/v2`). This
extension needs to be able to perform a mixed set of API calls, since
both a series of v1/v2 APIs are available, select v1 deprecated APIs
will no longer be available in the upcoming months (potential) and
certain v1 active APIs are still required for some actions.

To support various API paths, responsibility is now being placed inside
the publisher when forming requests. The REST client class will assume
the full path is provided via the URL configuration and the provided
path value.

Signed-off-by: James Knight <james.d.knight@live.com>
Provides initial support to interact with a Confluence instance using
REST v2 API. This updates the initial space search request to use a v2
API `spaces` for Confluence Cloud instances. Otherwise, it uses v1 for
all other cases (unless explicitly overridden).

This is a first step towards updating this extension to avoid the use of
any deprecated API call.

Since we now aim to support two types of API calls, the existing
`confluence_publish_disable_api_prefix` configuration does not
completely work as expected. Users may need a way to configure custom
prefixes based on whether a call uses v2 API or v1 API (since an API
mode may require using a mix of versions). To support this, introducing
a new option called `confluence_publish_override_api_prefix`, which
allows a user to tailor specific prefix values to use per API request
type being performed.

Signed-off-by: James Knight <james.d.knight@live.com>
Adds documentation for the recently added `confluence_api_mode` and
`confluence_publish_disable_api_prefix` options.

Signed-off-by: James Knight <james.d.knight@live.com>
Adds a `rest` client attribute by default. This allows a user of this
class to invoke `disconnect` without having to have worried about first
invoking `connect`.

This change is primarily for debugging purposes, to avoid the chances of
throwing an attribute exception when a test's connect stage is unable to
be run (but a cleanup operation is invoked anyways).

Signed-off-by: James Knight <james.d.knight@live.com>
Updating the logic to find ancestors to use the REST API v2 when
configured for a 'v2' API mode.

Signed-off-by: James Knight <james.d.knight@live.com>
Updating a select number of calls that perform a single page fetch
(using an ID) to use the REST API v2 when configured for a 'v2' API
mode.

This commit only updates a few cases. There will need to be some
plumbing fixes to address other page fetches where originally we could
also request ancestor/labels/etc., but now looks to require separate
calls.

Signed-off-by: James Knight <james.d.knight@live.com>
Updates adding prefixes into the publisher [1] failed to update the put
call used to update a space's homepage; correcting.

[1]: d920ee7

Signed-off-by: James Knight <james.d.knight@live.com>
Confluence's original REST API provided results-based responses that
include a `size` and `limit` fields. For Confluence v2 API calls, such
fields do not exist and can be inferred by using the requested limit and
the size of the results array. Updating all API calls to drop the use of
`size` and `limit` fields to provide flexibility no matter what version
of API is used.

Signed-off-by: James Knight <james.d.knight@live.com>
Updating the calls which fetch attachment data to support both API v1
and v2.

Signed-off-by: James Knight <james.d.knight@live.com>
Support the ability to retry the deletion an attachment if a transaction
failure is detected (in the same manner done if a page delete failed).

Signed-off-by: James Knight <james.d.knight@live.com>
Updating the calls which delete pages and attachments to support both
API v1 and v2.

Signed-off-by: James Knight <james.d.knight@live.com>
Signed-off-by: James Knight <james.d.knight@live.com>
Perform a little refactoring where we manage un-watch updates from
creating/updating a space into a specific call, and adjust the page
update events to call this post-action method.

Signed-off-by: James Knight <james.d.knight@live.com>
Reworking this extension's property key usage when storing
extension-specific data on Confluence pages. This update provides
support for both v1 and v2 REST APIs.

These changes also perform two minor changes:

- The property key name has been changed from `sphinx` to
   `sphinxcontrib.confluencebuilder`, to ensure a unique ID for this
   extension.
- Hash caching on pages was only applied to generic page store calls,
   but not when a store call was made to a specific base ID. Updating
   the implementation to process hash tracking the same in both calls.

Signed-off-by: James Knight <james.d.knight@live.com>
When a request to `get_base_page_id` results in using a page title to
find the base page, it did so using a custom REST call in the method.
However, a call to `get_page` would achieve the same results.
Refactoring the call to use `get_page` to simplify the implementation.

Signed-off-by: James Knight <james.d.knight@live.com>
Adds the final implementation to drop the use of deprecated API v1 calls
(on Confluence Cloud) to use v2 API calls instead. This does perform
some major tweaks to the page fetch and update calls, where certain
actions such as ancestor and label processing needing to be performed
in their own requests.

Signed-off-by: James Knight <james.d.knight@live.com>
Changes have been made to the base page processing to ensure a hash
value is cached in its properties. Updating the publish check calls to
included expected requests/responses that would now be generated from
this change.

Signed-off-by: James Knight <james.d.knight@live.com>
When performing validation testing, force enable deprecated API checks
to inform developers if a used API call is deprecated sooner than later.

Signed-off-by: James Knight <james.d.knight@live.com>
@jdknight jdknight changed the title Draft: Support REST v2 API Calls Support REST v2 API Calls Mar 18, 2024
@jdknight
Copy link
Member Author

A lot of changes.

Unit testing does pass, but we do not have 100% coverage. Testing perform with a validation run with Confluence Cloud appears to work. In addition, running some manual Sphinx documentation publish runs targeting Cloud and Server appear to work as well. Will attempt to perform more testing before we make a v2.5 release; and maybe others who use the main branch can report any issues from these new changes.

@jdknight jdknight merged commit 727366a into main Mar 18, 2024
30 checks passed
@jdknight jdknight deleted the support-v2-api branch March 18, 2024 00:36
@jdknight jdknight removed their assignment Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant