mirror of
https://github.com/kovetskiy/mark.git
synced 2025-04-24 05:42:40 +08:00
feat: Add support of confluence server. (#154)
This commit is contained in:
parent
49eb97b434
commit
c8709eecd1
6
auth.go
6
auth.go
@ -31,12 +31,6 @@ func GetCredentials(
|
|||||||
|
|
||||||
if username == "" {
|
if username == "" {
|
||||||
username = config.Username
|
username = config.Username
|
||||||
if username == "" {
|
|
||||||
return nil, errors.New(
|
|
||||||
"Confluence username should be specified using -u " +
|
|
||||||
"flag or be stored in configuration file",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if password == "" {
|
if password == "" {
|
||||||
|
6
main.go
6
main.go
@ -39,7 +39,7 @@ type Flags struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
version = "7.0"
|
version = "7.1"
|
||||||
usage = `mark - a tool for updating Atlassian Confluence pages from markdown.
|
usage = `mark - a tool for updating Atlassian Confluence pages from markdown.
|
||||||
|
|
||||||
Docs: https://github.com/kovetskiy/mark
|
Docs: https://github.com/kovetskiy/mark
|
||||||
@ -53,7 +53,9 @@ Usage:
|
|||||||
Options:
|
Options:
|
||||||
-u <username> Use specified username for updating Confluence page.
|
-u <username> Use specified username for updating Confluence page.
|
||||||
-p <token> Use specified token for updating Confluence page.
|
-p <token> Use specified token for updating Confluence page.
|
||||||
Specify - as password to read password from stdin.
|
Specify - as password to read password from stdin, or your Personal access token.
|
||||||
|
Username is not mandatory if personal access token is provided.
|
||||||
|
For more info please see: https://developer.atlassian.com/server/confluence/confluence-server-rest-api/#authentication.
|
||||||
-l <url> Edit specified Confluence page.
|
-l <url> Edit specified Confluence page.
|
||||||
If -l is not specified, file should contain metadata (see
|
If -l is not specified, file should contain metadata (see
|
||||||
above).
|
above).
|
||||||
|
@ -88,9 +88,18 @@ func (tracer *tracer) Printf(format string, args ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewAPI(baseURL string, username string, password string) *API {
|
func NewAPI(baseURL string, username string, password string) *API {
|
||||||
auth := &gopencils.BasicAuth{username, password}
|
var auth *gopencils.BasicAuth
|
||||||
|
if username != "" {
|
||||||
|
auth = &gopencils.BasicAuth{username, password}
|
||||||
|
}
|
||||||
rest := gopencils.Api(baseURL+"/rest/api", auth)
|
rest := gopencils.Api(baseURL+"/rest/api", auth)
|
||||||
|
if username == "" {
|
||||||
|
if rest.Headers == nil {
|
||||||
|
rest.Headers = http.Header{}
|
||||||
|
}
|
||||||
|
rest.SetHeader("Authorization", fmt.Sprintf("Bearer %s", password))
|
||||||
|
}
|
||||||
|
|
||||||
json := gopencils.Api(
|
json := gopencils.Api(
|
||||||
baseURL+"/rpc/json-rpc/confluenceservice-v2",
|
baseURL+"/rpc/json-rpc/confluenceservice-v2",
|
||||||
auth,
|
auth,
|
||||||
@ -218,7 +227,11 @@ func (api *API) CreateAttachment(
|
|||||||
)
|
)
|
||||||
|
|
||||||
resource.Payload = form.buffer
|
resource.Payload = form.buffer
|
||||||
|
oldHeaders := resource.Headers.Clone()
|
||||||
resource.Headers = http.Header{}
|
resource.Headers = http.Header{}
|
||||||
|
if resource.Api.BasicAuth == nil {
|
||||||
|
resource.Headers.Set("Authorization", oldHeaders.Get("Authorization"))
|
||||||
|
}
|
||||||
|
|
||||||
resource.SetHeader("Content-Type", form.writer.FormDataContentType())
|
resource.SetHeader("Content-Type", form.writer.FormDataContentType())
|
||||||
resource.SetHeader("X-Atlassian-Token", "no-check")
|
resource.SetHeader("X-Atlassian-Token", "no-check")
|
||||||
@ -284,7 +297,11 @@ func (api *API) UpdateAttachment(
|
|||||||
)
|
)
|
||||||
|
|
||||||
resource.Payload = form.buffer
|
resource.Payload = form.buffer
|
||||||
|
oldHeaders := resource.Headers.Clone()
|
||||||
resource.Headers = http.Header{}
|
resource.Headers = http.Header{}
|
||||||
|
if resource.Api.BasicAuth == nil {
|
||||||
|
resource.Headers.Set("Authorization", oldHeaders.Get("Authorization"))
|
||||||
|
}
|
||||||
|
|
||||||
resource.SetHeader("Content-Type", form.writer.FormDataContentType())
|
resource.SetHeader("Content-Type", form.writer.FormDataContentType())
|
||||||
resource.SetHeader("X-Atlassian-Token", "no-check")
|
resource.SetHeader("X-Atlassian-Token", "no-check")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user