Skip to content

Commit

Permalink
Merge pull request #106 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 0.2.1
  • Loading branch information
andyone authored Dec 28, 2024
2 parents c09a48e + 15483df commit 8fe3fff
Show file tree
Hide file tree
Showing 19 changed files with 240 additions and 207 deletions.
11 changes: 0 additions & 11 deletions .codebeatsettings

This file was deleted.

6 changes: 3 additions & 3 deletions .docker/alpine.docker
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## REGISTRY CONFIGURATION ######################################################

ARG REGISTRY="docker.io"
ARG REGISTRY="ghcr.io"

## BUILDER #####################################################################

FROM ${REGISTRY}/essentialkaos/golang:alpine3.18 as builder
FROM ${REGISTRY}/essentialkaos/golang:alpine3.20 as builder

WORKDIR /go/src/github.com/essentialkaos/atlassian-cloud-backuper

Expand All @@ -14,7 +14,7 @@ RUN make deps && make all

## FINAL IMAGE #################################################################

FROM ${REGISTRY}/essentialkaos/alpine:3.18
FROM ${REGISTRY}/essentialkaos/alpine:3.20

LABEL org.opencontainers.image.title="atlassian-cloud-backuper" \
org.opencontainers.image.description="Atlassian Cloud Backuper" \
Expand Down
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ updates:
schedule:
interval: "daily"
timezone: "Etc/UTC"
time: "07:00"
time: "03:00"
labels:
- "PR • MAINTENANCE"
assignees:
Expand All @@ -27,7 +27,7 @@ updates:
schedule:
interval: "daily"
timezone: "Etc/UTC"
time: "08:00"
time: "03:00"
labels:
- "PR • MAINTENANCE"
assignees:
Expand Down
2 changes: 1 addition & 1 deletion .github/images/card.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################

# This Makefile generated by GoMakeGen 3.1.0 using next command:
# This Makefile generated by GoMakeGen 3.2.3 using next command:
# gomakegen --mod .
#
# More info: https://kaos.sh/gomakegen
Expand All @@ -15,7 +15,12 @@ ifdef PROXY ## Force proxy usage for downloading dependencies (Flag)
export GOPROXY=https://proxy.golang.org/cached-only,direct
endif

COMPAT ?= 1.19
ifdef CGO ## Enable CGO usage (Flag)
export CGO_ENABLED=1
else
export CGO_ENABLED=0
endif

MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD)

Expand Down Expand Up @@ -49,19 +54,22 @@ update: mod-update ## Update dependencies to the latest versions
vendor: mod-vendor ## Make vendored copy of dependencies

mod-init:
@echo "[1/2] Modules initialization…"
@echo "[1/3] Modules initialization…"
@rm -f go.mod go.sum
ifdef MODULE_PATH ## Module path for initialization (String)
@go mod init $(MODULE_PATH)
else
@go mod init
endif

@echo "[37m[2/2][0m [36;1mDependencies cleanup…[0m"
@echo "[37m[2/3][0m [36;1mDependencies cleanup…[0m"
ifdef COMPAT ## Compatible Go version (String)
@go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT)
else
@go mod tidy $(VERBOSE_FLAG)
endif
@echo "[3/3] Stripping toolchain info…"
@grep -q 'toolchain ' go.mod && go mod edit -toolchain=none || :

mod-update:
@echo "[1/4] Updating dependencies…"
Expand Down Expand Up @@ -111,8 +119,9 @@ help: ## Show this info
@echo -e '\n\033[1mVariables:\033[0m\n'
@grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \
| sed 's/ifdef //' \
| sort -h \
| awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}'
@echo -e ''
@echo -e '\033[90mGenerated by GoMakeGen 3.1.0\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 3.2.3\033[0m\n'

################################################################################
113 changes: 62 additions & 51 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"os"
"strings"

