Recent Highlights
  • Added page version count.
  • Added page version delete.

Introduction

conflcmd is a simple command-line tool that allows one to manage various Confluence content from the command line. conflcmd uses the REST API (Confluence 6.x).

Usage

usage: conflcmd [<options>] <serverurl> <cmd> [<args>]

Manage content on Confluence site. Unless indicated, if <path> is
"-", input is read from stdin.

Configuration files:
~/.conflcmd/main.conf
                    Main configuration.
~/.conflcmd/creds.conf
                    Credentials-only configuration. Note: should
                    only be readable by user.

Common options:
-p                  Load password from configuration file.
-P                  Ask for password.
-u <username>       Account to use.

Commands:
add-attachment <spacekey> <pagename> <attachmentname> <path> <comment>
    Add attachment.

create-page <spacekey> <parentpagename> <pagename> <path>
    Create page. Set parentpagename to "" to create top-level page.

delete-attachment <spacekey> <pagename> <attachmentname>
    Delete attachment.

delete-page <spacekey> <pagename>
    Delete page.

delete-page-version <spacekey> <pagename> <versionrange>
    Delete page versions (from page history). Version range is
    inclusive and takes the form: <first>[-<last>].

get-attachment <spacekey> <pagename> <attachmentname>
    Get attachment.

get-page <spacekey> <pagename>
    Get page contents.

get-page-version-count <spacekey> <pagename>
    Get count of page versions (latest included).

get-page-view <spacekey> <pagename>
    Get rendered page contents.

list-attachments <spacekey> <pagename>
    List page attachments.

list-pages <spacekey>
    List pages.

list-spaces
    List space keys.

update-attachment <spacekey> <pagename> <attachmentname> <path> <comment>
    Update existing attachment.

update-page <spacekey> <pagename> <path> <comment>
    Update existing page.

Configuration

All configuration files are under ~/.conflcmd. The files are:

  • main.conf - main configuration settings; not used at the moment.
  • creds.conf - credentials; should be readable only by the user.

Ideally, the ~/.conflcmd directory should be user-readable only.

creds.conf

The creds.conf file is meant to hold credentials information that should be kept "secure".

[<sectionname>]
url = <server url>
username = <username>
password = <password>

Note: At the moment, the password is kept in clear text. So, make sure to keep that file user-readable only.

Examples

Security

If access is restricted, use the -u to pass username and either -P, or better,  -p . This is usually required to create, delete, and update.

With -P, a password will be asked for interactively. With -p, the password will be looked up in the configuration files.

For the creds.conf file:

[localhost]
url = https://localhost/confluence
username = john
password = 1234

Notes:

  • The url must match the serverurl used in the call to conflcmd.
  • The username must match the username used in the call to conflcmd.

Listing and Getting

List pages in space "TEST":

conflcmd https://localhost/confluence list-pages TEST

Get page contents in space "TEST":

conflcmd https://localhost/confluence get-page TEST Test

Get rendered page contents in space "TEST":

conflcmd https://localhost/confluence get-page-view TEST Test

Get number of page versions:

conflcmd https://localhost/confluence get-page-version-count TEST Test

Creating and Updating

Create a page in space "TEST":

conflcmd -u john -P https://localhost/confluence create-page TEST "" "Test2" test.html

Notes:

  • -u is used to specify the account to use.
  • -P tells conflcmd to ask for the password (safer than putting it on the command line).
  • Set parentpagename to "" to create a top-level page (i.e., not a child page).
  • The content is taken from the test.html file.

Create a page as a child of another in space "TEST":

conflcmd -u john -P https://localhost/confluence create-page TEST "Test2" "Test3" test.html

Update page "Hello" content in space "TEST":

conflcmd -u john -P https://localhost/confluence update-page TEST Hello hello.html ""

Notes:

  • The content is taken from the hello.html file.
  • The change comment is empty "".

Update page using credentials in configuration file:

conflcmd -u john -p https://localhost/confluence update-page TEST Hello - ""

Notes:

  • The password is provided via the creds.conf file.
  • The server url (https://localhost/confluence) must match a definition (url setting) in the creds.conf file.

Update page "Hello" content in space "TEST" from stdin:

echo "<h1>Hello</h1><p>Hey there!!!</p>" | conflcmd -u john -p https://localhost/confluence update-page TEST Hello - ""

Update attachment on "Hello" page in space "TEST":

conflcmd -u john -p https://localhost/confluence update-attachment TEST Hello report.pdf new_report.pdf ""

Notes:

  • Attachment named report.pdf is being updated.
  • The content is taken from new_report.pdf.

Deleting

Delete an attachment:

conflcmd -u jdm -p https://localhost/confluence delete-attachment TEST Hello report.pdf

Delete a page:

conflcmd -u jdm -p https://localhost/confluence delete-page TEST Hello

Notes:

  • Attachments will follow the page; i.e., they will be deleted.

Delete a page version:

conflcmd -u jdm -p https://localhost/confluence delete-page version TEST Hello 1-10

Note:

  • Versions 1 to 10 inclusively are deleted.
Tags: confluence
    

Contact

About

Requirements

Python

License

BSD-3

Repository

https://bitbucket.org/johnmdev/conflcmd

Email

expldotinfo@gmail.com