asy

package module
v1.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2022 License: MIT Imports: 10 Imported by: 1

README

apollo-synchronizer

Help developer to sync between local file and remote apollo portal web since portal web is so messy to use

Features
  • download namespaces into local directory.
  • synchronize local files to remote apollo portal web.
  • use terminal ui to display synchronization information.
  • apply force and overwrite flag
  • maybe some customize filter to dismiss some file/namespace?
  • GUI support for better user experience. README
Quick start
go install github.com/yeqown/apollo-synchronizer/cmd/asy@latest
Usage
# synchronize between one app in apollo with local file system.
$ asy -h
NAME:
   apollo-synchronizer - A new cli application

USAGE:
   asy [global options] command [command options] [arguments...]

VERSION:
   v1.2.0

DESCRIPTION:
   To help developers synchronize between apollo portal and local filesystem.

AUTHOR:
   yeqown <yeqown@gmail.com>

COMMANDS:
   tool     To help developers create, delete and read resources from apollo portal.
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --up                       upload to apollo portal with local filesystem (default: false)
   --down                     download from apollo portal (default: true)
   --force, -f                indicates whether to create the target while it not exists. (default: false)
   --overwrite                indicates whether asy update the target while it exists. (default: true)
   --enable-termui            use terminal ui to display and interact with instead of logs (default: false)
   --path value               specify the path to synchronize (default: /Users/med/.apollo-synchronizer)
   --apollo.portaladdr value  apollo portal address
   --apollo.appid value       the targeted remote app in apollo
   --apollo.secret value      api app`s token
   --apollo.account value     user id in apollo (default: apollo)
   --apollo.env value         the environment of target remote app (default: DEV)
   --apollo.cluster value     the cluster of target remote app (default: default)
   --auto-publish             enable auto publish apollo modified namespace. (default: false)
   --debug                    print debug logs (default: false)
   --help, -h                 show help (default: false)
   --version, -v              print the version (default: false)

demo:

# download configs from apollo [app=demo] [env=DEV] [cluster=default] 
./asy \
    --down \
    --debug \ 
    --force \
    --overwrite \
    --enable-termui \
    --path=./debugdata \
    --apollo.portaladdr=http://127.0.0.1:8070 \
    --apollo.appid=demo \
    --apollo.secret=82a95a5722ae8649f64ca5859a13032acab4b2a3

If synchronize the one [file/namespace] those not found in target place, asy will create one automatically if you use [-f] [--force] option.

Structure mapping
${FOLDER}       				= appID         // you can alse use `--appId` to specify.
├── filename.ext				= namespace.ext
├── ... more
└── service.yaml				= service.yaml
References

Documentation

Index

Constants

View Source
const (
	DiffMode_CREATE diffMode = "C+"
	DiffMode_MODIFY diffMode = "M~"
	DiffMode_DELETE diffMode = "D-"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Decide

type Decide uint8

Decide confirm synchronize or cancel.

const (
	Decide_UNKNOWN Decide = iota
	Decide_CONFIRMED
	Decide_CANCELLED
)

func (Decide) String

func (d Decide) String() string

type Diff0

type Diff0 struct {
	Key  string   `json:"key"`
	Mode diffMode `json:"mode"`
}

type Diff1

type Diff1 struct {
	Diff0

	AbsFilepath string `json:"absFilepath"`
}

type Renderer

type Renderer interface {
	// RenderingDiffs display the diffs and make a decision to control the synchronization
	// should go on or abort now.
	RenderingDiffs(diffs []Diff1) (d Decide, reason string)

	// RenderingResult display the result of synchronization.
	RenderingResult(results []*SynchronizeResult)
}

Renderer declares the display component which display some information.

type SynchronizeMode

type SynchronizeMode uint8
const (
	SynchronizeMode_UNKNOWN SynchronizeMode = iota
	SynchronizeMode_UPLOAD
	SynchronizeMode_DOWNLOAD
)

type SynchronizeResult

type SynchronizeResult struct {
	Key       string   `json:"key"`
	Mode      diffMode `json:"mode"`
	Error     string   `json:"error"`     // modified failed reason
	Succeeded bool     `json:"succeeded"` // modified Succeeded
	Published bool     `json:"published"` // changes Published
	Bytes     int      `json:"bytes"`     // file size (byte)
}

type SynchronizeScope

type SynchronizeScope struct {
	Mode SynchronizeMode
	// Path is the parent directory which holds all downloaded remote.
	// apollo.appId will be used as a subdirectory. [DOWNLOAD REQUIRED]
	Path string
	// LocalFiles represents the absolute file path of local files. [UPLOAD ONLY]
	LocalFiles []string

	ApolloSecret      string
	ApolloAppID       string
	ApolloEnv         string
	ApolloClusterName string
	ApolloPortalAddr  string
	ApolloAccount     string
	// ApolloAutoPublish indicates whether publish changes after uploaded
	// to apollo namespaces, it's disabled by default.
	ApolloAutoPublish bool

	// Overwrite indicates whether asy update the target while it exists.
	Overwrite bool
	// Force indicates whether to create the target while it not exists.
	Force bool

	// Render is an optional field which is used to render the process
	// and result of synchronization.
	Render Renderer
}

SynchronizeScope represents the context of Synchronizer.Synchronize.

func (SynchronizeScope) Valid

func (sc SynchronizeScope) Valid() error

type Synchronizer

type Synchronizer interface {
	Synchronize(ctx context.Context) ([]*SynchronizeResult, error)
}

Synchronizer 's duty is synchronizing between remote apollo portal and local filesystem.

func NewSynchronizer

func NewSynchronizer(scope *SynchronizeScope) (Synchronizer, error)

Directories

Path Synopsis
cmd
asy Module
pkg
fs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL