Wiki source code of conflcmd - Manage Confluence Content
Last modified by John on 2021/10/31 17:41
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{info title="Recent Highlights"}} | ||
2 | * Added page version count. | ||
3 | * Added page version delete. | ||
4 | {{/info}} | ||
5 | |||
6 | {{toc/}} | ||
7 | |||
8 | = Introduction = | ||
9 | |||
10 | 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). | ||
11 | |||
12 | = Usage = | ||
13 | |||
14 | {{noformat}} | ||
15 | usage: conflcmd [<options>] <serverurl> <cmd> [<args>] | ||
16 | |||
17 | Manage content on Confluence site. Unless indicated, if <path> is | ||
18 | "-", input is read from stdin. | ||
19 | |||
20 | Configuration files: | ||
21 | ~/.conflcmd/main.conf | ||
22 | Main configuration. | ||
23 | ~/.conflcmd/creds.conf | ||
24 | Credentials-only configuration. Note: should | ||
25 | only be readable by user. | ||
26 | |||
27 | Common options: | ||
28 | -p Load password from configuration file. | ||
29 | -P Ask for password. | ||
30 | -u <username> Account to use. | ||
31 | |||
32 | Commands: | ||
33 | add-attachment <spacekey> <pagename> <attachmentname> <path> <comment> | ||
34 | Add attachment. | ||
35 | |||
36 | create-page <spacekey> <parentpagename> <pagename> <path> | ||
37 | Create page. Set parentpagename to "" to create top-level page. | ||
38 | |||
39 | delete-attachment <spacekey> <pagename> <attachmentname> | ||
40 | Delete attachment. | ||
41 | |||
42 | delete-page <spacekey> <pagename> | ||
43 | Delete page. | ||
44 | |||
45 | delete-page-version <spacekey> <pagename> <versionrange> | ||
46 | Delete page versions (from page history). Version range is | ||
47 | inclusive and takes the form: <first>[-<last>]. | ||
48 | |||
49 | get-attachment <spacekey> <pagename> <attachmentname> | ||
50 | Get attachment. | ||
51 | |||
52 | get-page <spacekey> <pagename> | ||
53 | Get page contents. | ||
54 | |||
55 | get-page-version-count <spacekey> <pagename> | ||
56 | Get count of page versions (latest included). | ||
57 | |||
58 | get-page-view <spacekey> <pagename> | ||
59 | Get rendered page contents. | ||
60 | |||
61 | list-attachments <spacekey> <pagename> | ||
62 | List page attachments. | ||
63 | |||
64 | list-pages <spacekey> | ||
65 | List pages. | ||
66 | |||
67 | list-spaces | ||
68 | List space keys. | ||
69 | |||
70 | update-attachment <spacekey> <pagename> <attachmentname> <path> <comment> | ||
71 | Update existing attachment. | ||
72 | |||
73 | update-page <spacekey> <pagename> <path> <comment> | ||
74 | Update existing page. | ||
75 | {{/noformat}} | ||
76 | |||
77 | = Configuration = | ||
78 | |||
79 | All configuration files are under ~~/.conflcmd. The files are: | ||
80 | |||
81 | * main.conf - main configuration settings; not used at the moment. | ||
82 | * creds.conf - credentials; should be readable only by the user. | ||
83 | |||
84 | Ideally, the ~~/.conflcmd directory should be user-readable only. | ||
85 | |||
86 | == creds.conf == | ||
87 | |||
88 | The creds.conf file is meant to hold credentials information that should be kept "secure". | ||
89 | |||
90 | {{noformat}} | ||
91 | [<sectionname>] | ||
92 | url = <server url> | ||
93 | username = <username> | ||
94 | password = <password> | ||
95 | {{/noformat}} | ||
96 | |||
97 | Note: At the moment, the password is kept in clear text. So, make sure to keep that file user-readable only. | ||
98 | |||
99 | = Examples = | ||
100 | |||
101 | == Security == | ||
102 | |||
103 | 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. | ||
104 | |||
105 | With -P, a password will be asked for interactively. With -p, the password will be looked up in the configuration files. | ||
106 | |||
107 | For the creds.conf file: | ||
108 | |||
109 | {{noformat}} | ||
110 | [localhost] | ||
111 | url = https://localhost/confluence | ||
112 | username = john | ||
113 | password = 1234 | ||
114 | {{/noformat}} | ||
115 | |||
116 | Notes: | ||
117 | |||
118 | * The url must match the serverurl used in the call to conflcmd. | ||
119 | * The username must match the username used in the call to conflcmd. | ||
120 | |||
121 | == Listing and Getting == | ||
122 | |||
123 | List pages in space "TEST": | ||
124 | |||
125 | {{noformat}} | ||
126 | conflcmd https://localhost/confluence list-pages TEST | ||
127 | {{/noformat}} | ||
128 | |||
129 | Get page contents in space "TEST": | ||
130 | |||
131 | {{noformat}} | ||
132 | conflcmd https://localhost/confluence get-page TEST Test | ||
133 | {{/noformat}} | ||
134 | |||
135 | Get rendered page contents in space "TEST": | ||
136 | |||
137 | {{noformat}} | ||
138 | conflcmd https://localhost/confluence get-page-view TEST Test | ||
139 | {{/noformat}} | ||
140 | |||
141 | Get number of page versions: | ||
142 | |||
143 | {{noformat}} | ||
144 | conflcmd https://localhost/confluence get-page-version-count TEST Test | ||
145 | {{/noformat}} | ||
146 | |||
147 | == Creating and Updating == | ||
148 | |||
149 | Create a page in space "TEST": | ||
150 | |||
151 | {{noformat}} | ||
152 | conflcmd -u john -P https://localhost/confluence create-page TEST "" "Test2" test.html | ||
153 | {{/noformat}} | ||
154 | |||
155 | Notes: | ||
156 | |||
157 | * -u is used to specify the account to use. | ||
158 | * -P tells conflcmd to ask for the password (safer than putting it on the command line). | ||
159 | * Set parentpagename to "" to create a top-level page (i.e., not a child page). | ||
160 | * The content is taken from the test.html file. | ||
161 | |||
162 | Create a page as a child of another in space "TEST": | ||
163 | |||
164 | {{noformat}} | ||
165 | conflcmd -u john -P https://localhost/confluence create-page TEST "Test2" "Test3" test.html | ||
166 | {{/noformat}} | ||
167 | |||
168 | Update page "Hello" content in space "TEST": | ||
169 | |||
170 | {{noformat}} | ||
171 | conflcmd -u john -P https://localhost/confluence update-page TEST Hello hello.html "" | ||
172 | {{/noformat}} | ||
173 | |||
174 | Notes: | ||
175 | |||
176 | * The content is taken from the hello.html file. | ||
177 | * The change comment is empty "". | ||
178 | |||
179 | Update page using credentials in configuration file: | ||
180 | |||
181 | {{noformat}} | ||
182 | conflcmd -u john -p https://localhost/confluence update-page TEST Hello - "" | ||
183 | {{/noformat}} | ||
184 | |||
185 | Notes: | ||
186 | |||
187 | * The password is provided via the creds.conf file. | ||
188 | * The server url (https:~/~/localhost/confluence) must match a definition (url setting) in the creds.conf file. | ||
189 | |||
190 | Update page "Hello" content in space "TEST" from stdin: | ||
191 | |||
192 | {{noformat}} | ||
193 | echo "<h1>Hello</h1><p>Hey there!!!</p>" | conflcmd -u john -p https://localhost/confluence update-page TEST Hello - "" | ||
194 | {{/noformat}} | ||
195 | |||
196 | Update attachment on "Hello" page in space "TEST": | ||
197 | |||
198 | {{noformat}} | ||
199 | conflcmd -u john -p https://localhost/confluence update-attachment TEST Hello report.pdf new_report.pdf "" | ||
200 | {{/noformat}} | ||
201 | |||
202 | Notes: | ||
203 | |||
204 | * Attachment named report.pdf is being updated. | ||
205 | * The content is taken from new_report.pdf. | ||
206 | |||
207 | == Deleting == | ||
208 | |||
209 | Delete an attachment: | ||
210 | |||
211 | {{noformat}} | ||
212 | conflcmd -u jdm -p https://localhost/confluence delete-attachment TEST Hello report.pdf | ||
213 | {{/noformat}} | ||
214 | |||
215 | Delete a page: | ||
216 | |||
217 | {{noformat}} | ||
218 | conflcmd -u jdm -p https://localhost/confluence delete-page TEST Hello | ||
219 | {{/noformat}} | ||
220 | |||
221 | Notes: | ||
222 | |||
223 | * Attachments will follow the page; i.e., they will be deleted. | ||
224 | |||
225 | Delete a page version: | ||
226 | |||
227 | {{noformat}} | ||
228 | conflcmd -u jdm -p https://localhost/confluence delete-page version TEST Hello 1-10 | ||
229 | {{/noformat}} | ||
230 | |||
231 | Note: | ||
232 | |||
233 | * Versions 1 to 10 inclusively are deleted. |