"github.com/essentialkaos/ek/v13/errutil"
"github.com/essentialkaos/ek/v13/errors"
"github.com/essentialkaos/ek/v13/fmtc"
"github.com/essentialkaos/ek/v13/knf"
"github.com/essentialkaos/ek/v13/log"
Expand Down Expand Up @@ -42,7 +42,7 @@ import (
// Basic utility info
const (
APP = "Atlassian Cloud Backuper"
VER = "0.2.0"
VER = "0.2.1"
DESC = "Tool for backuping Atlassian cloud services (Jira and Confluence)"
)

Expand Down Expand Up @@ -96,7 +96,7 @@ const (
LOG_DIR = "log:dir"
LOG_FILE = "log:file"
LOG_FORMAT = "log:format"
LOG_MODE = "log:perms"
LOG_MODE = "log:mode"
LOG_LEVEL = "log:level"
)

Expand Down Expand Up @@ -147,7 +147,7 @@ func Run(gitRev string, gomod []byte) {

if !errs.IsEmpty() {
terminal.Error("Options parsing errors:")
terminal.Error(errs.String())
terminal.Error(errs.Error(" - "))
os.Exit(1)
}

Expand Down Expand Up @@ -178,7 +178,7 @@ func Run(gitRev string, gomod []byte) {
os.Exit(0)
}

err := errutil.Chain(
err := errors.Chain(
loadConfig,
validateConfig,
setupLogger,
Expand All @@ -192,7 +192,7 @@ func Run(gitRev string, gomod []byte) {
log.Divider()
log.Aux("%s %s starting…", APP, VER)

err = errutil.Chain(
err = errors.Chain(
setupTemp,
setupReq,
)
Expand All @@ -202,6 +202,8 @@ func Run(gitRev string, gomod []byte) {
os.Exit(1)
}

defer temp.Clean()

if options.GetB(OPT_SERVER) {
err = startServer()
} else {
Expand Down Expand Up @@ -300,66 +302,71 @@ func loadConfig() error {

// validateConfig validates configuration file values
func validateConfig() error {
validators := []*knf.Validator{
validators := knf.Validators{
{ACCESS_ACCOUNT, knfv.Set, nil},
{ACCESS_EMAIL, knfv.Set, nil},
{ACCESS_API_KEY, knfv.Set, nil},
{ACCESS_EMAIL, knfn.Mail, nil},
{STORAGE_TYPE, knfv.SetToAnyIgnoreCase, []string{
STORAGE_FS, STORAGE_SFTP, STORAGE_S3,
}},
{TEMP_DIR, knff.Perms, "DWRX"},
{LOG_FORMAT, knfv.SetToAnyIgnoreCase, []string{
"", "text", "json",
}},
{LOG_LEVEL, knfv.SetToAnyIgnoreCase, []string{
"", "debug", "info", "warn", "error", "crit",
}},
{TEMP_DIR, knff.Perms, "DWX"},
{LOG_LEVEL, knfv.SetToAnyIgnoreCase, log.Levels()},
}

switch strings.ToLower(knfu.GetS(STORAGE_TYPE)) {
case STORAGE_FS:
validators = append(validators,
&knf.Validator{STORAGE_FS_PATH, knff.Perms, "DRW"},
)
validators = validators.AddIf(
knfu.GetS(STORAGE_TYPE) == STORAGE_FS,
knf.Validators{
{STORAGE_FS_PATH, knff.Perms, "DRW"},
},
)

case STORAGE_SFTP:
validators = append(validators,
&knf.Validator{STORAGE_SFTP_HOST, knfv.Set, nil},
&knf.Validator{STORAGE_SFTP_USER, knfv.Set, nil},
&knf.Validator{STORAGE_SFTP_KEY, knfv.Set, nil},
&knf.Validator{STORAGE_SFTP_PATH, knfv.Set, nil},
)
validators = validators.AddIf(
knfu.GetS(STORAGE_TYPE) == STORAGE_SFTP,
knf.Validators{
{STORAGE_SFTP_HOST, knfv.Set, nil},
{STORAGE_SFTP_USER, knfv.Set, nil},
{STORAGE_SFTP_KEY, knfv.Set, nil},
{STORAGE_SFTP_PATH, knfv.Set, nil},
},
)

case STORAGE_S3:
validators = append(validators,
&knf.Validator{STORAGE_S3_HOST, knfv.Set, nil},
&knf.Validator{STORAGE_S3_ACCESS_KEY, knfv.Set, nil},
&knf.Validator{STORAGE_S3_SECRET_KEY, knfv.Set, nil},
&knf.Validator{STORAGE_S3_BUCKET, knfv.Set, nil},
&knf.Validator{STORAGE_S3_PART_SIZE, knfv.Greater, 5},
&knf.Validator{STORAGE_S3_PART_SIZE, knfv.Less, 5_000},
)
}
validators = validators.AddIf(
knfu.GetS(STORAGE_TYPE) == STORAGE_S3,
knf.Validators{
{STORAGE_S3_HOST, knfv.Set, nil},
{STORAGE_S3_ACCESS_KEY, knfv.Set, nil},
{STORAGE_S3_SECRET_KEY, knfv.Set, nil},
{STORAGE_S3_BUCKET, knfv.Set, nil},
{STORAGE_S3_PART_SIZE, knfv.TypeSize, nil},
{STORAGE_S3_PART_SIZE, knfv.SizeGreater, 1 * 1024 * 1024},
{STORAGE_S3_PART_SIZE, knfv.SizeLess, 100 * 1024 * 1024},
},
)

if options.GetB(OPT_SERVER) {
validators = append(validators,
&knf.Validator{SERVER_IP, knfn.IP, nil},
&knf.Validator{SERVER_PORT, knfn.Port, nil},
)
}
validators = validators.AddIf(
options.GetB(OPT_SERVER),
knf.Validators{
{SERVER_IP, knfn.IP, nil},
{SERVER_PORT, knfn.Port, nil},
},
)

if knfu.GetS(STORAGE_ENCRYPTION_KEY) != "" {
validators = append(validators,
&knf.Validator{STORAGE_ENCRYPTION_KEY, knfv.LenGreater, 16},
&knf.Validator{STORAGE_ENCRYPTION_KEY, knfv.LenLess, 96},
)
}
validators = validators.AddIf(
knfu.GetS(STORAGE_ENCRYPTION_KEY) != "",
knf.Validators{
{STORAGE_ENCRYPTION_KEY, knfv.LenGreater, 16},
{STORAGE_ENCRYPTION_KEY, knfv.LenLess, 96},
},
)

errs := knfu.Validate(validators)

if len(errs) > 0 {
return errs[0]
if !errs.IsEmpty() {
return errs.First()
}

return nil
Expand All @@ -370,7 +377,7 @@ func setupLogger() error {
var err error

if knfu.GetS(LOG_FILE) != "" {
err = log.Set(knfu.GetS(LOG_FILE), knfu.GetM(LOG_MODE, 0640))
err = log.Set(knfu.GetS(LOG_FILE), knfu.GetM(LOG_MODE, 0644))

if err != nil {
return err
Expand Down Expand Up @@ -403,9 +410,13 @@ func setupLogger() error {
func setupTemp() error {
var err error

temp, err = tmp.NewTemp(knfu.GetS(TEMP_DIR, "/tmp"))
temp, err = tmp.NewTemp(knfu.GetS(TEMP_DIR, os.TempDir()))

return err
if err != nil {
return fmt.Errorf("Can't setup temporary data directory: %w", err)
}

return nil
}

// setupReq configures HTTP request engine
Expand Down Expand Up @@ -530,7 +541,7 @@ func genUsage(section string) *usage.Info {
addUnitedOption(info, STORAGE_S3_SECRET_KEY, "S3 access secret key", "key")
addUnitedOption(info, STORAGE_S3_BUCKET, "S3 bucket", "name")
addUnitedOption(info, STORAGE_S3_PATH, "Path for backups", "path")
addUnitedOption(info, STORAGE_S3_PART_SIZE, "Uploading part size (in MB)", "num")
addUnitedOption(info, STORAGE_S3_PART_SIZE, "Uploading part size", "size")
addUnitedOption(info, JIRA_OUTPUT_FILE, "Jira backup output file name template", "template")
addUnitedOption(info, JIRA_INCLUDE_ATTACHMENTS, "Include attachments to Jira backup", "yes/no")
addUnitedOption(info, JIRA_CLOUD_FORMAT, "Create Jira backup for Cloud", "yes/no")
Expand Down
2 changes: 1 addition & 1 deletion app/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func startApp(args options.Arguments) error {
addEventsHandlers(dispatcher)
}

if knfu.GetS(STORAGE_ENCRYPTION_KEY) != "" {
if knfu.GetS(STORAGE_ENCRYPTION_KEY) != "" && options.GetB(OPT_INTERACTIVE) {
fmtc.NewLine()
terminal.Warn("▲ Backup will be encrypted while uploading. You will not be able to use the")
terminal.Warn(" backup if you lose the encryption key. Keep it in a safe place.")
Expand Down
2 changes: 1 addition & 1 deletion app/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func getUploader(target string) (uploader.Uploader, error) {
SecretKey: knfu.GetS(STORAGE_S3_SECRET_KEY),
Bucket: knfu.GetS(STORAGE_S3_BUCKET),
Path: path.Join(knfu.GetS(STORAGE_S3_PATH), target),
PartSize: knfu.GetI64(STORAGE_S3_PART_SIZE, 32),
PartSize: knfu.GetSZ(STORAGE_S3_PART_SIZE, 5*1024*1024),
})
}

Expand Down
27 changes: 12 additions & 15 deletions backuper/confluence/confluence-backuper.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,9 @@ func (b *ConfluenceBackuper) GetReader(backupFile string) (io.ReadCloser, error)
log.Debug("Downloading file from %s", backupFileURL)

resp, err := req.Request{
URL: backupFileURL,
BasicAuthUsername: b.config.Email,
BasicAuthPassword: b.config.APIKey,
AutoDiscard: true,
URL: backupFileURL,
Auth: req.AuthBasic{b.config.Email, b.config.APIKey},
AutoDiscard: true,
}.Get()

if err != nil {
Expand All @@ -245,11 +244,10 @@ func (b *ConfluenceBackuper) GetReader(backupFile string) (io.ReadCloser, error)
// startBackup starts backup process
func (b *ConfluenceBackuper) startBackup() error {
resp, err := req.Request{
URL: b.config.AccountURL() + "/wiki/rest/obm/1.0/runbackup",
BasicAuthUsername: b.config.Email,
BasicAuthPassword: b.config.APIKey,
Accept: req.CONTENT_TYPE_JSON,
ContentType: req.CONTENT_TYPE_JSON,
URL: b.config.AccountURL() + "/wiki/rest/obm/1.0/runbackup",
Auth: req.AuthBasic{b.config.Email, b.config.APIKey},
Accept: req.CONTENT_TYPE_JSON,
ContentType: req.CONTENT_TYPE_JSON,
Body: &BackupPrefs{
WithAttachments: b.config.WithAttachments,
ForCloud: b.config.ForCloud,
Expand All @@ -270,12 +268,11 @@ func (b *ConfluenceBackuper) startBackup() error {
// getBackupProgress returns backup progress info
func (b *ConfluenceBackuper) getBackupProgress() (*BackupProgressInfo, error) {
resp, err := req.Request{
URL: b.config.AccountURL() + "/wiki/rest/obm/1.0/getprogress",
BasicAuthUsername: b.config.Email,
BasicAuthPassword: b.config.APIKey,
Accept: req.CONTENT_TYPE_JSON,
ContentType: req.CONTENT_TYPE_JSON,
AutoDiscard: true,
URL: b.config.AccountURL() + "/wiki/rest/obm/1.0/getprogress",
Auth: req.AuthBasic{b.config.Email, b.config.APIKey},
Accept: req.CONTENT_TYPE_JSON,
ContentType: req.CONTENT_TYPE_JSON,
AutoDiscard: true,
}.Get()

if err != nil {
Expand Down
Loading

0 comments on commit 8fe3fff

Please sign in to comment.