Skip to content

Commit

Permalink
Issue-345 Added possibility to configure proxy for Confluence access
Browse files Browse the repository at this point in the history
  • Loading branch information
bit-jkraushaar committed Aug 22, 2019
1 parent 1279ee9 commit 8f63caf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,9 @@ confluence.with {
// added
// extraPageContent = '<ac:structured-macro ac:name="warning"><ac:parameter ac:name="title" /><ac:rich-text-body>This is a generated page, do not edit!</ac:rich-text-body></ac:structured-macro>
extraPageContent = ''

// Optional proxy configuration, only used to access Confluence
// schema supports http and https
// proxy = [host: 'my.proxy.com', port: 1234, schema: 'http']
}
//end::confluenceConfig[]
11 changes: 10 additions & 1 deletion scripts/asciidoc2confluence.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def uploadAttachment = { def pageId, String url, String fileName, String note ->
def api = new RESTClient(config.confluence.api)
//this fixes the encoding
api.encoderRegistry = new EncoderRegistry( charset: 'utf-8' )
if (config.confluence.proxy) {
api.setProxy(config.confluence.proxy.host, config.confluence.proxy.port, config.confluence.proxy.schema ?: 'http')
}

def headers = [
'Authorization': 'Basic ' + config.confluence.credentials,
Expand All @@ -138,6 +141,9 @@ def uploadAttachment = { def pageId, String url, String fileName, String note ->
}
} else {
http = new HTTPBuilder(config.confluence.api + 'content/' + pageId + '/child/attachment')
if (config.confluence.proxy) {
http.setProxy(config.confluence.proxy.host, config.confluence.proxy.port, config.confluence.proxy.schema ?: 'http')
}
}
if (http) {
http.request(Method.POST) { req ->
Expand Down Expand Up @@ -316,7 +322,7 @@ def parseBody = { body, anchors, pageAnchors ->
if(!src.startsWith("http")) {
def newUrl = baseUrl.toString().replaceAll('\\\\','/').replaceAll('/[^/]*$','/')+src
def fileName = java.net.URLDecoder.decode((src.tokenize('/')[-1]),"UTF-8")
newUrl = java.net.URLDecoder.decode(newUrl,"UTF-8")
newUrl = java.net.URLDecoder.decode(newUrl,"UTF-8")

trythis {
deferredUpload << [0,newUrl,fileName,"automatically uploaded"]
Expand Down Expand Up @@ -356,6 +362,9 @@ def pushToConfluence = { pageTitle, pageBody, parentId, anchors, pageAnchors ->
]
//this fixes the encoding
api.encoderRegistry = new EncoderRegistry( charset: 'utf-8' )
if (config.confluence.proxy) {
api.setProxy(config.confluence.proxy.host, config.confluence.proxy.port, config.confluence.proxy.schema ?: 'http')
}
//try to get an existing page
localPage = parseBody(pageBody, anchors, pageAnchors)

Expand Down
3 changes: 3 additions & 0 deletions src/docs/manual/03_task_publishToConfluence.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ e.g. you can do things like `credentials = "user:${new File("/home/me/apitoken")
extraPageContent::
If you need to prefix you pages with a warning that this is generated content - this is the right place.

proxy::
If you need to provide a proxy to access Confluence, you may set a map with keys `host` (e.g. `'my.proxy.com'`), `port` (e.g. `'1234'`) and `schema` (e.g. `'http'`) of your proxy.

.configuration
.publishToConfluence.gradle
[source,groovy]
Expand Down

0 comments on commit 8f63caf

Please sign in to comment.