working commit
This commit is contained in:
@@ -16,3 +16,8 @@ tmp
|
|||||||
mstored
|
mstored
|
||||||
mstorectl
|
mstorectl
|
||||||
DIST
|
DIST
|
||||||
|
*.tar.gz
|
||||||
|
*.deb
|
||||||
|
*.rpm
|
||||||
|
mstored.service
|
||||||
|
variant.go
|
||||||
|
|||||||
+12
-1
@@ -29,6 +29,7 @@ CWD=$(shell pwd)
|
|||||||
EXTRA_mstored_SOURCES = \
|
EXTRA_mstored_SOURCES = \
|
||||||
app/config/config.go \
|
app/config/config.go \
|
||||||
app/config/variant.go \
|
app/config/variant.go \
|
||||||
|
\
|
||||||
app/descr/account.go \
|
app/descr/account.go \
|
||||||
app/descr/blob.go \
|
app/descr/blob.go \
|
||||||
app/descr/file.go \
|
app/descr/file.go \
|
||||||
@@ -36,6 +37,7 @@ EXTRA_mstored_SOURCES = \
|
|||||||
app/descr/manifest.go \
|
app/descr/manifest.go \
|
||||||
app/descr/response.go \
|
app/descr/response.go \
|
||||||
app/descr/server.go \
|
app/descr/server.go \
|
||||||
|
\
|
||||||
app/handler/aaafunc.go \
|
app/handler/aaafunc.go \
|
||||||
app/handler/account.go \
|
app/handler/account.go \
|
||||||
app/handler/blob.go \
|
app/handler/blob.go \
|
||||||
@@ -48,6 +50,7 @@ EXTRA_mstored_SOURCES = \
|
|||||||
app/handler/service.go \
|
app/handler/service.go \
|
||||||
app/handler/version.go \
|
app/handler/version.go \
|
||||||
app/logger/logger.go \
|
app/logger/logger.go \
|
||||||
|
\
|
||||||
app/maindb/account.go \
|
app/maindb/account.go \
|
||||||
app/maindb/blob.go \
|
app/maindb/blob.go \
|
||||||
app/maindb/file.go \
|
app/maindb/file.go \
|
||||||
@@ -56,6 +59,7 @@ EXTRA_mstored_SOURCES = \
|
|||||||
app/maindb/maindb.go \
|
app/maindb/maindb.go \
|
||||||
app/maindb/manifest.go \
|
app/maindb/manifest.go \
|
||||||
app/maindb/scheme.go \
|
app/maindb/scheme.go \
|
||||||
|
\
|
||||||
app/operator/account.go \
|
app/operator/account.go \
|
||||||
app/operator/blob.go \
|
app/operator/blob.go \
|
||||||
app/operator/file.go \
|
app/operator/file.go \
|
||||||
@@ -73,9 +77,11 @@ EXTRA_mstored_SOURCES = \
|
|||||||
app/router/pathc.go \
|
app/router/pathc.go \
|
||||||
app/router/recovermw.go \
|
app/router/recovermw.go \
|
||||||
app/router/router.go \
|
app/router/router.go \
|
||||||
|
\
|
||||||
app/server/server.go \
|
app/server/server.go \
|
||||||
app/service/service.go \
|
app/service/service.go \
|
||||||
app/storage/storage.go \
|
app/storage/storage.go \
|
||||||
|
\
|
||||||
pkg/auxhttp/basic.go \
|
pkg/auxhttp/basic.go \
|
||||||
pkg/auxhttp/crange.go \
|
pkg/auxhttp/crange.go \
|
||||||
pkg/auxoci/ociaux.go \
|
pkg/auxoci/ociaux.go \
|
||||||
@@ -107,15 +113,18 @@ EXTRA_DIST = \
|
|||||||
go.sum \
|
go.sum \
|
||||||
LICENSE.txt \
|
LICENSE.txt \
|
||||||
README.md \
|
README.md \
|
||||||
|
\
|
||||||
app/logger/logger_test.go \
|
app/logger/logger_test.go \
|
||||||
app/maindb/file_test.go \
|
app/maindb/file_test.go \
|
||||||
app/maindb/grant_test.go \
|
app/maindb/grant_test.go \
|
||||||
app/router/pathc_test.go \
|
app/router/pathc_test.go \
|
||||||
app/router/router_test.go \
|
app/router/router_test.go \
|
||||||
|
\
|
||||||
pkg/auxpwd/passwd_test.go \
|
pkg/auxpwd/passwd_test.go \
|
||||||
pkg/auxx509/x509cert_test.go \
|
pkg/auxx509/x509cert_test.go \
|
||||||
attic/account_test.go \
|
attic/account_test.go \
|
||||||
attic/file_test.go \
|
attic/file_test.go \
|
||||||
|
\
|
||||||
chart/Chart.yaml.in \
|
chart/Chart.yaml.in \
|
||||||
chart/.gitignore \
|
chart/.gitignore \
|
||||||
chart/.helmignore \
|
chart/.helmignore \
|
||||||
@@ -129,10 +138,10 @@ EXTRA_DIST = \
|
|||||||
chart/templates/_userpass.tpl \
|
chart/templates/_userpass.tpl \
|
||||||
chart/templates/volumeclaim.yaml \
|
chart/templates/volumeclaim.yaml \
|
||||||
chart/values.yaml.in \
|
chart/values.yaml.in \
|
||||||
|
\
|
||||||
debian/changelog.in \
|
debian/changelog.in \
|
||||||
debian/compat \
|
debian/compat \
|
||||||
debian/control.in \
|
debian/control.in \
|
||||||
debian/debhelper-build-stamp \
|
|
||||||
debian/files \
|
debian/files \
|
||||||
debian/.gitignore \
|
debian/.gitignore \
|
||||||
debian/mstore-control.install \
|
debian/mstore-control.install \
|
||||||
@@ -151,9 +160,11 @@ EXTRA_DIST = \
|
|||||||
debian/source/format \
|
debian/source/format \
|
||||||
debian/source/include-binaries \
|
debian/source/include-binaries \
|
||||||
debian/watch \
|
debian/watch \
|
||||||
|
\
|
||||||
initrc/.gitignore \
|
initrc/.gitignore \
|
||||||
initrc/mstored.in \
|
initrc/mstored.in \
|
||||||
initrc/mstored.service.in \
|
initrc/mstored.service.in \
|
||||||
|
\
|
||||||
test/account_test.go \
|
test/account_test.go \
|
||||||
test/file_test.go \
|
test/file_test.go \
|
||||||
test/image_test.go \
|
test/image_test.go \
|
||||||
|
|||||||
+12
-1
@@ -317,6 +317,7 @@ CWD = $(shell pwd)
|
|||||||
EXTRA_mstored_SOURCES = \
|
EXTRA_mstored_SOURCES = \
|
||||||
app/config/config.go \
|
app/config/config.go \
|
||||||
app/config/variant.go \
|
app/config/variant.go \
|
||||||
|
\
|
||||||
app/descr/account.go \
|
app/descr/account.go \
|
||||||
app/descr/blob.go \
|
app/descr/blob.go \
|
||||||
app/descr/file.go \
|
app/descr/file.go \
|
||||||
@@ -324,6 +325,7 @@ EXTRA_mstored_SOURCES = \
|
|||||||
app/descr/manifest.go \
|
app/descr/manifest.go \
|
||||||
app/descr/response.go \
|
app/descr/response.go \
|
||||||
app/descr/server.go \
|
app/descr/server.go \
|
||||||
|
\
|
||||||
app/handler/aaafunc.go \
|
app/handler/aaafunc.go \
|
||||||
app/handler/account.go \
|
app/handler/account.go \
|
||||||
app/handler/blob.go \
|
app/handler/blob.go \
|
||||||
@@ -336,6 +338,7 @@ EXTRA_mstored_SOURCES = \
|
|||||||
app/handler/service.go \
|
app/handler/service.go \
|
||||||
app/handler/version.go \
|
app/handler/version.go \
|
||||||
app/logger/logger.go \
|
app/logger/logger.go \
|
||||||
|
\
|
||||||
app/maindb/account.go \
|
app/maindb/account.go \
|
||||||
app/maindb/blob.go \
|
app/maindb/blob.go \
|
||||||
app/maindb/file.go \
|
app/maindb/file.go \
|
||||||
@@ -344,6 +347,7 @@ EXTRA_mstored_SOURCES = \
|
|||||||
app/maindb/maindb.go \
|
app/maindb/maindb.go \
|
||||||
app/maindb/manifest.go \
|
app/maindb/manifest.go \
|
||||||
app/maindb/scheme.go \
|
app/maindb/scheme.go \
|
||||||
|
\
|
||||||
app/operator/account.go \
|
app/operator/account.go \
|
||||||
app/operator/blob.go \
|
app/operator/blob.go \
|
||||||
app/operator/file.go \
|
app/operator/file.go \
|
||||||
@@ -361,9 +365,11 @@ EXTRA_mstored_SOURCES = \
|
|||||||
app/router/pathc.go \
|
app/router/pathc.go \
|
||||||
app/router/recovermw.go \
|
app/router/recovermw.go \
|
||||||
app/router/router.go \
|
app/router/router.go \
|
||||||
|
\
|
||||||
app/server/server.go \
|
app/server/server.go \
|
||||||
app/service/service.go \
|
app/service/service.go \
|
||||||
app/storage/storage.go \
|
app/storage/storage.go \
|
||||||
|
\
|
||||||
pkg/auxhttp/basic.go \
|
pkg/auxhttp/basic.go \
|
||||||
pkg/auxhttp/crange.go \
|
pkg/auxhttp/crange.go \
|
||||||
pkg/auxoci/ociaux.go \
|
pkg/auxoci/ociaux.go \
|
||||||
@@ -395,15 +401,18 @@ EXTRA_DIST = \
|
|||||||
go.sum \
|
go.sum \
|
||||||
LICENSE.txt \
|
LICENSE.txt \
|
||||||
README.md \
|
README.md \
|
||||||
|
\
|
||||||
app/logger/logger_test.go \
|
app/logger/logger_test.go \
|
||||||
app/maindb/file_test.go \
|
app/maindb/file_test.go \
|
||||||
app/maindb/grant_test.go \
|
app/maindb/grant_test.go \
|
||||||
app/router/pathc_test.go \
|
app/router/pathc_test.go \
|
||||||
app/router/router_test.go \
|
app/router/router_test.go \
|
||||||
|
\
|
||||||
pkg/auxpwd/passwd_test.go \
|
pkg/auxpwd/passwd_test.go \
|
||||||
pkg/auxx509/x509cert_test.go \
|
pkg/auxx509/x509cert_test.go \
|
||||||
attic/account_test.go \
|
attic/account_test.go \
|
||||||
attic/file_test.go \
|
attic/file_test.go \
|
||||||
|
\
|
||||||
chart/Chart.yaml.in \
|
chart/Chart.yaml.in \
|
||||||
chart/.gitignore \
|
chart/.gitignore \
|
||||||
chart/.helmignore \
|
chart/.helmignore \
|
||||||
@@ -417,10 +426,10 @@ EXTRA_DIST = \
|
|||||||
chart/templates/_userpass.tpl \
|
chart/templates/_userpass.tpl \
|
||||||
chart/templates/volumeclaim.yaml \
|
chart/templates/volumeclaim.yaml \
|
||||||
chart/values.yaml.in \
|
chart/values.yaml.in \
|
||||||
|
\
|
||||||
debian/changelog.in \
|
debian/changelog.in \
|
||||||
debian/compat \
|
debian/compat \
|
||||||
debian/control.in \
|
debian/control.in \
|
||||||
debian/debhelper-build-stamp \
|
|
||||||
debian/files \
|
debian/files \
|
||||||
debian/.gitignore \
|
debian/.gitignore \
|
||||||
debian/mstore-control.install \
|
debian/mstore-control.install \
|
||||||
@@ -439,9 +448,11 @@ EXTRA_DIST = \
|
|||||||
debian/source/format \
|
debian/source/format \
|
||||||
debian/source/include-binaries \
|
debian/source/include-binaries \
|
||||||
debian/watch \
|
debian/watch \
|
||||||
|
\
|
||||||
initrc/.gitignore \
|
initrc/.gitignore \
|
||||||
initrc/mstored.in \
|
initrc/mstored.in \
|
||||||
initrc/mstored.service.in \
|
initrc/mstored.service.in \
|
||||||
|
\
|
||||||
test/account_test.go \
|
test/account_test.go \
|
||||||
test/file_test.go \
|
test/file_test.go \
|
||||||
test/image_test.go \
|
test/image_test.go \
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ func (hand *Handler) CheckAccess(rctx *router.Context) (bool, string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return success, accountID, err
|
return success, accountID, err
|
||||||
}
|
}
|
||||||
|
hand.logg.Debugf("Authorization pair is %s:%s", username, password)
|
||||||
|
|
||||||
success, id, err := hand.ValidatePassword(rctx.Ctx, username, password)
|
success, id, err := hand.ValidatePassword(rctx.Ctx, username, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, accountID, err
|
return false, accountID, err
|
||||||
|
|||||||
+2
-2
@@ -124,7 +124,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
|||||||
ID: auxuuid.NewUUID(),
|
ID: auxuuid.NewUUID(),
|
||||||
AccountID: accountDescr.ID,
|
AccountID: accountDescr.ID,
|
||||||
Right: descr.RightReadAccounts,
|
Right: descr.RightReadAccounts,
|
||||||
Pattern: ",*",
|
Pattern: ".*",
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
CreatedBy: descr.ServerID,
|
CreatedBy: descr.ServerID,
|
||||||
@@ -153,7 +153,7 @@ func (db *Database) WriteInituser(ctx context.Context) error {
|
|||||||
ID: auxuuid.NewUUID(),
|
ID: auxuuid.NewUUID(),
|
||||||
AccountID: accountDescr.ID,
|
AccountID: accountDescr.ID,
|
||||||
Right: descr.RightReadGrants,
|
Right: descr.RightReadGrants,
|
||||||
Pattern: ",*",
|
Pattern: ".*",
|
||||||
CreatedAt: now,
|
CreatedAt: now,
|
||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
CreatedBy: descr.ServerID,
|
CreatedBy: descr.ServerID,
|
||||||
|
|||||||
+94
-94
@@ -26,29 +26,46 @@ const (
|
|||||||
defaultHostname = "localhost:1025"
|
defaultHostname = "localhost:1025"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type AccountUtil struct {
|
||||||
|
createAccountParams CreateAccountParams
|
||||||
|
updateAccountParams UpdateAccountParams
|
||||||
|
getAccountParams GetAccountParams
|
||||||
|
deleteAccountParams DeleteAccountParams
|
||||||
|
listAccountsParams ListAccountsParams
|
||||||
|
commonAccountParams CommonAccountParams
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommonAccountParams struct {
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
Hostname string
|
||||||
|
Timeout uint64
|
||||||
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
||||||
var subCmd = &cobra.Command{
|
var subCmd = &cobra.Command{
|
||||||
Use: "account",
|
Use: "accounts",
|
||||||
Short: "Account operation",
|
Short: "Account operation",
|
||||||
|
Aliases: []string{"account"},
|
||||||
}
|
}
|
||||||
const defaultTimeout uint64 = 10
|
const defaultTimeout uint64 = 10
|
||||||
|
|
||||||
|
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Username, "user", "u", "", "Username")
|
||||||
|
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Password, "pass", "p", "", "Password")
|
||||||
|
subCmd.PersistentFlags().StringVarP(&util.commonAccountParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||||
|
subCmd.PersistentFlags().Uint64VarP(&util.commonAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||||
|
subCmd.MarkPersistentFlagRequired("host")
|
||||||
|
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||||
|
|
||||||
// CreateAccount
|
// CreateAccount
|
||||||
var createAccountCmd = &cobra.Command{
|
var createAccountCmd = &cobra.Command{
|
||||||
Use: "create",
|
Use: "create",
|
||||||
Short: "Create user account",
|
Short: "Create user account",
|
||||||
Run: util.CreateAccount,
|
Run: util.CreateAccount,
|
||||||
}
|
}
|
||||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.Username, "user", "u", "", "Username")
|
|
||||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.Password, "pass", "p", "", "Password")
|
|
||||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
|
||||||
createAccountCmd.Flags().Uint64VarP(&util.createAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
|
|
||||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.NewUsername, "newuser", "U", "", "New account username")
|
createAccountCmd.Flags().StringVarP(&util.createAccountParams.NewUsername, "newuser", "U", "", "New account username")
|
||||||
createAccountCmd.Flags().StringVarP(&util.createAccountParams.NewPassword, "newpass", "P", "", "New account password")
|
createAccountCmd.Flags().StringVarP(&util.createAccountParams.NewPassword, "newpass", "P", "", "New account password")
|
||||||
createAccountCmd.MarkFlagRequired("host")
|
|
||||||
createAccountCmd.MarkFlagsRequiredTogether("newuser", "newpass")
|
createAccountCmd.MarkFlagsRequiredTogether("newuser", "newpass")
|
||||||
createAccountCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
subCmd.AddCommand(createAccountCmd)
|
subCmd.AddCommand(createAccountCmd)
|
||||||
|
|
||||||
// GetAccount
|
// GetAccount
|
||||||
@@ -57,38 +74,23 @@ func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
|||||||
Short: "Get account info",
|
Short: "Get account info",
|
||||||
Run: util.GetAccount,
|
Run: util.GetAccount,
|
||||||
}
|
}
|
||||||
getAccountCmd.Flags().StringVarP(&util.getAccountParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
|
||||||
getAccountCmd.Flags().StringVarP(&util.getAccountParams.Username, "user", "u", "", "Username")
|
|
||||||
getAccountCmd.Flags().StringVarP(&util.getAccountParams.Password, "pass", "p", "", "Password")
|
|
||||||
getAccountCmd.Flags().Uint64VarP(&util.getAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
getAccountCmd.Flags().StringVarP(&util.getAccountParams.AccountID, "id", "I", "", "Account ID or name")
|
getAccountCmd.Flags().StringVarP(&util.getAccountParams.AccountID, "id", "I", "", "Account ID or name")
|
||||||
getAccountCmd.Flags().StringVarP(&util.getAccountParams.AccountID, "name", "n", "", "Account ID or name")
|
getAccountCmd.Flags().StringVarP(&util.getAccountParams.AccountID, "name", "n", "", "Account ID or name")
|
||||||
|
|
||||||
getAccountCmd.MarkFlagRequired("host")
|
|
||||||
getAccountCmd.MarkFlagsOneRequired("id", "name")
|
getAccountCmd.MarkFlagsOneRequired("id", "name")
|
||||||
getAccountCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
subCmd.AddCommand(getAccountCmd)
|
subCmd.AddCommand(getAccountCmd)
|
||||||
|
|
||||||
// UpdateAccount
|
// UpdateAccount
|
||||||
var updateAccountCmd = &cobra.Command{
|
var updateAccountCmd = &cobra.Command{
|
||||||
Use: "info",
|
Use: "update",
|
||||||
Short: "Update account parameters",
|
Short: "Update account parameters",
|
||||||
Run: util.UpdateAccount,
|
Run: util.UpdateAccount,
|
||||||
}
|
}
|
||||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.Username, "user", "u", "", "Username")
|
|
||||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.Password, "pass", "p", "", "Password")
|
|
||||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.Hostname, "host", "x", "", "File path")
|
|
||||||
updateAccountCmd.Flags().Uint64VarP(&util.updateAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
|
|
||||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "id", "I", "", "Account ID or username")
|
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "id", "I", "", "Account ID or username")
|
||||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "name", "n", "", "Account ID or username")
|
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "name", "n", "", "Account ID or username")
|
||||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.NewUsername, "newname", "N", "", "New username")
|
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.NewUsername, "newname", "N", "", "New username")
|
||||||
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.NewPassword, "newpass", "P", "", "New password")
|
updateAccountCmd.Flags().StringVarP(&util.updateAccountParams.NewPassword, "newpass", "P", "", "New password")
|
||||||
updateAccountCmd.MarkFlagRequired("host")
|
|
||||||
updateAccountCmd.MarkFlagsOneRequired("id", "name")
|
updateAccountCmd.MarkFlagsOneRequired("id", "name")
|
||||||
updateAccountCmd.MarkFlagsOneRequired("newname", "newpass")
|
updateAccountCmd.MarkFlagsOneRequired("newname", "newpass")
|
||||||
|
|
||||||
subCmd.AddCommand(updateAccountCmd)
|
subCmd.AddCommand(updateAccountCmd)
|
||||||
|
|
||||||
// DeleteAccount
|
// DeleteAccount
|
||||||
@@ -97,85 +99,71 @@ func (util *AccountUtil) CreateAccountCmds() *cobra.Command {
|
|||||||
Short: "Delete account",
|
Short: "Delete account",
|
||||||
Run: util.DeleteAccount,
|
Run: util.DeleteAccount,
|
||||||
}
|
}
|
||||||
deleteAccountCmd.Flags().StringVarP(&util.deleteAccountParams.Username, "user", "u", "", "Username")
|
|
||||||
deleteAccountCmd.Flags().StringVarP(&util.deleteAccountParams.Password, "pass", "p", "", "Password")
|
|
||||||
deleteAccountCmd.Flags().StringVarP(&util.deleteAccountParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
|
||||||
deleteAccountCmd.Flags().Uint64VarP(&util.deleteAccountParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
|
|
||||||
deleteAccountCmd.Flags().StringVarP(&util.deleteAccountParams.AccountID, "id", "I", "", "Account ID")
|
deleteAccountCmd.Flags().StringVarP(&util.deleteAccountParams.AccountID, "id", "I", "", "Account ID")
|
||||||
deleteAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "name", "n", "", "Account ID or username")
|
deleteAccountCmd.Flags().StringVarP(&util.updateAccountParams.AccountID, "name", "n", "", "Account ID or username")
|
||||||
deleteAccountCmd.MarkFlagRequired("host")
|
|
||||||
deleteAccountCmd.MarkFlagsOneRequired("id", "name")
|
deleteAccountCmd.MarkFlagsOneRequired("id", "name")
|
||||||
deleteAccountCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
subCmd.AddCommand(deleteAccountCmd)
|
subCmd.AddCommand(deleteAccountCmd)
|
||||||
|
|
||||||
return subCmd
|
// ListAccount
|
||||||
}
|
|
||||||
|
|
||||||
func (util *AccountUtil) CreateAccountsCmds() *cobra.Command {
|
|
||||||
var subCmd = &cobra.Command{
|
|
||||||
Use: "accounts",
|
|
||||||
Short: "Accounts operation",
|
|
||||||
}
|
|
||||||
const defaultTimeout uint64 = 10
|
|
||||||
// ListAccounts
|
|
||||||
var listAccountsCmd = &cobra.Command{
|
var listAccountsCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "list accounts",
|
Short: "list accounts",
|
||||||
Run: util.ListAccounts,
|
Run: util.ListAccounts,
|
||||||
}
|
}
|
||||||
listAccountsCmd.Flags().StringVarP(&util.listAccountsParams.Username, "user", "u", "", "Username")
|
|
||||||
listAccountsCmd.Flags().StringVarP(&util.listAccountsParams.Password, "pass", "p", "", "Password")
|
|
||||||
listAccountsCmd.Flags().StringVarP(&util.listAccountsParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
|
||||||
listAccountsCmd.Flags().Uint64VarP(&util.listAccountsParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
listAccountsCmd.Flags().BoolVarP(&util.listAccountsParams.Detail, "detail", "d", false, "Show detail information")
|
listAccountsCmd.Flags().BoolVarP(&util.listAccountsParams.Detail, "detail", "d", false, "Show detail information")
|
||||||
listAccountsCmd.Flags().StringVarP(&util.listAccountsParams.Regex, "regex", "r", "", "Output regexp for usernames")
|
listAccountsCmd.Flags().StringVarP(&util.listAccountsParams.Regex, "regex", "r", "", "Output regexp for usernames")
|
||||||
listAccountsCmd.MarkFlagRequired("host")
|
listAccountsCmd.MarkFlagRequired("host")
|
||||||
|
|
||||||
subCmd.AddCommand(listAccountsCmd)
|
subCmd.AddCommand(listAccountsCmd)
|
||||||
return subCmd
|
|
||||||
}
|
|
||||||
|
|
||||||
type AccountUtil struct {
|
return subCmd
|
||||||
createAccountParams CreateAccountParams
|
|
||||||
updateAccountParams UpdateAccountParams
|
|
||||||
getAccountParams GetAccountParams
|
|
||||||
deleteAccountParams DeleteAccountParams
|
|
||||||
listAccountsParams ListAccountsParams
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateAccount
|
// CreateAccount
|
||||||
type CreateAccountParams struct {
|
type CreateAccountParams struct {
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Hostname string
|
|
||||||
NewUsername string
|
NewUsername string
|
||||||
NewPassword string
|
NewPassword string
|
||||||
Timeout uint64
|
|
||||||
}
|
}
|
||||||
type CreateAccountResult struct {
|
type CreateAccountResult struct {
|
||||||
AccountID string
|
AccountID string `json:"accountId"`
|
||||||
|
GrantIDs []string `json:"grantsIds,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) CreateAccount(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.createAccount(&util.createAccountParams)
|
res, err := util.createAccount(&util.commonAccountParams, &util.createAccountParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) createAccount(params *CreateAccountParams) (*CreateAccountResult, error) {
|
func (util *AccountUtil) createAccount(common *CommonAccountParams, params *CreateAccountParams) (*CreateAccountResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &CreateAccountResult{}
|
res := &CreateAccountResult{
|
||||||
params.Hostname, err = packUserinfo(params.Hostname, params.NewUsername, params.NewPassword)
|
GrantIDs: make([]string, 0),
|
||||||
|
}
|
||||||
|
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
accountID, err := client.NewClient().CreateAccount(ctx, params.Hostname, params.NewUsername, params.NewPassword)
|
accountID, err := client.NewClient().CreateAccount(ctx, hostname, params.NewUsername, params.NewPassword)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fullRights := []string{
|
||||||
|
descr.RightWriteAccounts,
|
||||||
|
descr.RightReadAccounts,
|
||||||
|
descr.RightWriteFiles,
|
||||||
|
descr.RightReadFiles,
|
||||||
|
descr.RightWriteImages,
|
||||||
|
descr.RightReadImages,
|
||||||
|
}
|
||||||
|
for _, right := range fullRights {
|
||||||
|
id, err := client.NewClient().CreateGrant(ctx, hostname, accountID, right, ".*")
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
res.GrantIDs = append(res.GrantIDs, id)
|
||||||
|
}
|
||||||
res.AccountID = accountID
|
res.AccountID = accountID
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@@ -195,25 +183,25 @@ type UpdateAccountResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) UpdateAccount(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) UpdateAccount(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.updateAccount(&util.updateAccountParams)
|
res, err := util.updateAccount(&util.commonAccountParams, &util.updateAccountParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) updateAccount(params *UpdateAccountParams) (*UpdateAccountResult, error) {
|
func (util *AccountUtil) updateAccount(common *CommonAccountParams, params *UpdateAccountParams) (*UpdateAccountResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &UpdateAccountResult{}
|
res := &UpdateAccountResult{}
|
||||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
re := regexp.MustCompile(uuidRegex)
|
re := regexp.MustCompile(uuidRegex)
|
||||||
id := strings.ToLower(params.AccountID)
|
id := strings.ToLower(params.AccountID)
|
||||||
if re.MatchString(id) {
|
if re.MatchString(id) {
|
||||||
err = client.NewClient().UpdateAccountByID(ctx, params.Hostname, id, params.NewUsername, params.NewPassword)
|
err = client.NewClient().UpdateAccountByID(ctx, hostname, id, params.NewUsername, params.NewPassword)
|
||||||
} else {
|
} else {
|
||||||
err = client.NewClient().UpdateAccountByName(ctx, params.Hostname, params.AccountID, params.NewUsername, params.NewPassword)
|
err = client.NewClient().UpdateAccountByName(ctx, hostname, params.AccountID, params.NewUsername, params.NewPassword)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
@@ -231,7 +219,7 @@ type GetAccountParams struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) GetAccount(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) GetAccount(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.getAccount(&util.getAccountParams)
|
res, err := util.getAccount(&util.commonAccountParams, &util.getAccountParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,23 +227,23 @@ type GetAccountResult struct {
|
|||||||
Account *descr.AccountShort `json:"account,omitempty"`
|
Account *descr.AccountShort `json:"account,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) getAccount(params *GetAccountParams) (*GetAccountResult, error) {
|
func (util *AccountUtil) getAccount(common *CommonAccountParams, params *GetAccountParams) (*GetAccountResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &GetAccountResult{}
|
res := &GetAccountResult{}
|
||||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
opRes := &descr.AccountShort{}
|
opRes := &descr.AccountShort{}
|
||||||
|
|
||||||
re := regexp.MustCompile(uuidRegex)
|
re := regexp.MustCompile(uuidRegex)
|
||||||
id := strings.ToLower(params.AccountID)
|
id := strings.ToLower(params.AccountID)
|
||||||
if re.MatchString(id) {
|
if re.MatchString(id) {
|
||||||
opRes, err = client.NewClient().GetAccountByID(ctx, params.Hostname, id)
|
opRes, err = client.NewClient().GetAccountByID(ctx, hostname, id)
|
||||||
} else {
|
} else {
|
||||||
opRes, err = client.NewClient().GetAccountByName(ctx, params.Hostname, params.AccountID)
|
opRes, err = client.NewClient().GetAccountByName(ctx, hostname, params.AccountID)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
@@ -276,24 +264,24 @@ type DeleteAccountParams struct {
|
|||||||
type DeleteAccountResult struct{}
|
type DeleteAccountResult struct{}
|
||||||
|
|
||||||
func (util *AccountUtil) DeleteAccount(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) DeleteAccount(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.deleteAccount(&util.deleteAccountParams)
|
res, err := util.deleteAccount(&util.commonAccountParams, &util.deleteAccountParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
func (util *AccountUtil) deleteAccount(params *DeleteAccountParams) (*DeleteAccountResult, error) {
|
func (util *AccountUtil) deleteAccount(common *CommonAccountParams, params *DeleteAccountParams) (*DeleteAccountResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &DeleteAccountResult{}
|
res := &DeleteAccountResult{}
|
||||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
re := regexp.MustCompile(uuidRegex)
|
re := regexp.MustCompile(uuidRegex)
|
||||||
id := strings.ToLower(params.AccountID)
|
id := strings.ToLower(params.AccountID)
|
||||||
if re.MatchString(id) {
|
if re.MatchString(id) {
|
||||||
err = client.NewClient().DeleteAccountByID(ctx, params.Hostname, id)
|
err = client.NewClient().DeleteAccountByID(ctx, hostname, id)
|
||||||
} else {
|
} else {
|
||||||
err = client.NewClient().DeleteAccountByName(ctx, params.Hostname, params.AccountID)
|
err = client.NewClient().DeleteAccountByName(ctx, hostname, params.AccountID)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
@@ -311,19 +299,24 @@ type ListAccountsParams struct {
|
|||||||
Regex string
|
Regex string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Userinfo struct {
|
||||||
|
Username string `json:"username,omitempty"`
|
||||||
|
Rights []string `json:"rights,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type ListAccountsResult struct {
|
type ListAccountsResult struct {
|
||||||
Accounts []descr.AccountShort `json:"accounts,omitempty"`
|
Accounts []descr.AccountShort `json:"accounts,omitempty"`
|
||||||
Usernames []string `json:"names,omitempty"`
|
Users []Userinfo `json:"users,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *AccountUtil) ListAccounts(cmd *cobra.Command, args []string) {
|
func (util *AccountUtil) ListAccounts(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.listAccounts(&util.listAccountsParams)
|
res, err := util.listAccounts(&util.commonAccountParams, &util.listAccountsParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
func (util *AccountUtil) listAccounts(params *ListAccountsParams) (*ListAccountsResult, error) {
|
func (util *AccountUtil) listAccounts(common *CommonAccountParams, params *ListAccountsParams) (*ListAccountsResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &ListAccountsResult{}
|
res := &ListAccountsResult{}
|
||||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@@ -332,9 +325,9 @@ func (util *AccountUtil) listAccounts(params *ListAccountsParams) (*ListAccounts
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
accounts, err := client.NewClient().ListAccounts(ctx, params.Hostname)
|
accounts, err := client.NewClient().ListAccounts(ctx, hostname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@@ -351,9 +344,16 @@ func (util *AccountUtil) listAccounts(params *ListAccountsParams) (*ListAccounts
|
|||||||
if params.Detail {
|
if params.Detail {
|
||||||
res.Accounts = outAccounts
|
res.Accounts = outAccounts
|
||||||
} else {
|
} else {
|
||||||
res.Usernames = make([]string, 0)
|
res.Users = make([]Userinfo, 0)
|
||||||
for _, item := range outAccounts {
|
for _, account := range outAccounts {
|
||||||
res.Usernames = append(res.Usernames, item.Username)
|
userinfo := Userinfo{
|
||||||
|
Username: account.Username,
|
||||||
|
Rights: make([]string, 0),
|
||||||
|
}
|
||||||
|
for _, grant := range account.Grants {
|
||||||
|
userinfo.Rights = append(userinfo.Rights, grant.Right)
|
||||||
|
}
|
||||||
|
res.Users = append(res.Users, userinfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res, err
|
return res, err
|
||||||
|
|||||||
+39
-68
@@ -22,23 +22,28 @@ import (
|
|||||||
|
|
||||||
func (util *FileUtil) CreateFileCmds() *cobra.Command {
|
func (util *FileUtil) CreateFileCmds() *cobra.Command {
|
||||||
var subCmd = &cobra.Command{
|
var subCmd = &cobra.Command{
|
||||||
Use: "file",
|
Use: "files",
|
||||||
Short: "File operation",
|
Short: "File operation",
|
||||||
|
Aliases: []string{"file"},
|
||||||
}
|
}
|
||||||
const defaultTimeout uint64 = 10
|
const defaultTimeout uint64 = 10
|
||||||
|
|
||||||
|
subCmd.PersistentFlags().StringVarP(&util.commonFileParams.Username, "user", "u", "", "Username")
|
||||||
|
subCmd.PersistentFlags().StringVarP(&util.commonFileParams.Password, "pass", "p", "", "Password")
|
||||||
|
subCmd.PersistentFlags().Uint64VarP(&util.commonFileParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||||
|
subCmd.MarkPersistentFlagRequired("host")
|
||||||
|
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||||
|
|
||||||
// PutFile
|
// PutFile
|
||||||
var putFileCmd = &cobra.Command{
|
var putFileCmd = &cobra.Command{
|
||||||
Use: "put",
|
Use: "put",
|
||||||
|
Aliases: []string{"push"},
|
||||||
Short: "Put file to storage",
|
Short: "Put file to storage",
|
||||||
Run: util.PutFile,
|
Run: util.PutFile,
|
||||||
}
|
}
|
||||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Username, "user", "u", "", "Username")
|
|
||||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Password, "pass", "p", "", "Password")
|
|
||||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Source, "src", "s", "", "Source path")
|
putFileCmd.Flags().StringVarP(&util.putFileParams.Source, "src", "s", "", "Source path")
|
||||||
putFileCmd.Flags().StringVarP(&util.putFileParams.Dest, "dest", "d", "", "Desctination path")
|
putFileCmd.Flags().StringVarP(&util.putFileParams.Dest, "dest", "d", "", "Desctination path")
|
||||||
putFileCmd.Flags().Uint64VarP(&util.putFileParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
putFileCmd.MarkFlagsRequiredTogether("src", "dest")
|
putFileCmd.MarkFlagsRequiredTogether("src", "dest")
|
||||||
putFileCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
putFileCmd.MarkFlagFilename("src")
|
putFileCmd.MarkFlagFilename("src")
|
||||||
|
|
||||||
subCmd.AddCommand(putFileCmd)
|
subCmd.AddCommand(putFileCmd)
|
||||||
@@ -46,16 +51,13 @@ func (util *FileUtil) CreateFileCmds() *cobra.Command {
|
|||||||
// GetFile
|
// GetFile
|
||||||
var getFileCmd = &cobra.Command{
|
var getFileCmd = &cobra.Command{
|
||||||
Use: "get",
|
Use: "get",
|
||||||
|
Aliases: []string{"pull"},
|
||||||
Short: "Get file from storage",
|
Short: "Get file from storage",
|
||||||
Run: util.GetFile,
|
Run: util.GetFile,
|
||||||
}
|
}
|
||||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Username, "user", "u", "", "Username")
|
|
||||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Password, "pass", "p", "", "Password")
|
|
||||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Source, "src", "s", "", "Source path")
|
getFileCmd.Flags().StringVarP(&util.getFileParams.Source, "src", "s", "", "Source path")
|
||||||
getFileCmd.Flags().StringVarP(&util.getFileParams.Dest, "dest", "d", "", "Desctination path")
|
getFileCmd.Flags().StringVarP(&util.getFileParams.Dest, "dest", "d", "", "Desctination path")
|
||||||
getFileCmd.Flags().Uint64VarP(&util.getFileParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
getFileCmd.MarkFlagsRequiredTogether("src", "dest")
|
getFileCmd.MarkFlagsRequiredTogether("src", "dest")
|
||||||
getFileCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
subCmd.AddCommand(getFileCmd)
|
subCmd.AddCommand(getFileCmd)
|
||||||
|
|
||||||
@@ -65,53 +67,30 @@ func (util *FileUtil) CreateFileCmds() *cobra.Command {
|
|||||||
Short: "Show file information",
|
Short: "Show file information",
|
||||||
Run: util.FileInfo,
|
Run: util.FileInfo,
|
||||||
}
|
}
|
||||||
fileInfoCmd.Flags().StringVarP(&util.fileInfoParams.Username, "user", "u", "", "Username")
|
|
||||||
fileInfoCmd.Flags().StringVarP(&util.fileInfoParams.Password, "pass", "p", "", "Password")
|
|
||||||
fileInfoCmd.Flags().StringVarP(&util.fileInfoParams.Filepath, "path", "d", "", "File path")
|
fileInfoCmd.Flags().StringVarP(&util.fileInfoParams.Filepath, "path", "d", "", "File path")
|
||||||
fileInfoCmd.Flags().Uint64VarP(&util.fileInfoParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
fileInfoCmd.MarkFlagRequired("path")
|
fileInfoCmd.MarkFlagRequired("path")
|
||||||
fileInfoCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
subCmd.AddCommand(fileInfoCmd)
|
subCmd.AddCommand(fileInfoCmd)
|
||||||
|
|
||||||
// DeleteFile
|
// DeleteFile
|
||||||
var deleteFileCmd = &cobra.Command{
|
var deleteFileCmd = &cobra.Command{
|
||||||
Use: "delete",
|
Use: "delete",
|
||||||
|
Aliases: []string{"remove"},
|
||||||
Short: "Delete file in storage",
|
Short: "Delete file in storage",
|
||||||
Run: util.DeleteFile,
|
Run: util.DeleteFile,
|
||||||
}
|
}
|
||||||
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Username, "user", "u", "", "Username")
|
|
||||||
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Password, "pass", "p", "", "Password")
|
|
||||||
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Filepath, "path", "d", "", "File path")
|
deleteFileCmd.Flags().StringVarP(&util.deleteFileParams.Filepath, "path", "d", "", "File path")
|
||||||
deleteFileCmd.Flags().Uint64VarP(&util.deleteFileParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
deleteFileCmd.MarkFlagRequired("path")
|
deleteFileCmd.MarkFlagRequired("path")
|
||||||
deleteFileCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
subCmd.AddCommand(deleteFileCmd)
|
subCmd.AddCommand(deleteFileCmd)
|
||||||
|
|
||||||
return subCmd
|
|
||||||
}
|
|
||||||
|
|
||||||
func (util *FileUtil) CreateFilesCmds() *cobra.Command {
|
|
||||||
var subCmd = &cobra.Command{
|
|
||||||
Use: "files",
|
|
||||||
Short: "Files operation",
|
|
||||||
}
|
|
||||||
const defaultTimeout uint64 = 10
|
|
||||||
|
|
||||||
// ListFiles
|
// ListFiles
|
||||||
var listFilesCmd = &cobra.Command{
|
var listFilesCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "List file in storage",
|
Short: "List file in storage",
|
||||||
Run: util.ListFiles,
|
Run: util.ListFiles,
|
||||||
}
|
}
|
||||||
listFilesCmd.Flags().StringVarP(&util.listFilesParams.Username, "user", "u", "", "Username")
|
|
||||||
listFilesCmd.Flags().StringVarP(&util.listFilesParams.Password, "pass", "p", "", "Password")
|
|
||||||
listFilesCmd.Flags().StringVarP(&util.listFilesParams.Filepath, "catalog", "c", "", "Catalog path")
|
listFilesCmd.Flags().StringVarP(&util.listFilesParams.Filepath, "catalog", "c", "", "Catalog path")
|
||||||
listFilesCmd.Flags().Uint64VarP(&util.listFilesParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
listFilesCmd.MarkFlagRequired("catalog")
|
listFilesCmd.MarkFlagRequired("catalog")
|
||||||
listFilesCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
subCmd.AddCommand(listFilesCmd)
|
subCmd.AddCommand(listFilesCmd)
|
||||||
|
|
||||||
return subCmd
|
return subCmd
|
||||||
@@ -123,32 +102,36 @@ type FileUtil struct {
|
|||||||
getFileParams GetFileParams
|
getFileParams GetFileParams
|
||||||
deleteFileParams DeleteFileParams
|
deleteFileParams DeleteFileParams
|
||||||
listFilesParams ListFilesParams
|
listFilesParams ListFilesParams
|
||||||
|
commonFileParams CommonFileParams
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommonFileParams struct {
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
Timeout uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileInfo
|
// FileInfo
|
||||||
type FileInfoParams struct {
|
type FileInfoParams struct {
|
||||||
Filepath string
|
Filepath string
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Timeout uint64
|
|
||||||
}
|
}
|
||||||
type FileInfoResult struct {
|
type FileInfoResult struct {
|
||||||
File *descr.File `json:"file,omitempty"`
|
File *descr.File `json:"file,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *FileUtil) FileInfo(cmd *cobra.Command, args []string) {
|
func (util *FileUtil) FileInfo(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.fileInfo(&util.fileInfoParams)
|
res, err := util.fileInfo(&util.commonFileParams, &util.fileInfoParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *FileUtil) fileInfo(params *FileInfoParams) (*FileInfoResult, error) {
|
func (util *FileUtil) fileInfo(common *CommonFileParams, params *FileInfoParams) (*FileInfoResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &FileInfoResult{}
|
res := &FileInfoResult{}
|
||||||
params.Filepath, err = packUserinfo(params.Filepath, params.Username, params.Password)
|
params.Filepath, err = packUserinfo(params.Filepath, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
exists, opres, err := client.NewClient().FileInfo(ctx, params.Filepath)
|
exists, opres, err := client.NewClient().FileInfo(ctx, params.Filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -166,25 +149,22 @@ func (util *FileUtil) fileInfo(params *FileInfoParams) (*FileInfoResult, error)
|
|||||||
type PutFileParams struct {
|
type PutFileParams struct {
|
||||||
Source string
|
Source string
|
||||||
Dest string
|
Dest string
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Timeout uint64
|
|
||||||
}
|
}
|
||||||
type PutFileResult struct{}
|
type PutFileResult struct{}
|
||||||
|
|
||||||
func (util *FileUtil) PutFile(cmd *cobra.Command, args []string) {
|
func (util *FileUtil) PutFile(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.putFile(&util.putFileParams)
|
res, err := util.putFile(&util.commonFileParams, &util.putFileParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *FileUtil) putFile(params *PutFileParams) (*PutFileResult, error) {
|
func (util *FileUtil) putFile(common *CommonFileParams, params *PutFileParams) (*PutFileResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &PutFileResult{}
|
res := &PutFileResult{}
|
||||||
params.Dest, err = packUserinfo(params.Dest, params.Username, params.Password)
|
params.Dest, err = packUserinfo(params.Dest, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
err = client.NewClient().PutFile(ctx, params.Source, params.Dest)
|
err = client.NewClient().PutFile(ctx, params.Source, params.Dest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -197,26 +177,23 @@ func (util *FileUtil) putFile(params *PutFileParams) (*PutFileResult, error) {
|
|||||||
type GetFileParams struct {
|
type GetFileParams struct {
|
||||||
Source string
|
Source string
|
||||||
Dest string
|
Dest string
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Timeout uint64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *FileUtil) GetFile(cmd *cobra.Command, args []string) {
|
func (util *FileUtil) GetFile(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.getFile(&util.getFileParams)
|
res, err := util.getFile(&util.commonFileParams, &util.getFileParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetFileResult struct{}
|
type GetFileResult struct{}
|
||||||
|
|
||||||
func (util *FileUtil) getFile(params *GetFileParams) (*GetFileResult, error) {
|
func (util *FileUtil) getFile(common *CommonFileParams, params *GetFileParams) (*GetFileResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &GetFileResult{}
|
res := &GetFileResult{}
|
||||||
params.Dest, err = packUserinfo(params.Source, params.Username, params.Password)
|
params.Dest, err = packUserinfo(params.Source, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
_, err = client.NewClient().GetFile(ctx, params.Dest, params.Source)
|
_, err = client.NewClient().GetFile(ctx, params.Dest, params.Source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -228,25 +205,22 @@ func (util *FileUtil) getFile(params *GetFileParams) (*GetFileResult, error) {
|
|||||||
// DeleteFile
|
// DeleteFile
|
||||||
type DeleteFileParams struct {
|
type DeleteFileParams struct {
|
||||||
Filepath string
|
Filepath string
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Timeout uint64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteFileResult struct{}
|
type DeleteFileResult struct{}
|
||||||
|
|
||||||
func (util *FileUtil) DeleteFile(cmd *cobra.Command, args []string) {
|
func (util *FileUtil) DeleteFile(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.deleteFile(&util.deleteFileParams)
|
res, err := util.deleteFile(&util.commonFileParams, &util.deleteFileParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
func (util *FileUtil) deleteFile(params *DeleteFileParams) (*DeleteFileResult, error) {
|
func (util *FileUtil) deleteFile(common *CommonFileParams, params *DeleteFileParams) (*DeleteFileResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &DeleteFileResult{}
|
res := &DeleteFileResult{}
|
||||||
params.Filepath, err = packUserinfo(params.Filepath, params.Username, params.Password)
|
params.Filepath, err = packUserinfo(params.Filepath, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
err = client.NewClient().DeleteFile(ctx, params.Filepath)
|
err = client.NewClient().DeleteFile(ctx, params.Filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -258,9 +232,6 @@ func (util *FileUtil) deleteFile(params *DeleteFileParams) (*DeleteFileResult, e
|
|||||||
// ListFiles
|
// ListFiles
|
||||||
type ListFilesParams struct {
|
type ListFilesParams struct {
|
||||||
Filepath string
|
Filepath string
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Timeout uint64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListFilesResult struct {
|
type ListFilesResult struct {
|
||||||
@@ -268,17 +239,17 @@ type ListFilesResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (util *FileUtil) ListFiles(cmd *cobra.Command, args []string) {
|
func (util *FileUtil) ListFiles(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.listFiles(&util.listFilesParams)
|
res, err := util.listFiles(&util.commonFileParams, &util.listFilesParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
func (util *FileUtil) listFiles(params *ListFilesParams) (*ListFilesResult, error) {
|
func (util *FileUtil) listFiles(common *CommonFileParams, params *ListFilesParams) (*ListFilesResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &ListFilesResult{}
|
res := &ListFilesResult{}
|
||||||
params.Filepath, err = packUserinfo(params.Filepath, params.Username, params.Password)
|
params.Filepath, err = packUserinfo(params.Filepath, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
files, err := client.NewClient().ListFiles(ctx, params.Filepath)
|
files, err := client.NewClient().ListFiles(ctx, params.Filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+49
-94
@@ -23,28 +23,28 @@ import (
|
|||||||
|
|
||||||
func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
||||||
var subCmd = &cobra.Command{
|
var subCmd = &cobra.Command{
|
||||||
Use: "account",
|
Use: "grants",
|
||||||
Short: "Grant operation",
|
Short: "Grant operation",
|
||||||
|
Aliases: []string{"grant"},
|
||||||
}
|
}
|
||||||
const defaultTimeout uint64 = 10
|
const defaultTimeout uint64 = 10
|
||||||
|
|
||||||
|
subCmd.PersistentFlags().StringVarP(&util.commonGrantParams.Username, "user", "u", "", "Username")
|
||||||
|
subCmd.PersistentFlags().StringVarP(&util.commonGrantParams.Password, "pass", "p", "", "Password")
|
||||||
|
subCmd.PersistentFlags().StringVarP(&util.commonGrantParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
||||||
|
subCmd.PersistentFlags().Uint64VarP(&util.commonGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||||
|
subCmd.MarkPersistentFlagRequired("host")
|
||||||
|
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||||
|
|
||||||
// CreateGrant
|
// CreateGrant
|
||||||
var createGrantCmd = &cobra.Command{
|
var createGrantCmd = &cobra.Command{
|
||||||
Use: "create",
|
Use: "create",
|
||||||
Short: "Create grant",
|
Short: "Create grant",
|
||||||
Run: util.CreateGrant,
|
Run: util.CreateGrant,
|
||||||
}
|
}
|
||||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Username, "username", "u", "", "Username")
|
|
||||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Password, "password", "p", "", "Password")
|
|
||||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
|
||||||
createGrantCmd.Flags().Uint64VarP(&util.createGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
|
|
||||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Right, "newuser", "U", "", "New account username")
|
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Right, "newuser", "U", "", "New account username")
|
||||||
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Pattern, "newpass", "P", "", "New account password")
|
createGrantCmd.Flags().StringVarP(&util.createGrantParams.Pattern, "newpass", "P", "", "New account password")
|
||||||
createGrantCmd.MarkFlagRequired("host")
|
|
||||||
createGrantCmd.MarkFlagsRequiredTogether("newuser", "newpass")
|
createGrantCmd.MarkFlagsRequiredTogether("newuser", "newpass")
|
||||||
createGrantCmd.MarkFlagsRequiredTogether("username", "password")
|
|
||||||
|
|
||||||
subCmd.AddCommand(createGrantCmd)
|
subCmd.AddCommand(createGrantCmd)
|
||||||
|
|
||||||
// GetGrant
|
// GetGrant
|
||||||
@@ -53,17 +53,9 @@ func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
|||||||
Short: "Get detail grant info",
|
Short: "Get detail grant info",
|
||||||
Run: util.GetGrant,
|
Run: util.GetGrant,
|
||||||
}
|
}
|
||||||
getGrantCmd.Flags().StringVarP(&util.getGrantParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
|
||||||
getGrantCmd.Flags().StringVarP(&util.getGrantParams.Username, "username", "u", "", "Username")
|
|
||||||
getGrantCmd.Flags().StringVarP(&util.getGrantParams.Password, "password", "p", "", "Password")
|
|
||||||
getGrantCmd.Flags().Uint64VarP(&util.getGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
getGrantCmd.Flags().StringVarP(&util.getGrantParams.GrantID, "id", "I", "", "Grant ID or name")
|
getGrantCmd.Flags().StringVarP(&util.getGrantParams.GrantID, "id", "I", "", "Grant ID or name")
|
||||||
getGrantCmd.Flags().StringVarP(&util.getGrantParams.GrantID, "name", "n", "", "Grant ID or name")
|
getGrantCmd.Flags().StringVarP(&util.getGrantParams.GrantID, "name", "n", "", "Grant ID or name")
|
||||||
|
|
||||||
getGrantCmd.MarkFlagRequired("host")
|
|
||||||
getGrantCmd.MarkFlagsOneRequired("id", "name")
|
getGrantCmd.MarkFlagsOneRequired("id", "name")
|
||||||
getGrantCmd.MarkFlagsRequiredTogether("username", "password")
|
|
||||||
|
|
||||||
subCmd.AddCommand(getGrantCmd)
|
subCmd.AddCommand(getGrantCmd)
|
||||||
|
|
||||||
// UpdateGrant
|
// UpdateGrant
|
||||||
@@ -72,18 +64,13 @@ func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
|||||||
Short: "Update grant parameters",
|
Short: "Update grant parameters",
|
||||||
Run: util.UpdateGrant,
|
Run: util.UpdateGrant,
|
||||||
}
|
}
|
||||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Username, "username", "u", "", "Username")
|
|
||||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Password, "password", "p", "", "Password")
|
|
||||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Hostname, "host", "x", "", "File path")
|
|
||||||
updateGrantCmd.Flags().Uint64VarP(&util.updateGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
|
|
||||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.GrantID, "id", "I", "", "Grant ID or username")
|
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.GrantID, "id", "I", "", "Grant ID or username")
|
||||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.GrantID, "name", "n", "", "Grant ID or username")
|
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.GrantID, "name", "n", "", "Grant ID or username")
|
||||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Right, "newuser", "U", "", "New username")
|
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Right, "rigth", "U", "", "Rigth")
|
||||||
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Pattern, "pass", "P", "", "New password")
|
updateGrantCmd.Flags().StringVarP(&util.updateGrantParams.Pattern, "pattern", "P", "", "New pattern")
|
||||||
updateGrantCmd.MarkFlagRequired("host")
|
|
||||||
updateGrantCmd.MarkFlagsOneRequired("id", "name")
|
updateGrantCmd.MarkFlagsOneRequired("id", "name")
|
||||||
|
updateGrantCmd.MarkFlagRequired("rigth")
|
||||||
|
updateGrantCmd.MarkFlagRequired("pattern")
|
||||||
subCmd.AddCommand(updateGrantCmd)
|
subCmd.AddCommand(updateGrantCmd)
|
||||||
|
|
||||||
// DeleteGrant
|
// DeleteGrant
|
||||||
@@ -92,44 +79,24 @@ func (util *GrantUtil) CreateGrantCmds() *cobra.Command {
|
|||||||
Short: "Delete grant",
|
Short: "Delete grant",
|
||||||
Run: util.DeleteGrant,
|
Run: util.DeleteGrant,
|
||||||
}
|
}
|
||||||
deleteGrantCmd.Flags().StringVarP(&util.deleteGrantParams.Username, "username", "u", "", "Username")
|
|
||||||
deleteGrantCmd.Flags().StringVarP(&util.deleteGrantParams.Password, "password", "p", "", "Password")
|
|
||||||
deleteGrantCmd.Flags().StringVarP(&util.deleteGrantParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
|
||||||
deleteGrantCmd.Flags().Uint64VarP(&util.deleteGrantParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
|
|
||||||
deleteGrantCmd.Flags().StringVarP(&util.deleteGrantParams.GrantID, "id", "I", "", "Grant ID")
|
deleteGrantCmd.Flags().StringVarP(&util.deleteGrantParams.GrantID, "id", "I", "", "Grant ID")
|
||||||
deleteGrantCmd.MarkFlagRequired("host")
|
deleteGrantCmd.MarkFlagRequired("id")
|
||||||
deleteGrantCmd.MarkFlagsRequiredTogether("username", "password")
|
|
||||||
|
|
||||||
subCmd.AddCommand(deleteGrantCmd)
|
subCmd.AddCommand(deleteGrantCmd)
|
||||||
|
|
||||||
return subCmd
|
|
||||||
}
|
|
||||||
|
|
||||||
func (util *GrantUtil) CreateGrantsCmds() *cobra.Command {
|
|
||||||
var subCmd = &cobra.Command{
|
|
||||||
Use: "grans",
|
|
||||||
Short: "Grants operation",
|
|
||||||
}
|
|
||||||
const defaultTimeout uint64 = 10
|
|
||||||
// ListGrants
|
// ListGrants
|
||||||
var listGrantsCmd = &cobra.Command{
|
var listGrantsCmd = &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "list user grants",
|
Short: "list user grants",
|
||||||
Run: util.ListGrants,
|
Run: util.ListGrants,
|
||||||
}
|
}
|
||||||
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.Username, "username", "u", "", "Username")
|
|
||||||
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.Password, "password", "p", "", "Password")
|
|
||||||
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.Hostname, "host", "x", defaultHostname, "Hostname")
|
|
||||||
listGrantsCmd.Flags().Uint64VarP(&util.listGrantsParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
listGrantsCmd.Flags().BoolVarP(&util.listGrantsParams.Detail, "detail", "d", false, "Show detail information")
|
listGrantsCmd.Flags().BoolVarP(&util.listGrantsParams.Detail, "detail", "d", false, "Show detail information")
|
||||||
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.AccountID, "id", "I", "", "User account ID")
|
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.AccountID, "id", "I", "", "User account ID")
|
||||||
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.AccountID, "name", "n", "", "User account ID")
|
listGrantsCmd.Flags().StringVarP(&util.listGrantsParams.AccountID, "name", "n", "", "User account ID")
|
||||||
|
|
||||||
listGrantsCmd.MarkFlagRequired("host")
|
listGrantsCmd.MarkFlagRequired("host")
|
||||||
listGrantsCmd.MarkFlagsOneRequired("id", "name")
|
listGrantsCmd.MarkFlagsOneRequired("id", "name")
|
||||||
|
|
||||||
subCmd.AddCommand(listGrantsCmd)
|
subCmd.AddCommand(listGrantsCmd)
|
||||||
|
|
||||||
return subCmd
|
return subCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,37 +106,41 @@ type GrantUtil struct {
|
|||||||
getGrantParams GetGrantParams
|
getGrantParams GetGrantParams
|
||||||
deleteGrantParams DeleteGrantParams
|
deleteGrantParams DeleteGrantParams
|
||||||
listGrantsParams ListGrantsParams
|
listGrantsParams ListGrantsParams
|
||||||
|
commonGrantParams CommonGrantParams
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommonGrantParams struct {
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
|
Hostname string
|
||||||
|
Timeout uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateGrant
|
// CreateGrant
|
||||||
type CreateGrantParams struct {
|
type CreateGrantParams struct {
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Hostname string
|
|
||||||
AccountID string
|
AccountID string
|
||||||
Right string
|
Right string
|
||||||
Pattern string
|
Pattern string
|
||||||
Timeout uint64
|
|
||||||
}
|
}
|
||||||
type CreateGrantResult struct {
|
type CreateGrantResult struct {
|
||||||
GrantID string `json:"grantId"`
|
GrantID string `json:"grantId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) CreateGrant(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.createGrant(&util.createGrantParams)
|
res, err := util.createGrant(&util.commonGrantParams, &util.createGrantParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) createGrant(params *CreateGrantParams) (*CreateGrantResult, error) {
|
func (util *GrantUtil) createGrant(common *CommonGrantParams, params *CreateGrantParams) (*CreateGrantResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &CreateGrantResult{}
|
res := &CreateGrantResult{}
|
||||||
params.Hostname, err = packUserinfo(params.Hostname, params.Right, params.Pattern)
|
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
accountID, err := client.NewClient().CreateGrant(ctx, params.Hostname, params.AccountID, params.Right, params.Pattern)
|
accountID, err := client.NewClient().CreateGrant(ctx, hostname, params.AccountID, params.Right, params.Pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@@ -179,10 +150,6 @@ func (util *GrantUtil) createGrant(params *CreateGrantParams) (*CreateGrantResul
|
|||||||
|
|
||||||
// UpdateGrant
|
// UpdateGrant
|
||||||
type UpdateGrantParams struct {
|
type UpdateGrantParams struct {
|
||||||
Hostname string
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Timeout uint64
|
|
||||||
GrantID string
|
GrantID string
|
||||||
Right string
|
Right string
|
||||||
Pattern string
|
Pattern string
|
||||||
@@ -190,21 +157,21 @@ type UpdateGrantParams struct {
|
|||||||
type UpdateGrantResult struct{}
|
type UpdateGrantResult struct{}
|
||||||
|
|
||||||
func (util *GrantUtil) UpdateGrant(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) UpdateGrant(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.updateGrant(&util.updateGrantParams)
|
res, err := util.updateGrant(&util.commonGrantParams, &util.updateGrantParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) updateGrant(params *UpdateGrantParams) (*UpdateGrantResult, error) {
|
func (util *GrantUtil) updateGrant(common *CommonGrantParams, params *UpdateGrantParams) (*UpdateGrantResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &UpdateGrantResult{}
|
res := &UpdateGrantResult{}
|
||||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
id := strings.ToLower(params.GrantID)
|
id := strings.ToLower(params.GrantID)
|
||||||
err = client.NewClient().UpdateGrant(ctx, params.Hostname, id, params.Pattern)
|
err = client.NewClient().UpdateGrant(ctx, hostname, id, params.Pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@@ -213,10 +180,6 @@ func (util *GrantUtil) updateGrant(params *UpdateGrantParams) (*UpdateGrantResul
|
|||||||
|
|
||||||
// GetGrant
|
// GetGrant
|
||||||
type GetGrantParams struct {
|
type GetGrantParams struct {
|
||||||
Hostname string
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Timeout uint64
|
|
||||||
GrantID string
|
GrantID string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,23 +188,23 @@ type GetGrantResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) GetGrant(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) GetGrant(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.getGrant(&util.getGrantParams)
|
res, err := util.getGrant(&util.commonGrantParams, &util.getGrantParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) getGrant(params *GetGrantParams) (*GetGrantResult, error) {
|
func (util *GrantUtil) getGrant(common *CommonGrantParams, params *GetGrantParams) (*GetGrantResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &GetGrantResult{}
|
res := &GetGrantResult{}
|
||||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
opRes := &descr.Grant{}
|
opRes := &descr.Grant{}
|
||||||
|
|
||||||
id := strings.ToLower(params.GrantID)
|
id := strings.ToLower(params.GrantID)
|
||||||
opRes, err = client.NewClient().GetGrant(ctx, params.Hostname, id)
|
opRes, err = client.NewClient().GetGrant(ctx, hostname, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@@ -251,30 +214,26 @@ func (util *GrantUtil) getGrant(params *GetGrantParams) (*GetGrantResult, error)
|
|||||||
|
|
||||||
// DeleteGrant
|
// DeleteGrant
|
||||||
type DeleteGrantParams struct {
|
type DeleteGrantParams struct {
|
||||||
Hostname string
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
GrantID string
|
GrantID string
|
||||||
Timeout uint64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteGrantResult struct{}
|
type DeleteGrantResult struct{}
|
||||||
|
|
||||||
func (util *GrantUtil) DeleteGrant(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) DeleteGrant(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.deleteGrant(&util.deleteGrantParams)
|
res, err := util.deleteGrant(&util.commonGrantParams, &util.deleteGrantParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
func (util *GrantUtil) deleteGrant(params *DeleteGrantParams) (*DeleteGrantResult, error) {
|
func (util *GrantUtil) deleteGrant(common *CommonGrantParams, params *DeleteGrantParams) (*DeleteGrantResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &DeleteGrantResult{}
|
res := &DeleteGrantResult{}
|
||||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
id := strings.ToLower(params.GrantID)
|
id := strings.ToLower(params.GrantID)
|
||||||
err = client.NewClient().DeleteGrant(ctx, params.Hostname, id)
|
err = client.NewClient().DeleteGrant(ctx, hostname, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@@ -283,10 +242,6 @@ func (util *GrantUtil) deleteGrant(params *DeleteGrantParams) (*DeleteGrantResul
|
|||||||
|
|
||||||
// ListGrants
|
// ListGrants
|
||||||
type ListGrantsParams struct {
|
type ListGrantsParams struct {
|
||||||
Hostname string
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
Timeout uint64
|
|
||||||
Detail bool
|
Detail bool
|
||||||
AccountID string
|
AccountID string
|
||||||
}
|
}
|
||||||
@@ -297,25 +252,25 @@ type ListGrantsResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
|
func (util *GrantUtil) ListGrants(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.listGrants(&util.listGrantsParams)
|
res, err := util.listGrants(&util.commonGrantParams, &util.listGrantsParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
func (util *GrantUtil) listGrants(params *ListGrantsParams) (*ListGrantsResult, error) {
|
func (util *GrantUtil) listGrants(common *CommonGrantParams, params *ListGrantsParams) (*ListGrantsResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &ListGrantsResult{}
|
res := &ListGrantsResult{}
|
||||||
params.Hostname, err = packUserinfo(params.Hostname, params.Username, params.Password)
|
hostname, err := packUserinfo(common.Hostname, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
ctx, _ := context.WithTimeout(context.Background(), timeout)
|
||||||
grants := make([]descr.Grant, 0)
|
grants := make([]descr.Grant, 0)
|
||||||
re := regexp.MustCompile(uuidRegex)
|
re := regexp.MustCompile(uuidRegex)
|
||||||
id := strings.ToLower(params.AccountID)
|
id := strings.ToLower(params.AccountID)
|
||||||
if re.MatchString(id) {
|
if re.MatchString(id) {
|
||||||
grants, err = client.NewClient().ListGrantsByAccountID(ctx, params.Hostname, params.AccountID)
|
grants, err = client.NewClient().ListGrantsByAccountID(ctx, hostname, params.AccountID)
|
||||||
} else {
|
} else {
|
||||||
grants, err = client.NewClient().ListGrantsByUsername(ctx, params.Hostname, params.AccountID)
|
grants, err = client.NewClient().ListGrantsByUsername(ctx, hostname, params.AccountID)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
|
|||||||
+35
-51
@@ -43,24 +43,25 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
|||||||
const defaultTimeout uint64 = 30 // Second
|
const defaultTimeout uint64 = 30 // Second
|
||||||
|
|
||||||
var subCmd = &cobra.Command{
|
var subCmd = &cobra.Command{
|
||||||
Use: "image",
|
Use: "images",
|
||||||
Short: "Image operation",
|
Short: "Image operation",
|
||||||
|
Aliases: []string{"image"},
|
||||||
}
|
}
|
||||||
|
subCmd.PersistentFlags().StringVarP(&util.commonImageParams.Username, "user", "u", "", "Username")
|
||||||
|
subCmd.PersistentFlags().StringVarP(&util.commonImageParams.Password, "pass", "p", "", "Password")
|
||||||
|
subCmd.PersistentFlags().Uint64VarP(&util.commonImageParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
||||||
|
subCmd.MarkFlagsRequiredTogether("user", "pass")
|
||||||
|
|
||||||
// PushImage
|
// PushImage
|
||||||
var pushImageCmd = &cobra.Command{
|
var pushImageCmd = &cobra.Command{
|
||||||
Use: "push",
|
Use: "push",
|
||||||
Short: "Pull container image into local file",
|
Short: "Push container image from local tar file into registry",
|
||||||
Run: util.PushImage,
|
Run: util.PushImage,
|
||||||
}
|
}
|
||||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Username, "user", "u", "", "Username")
|
|
||||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Password, "pass", "p", "", "Password")
|
|
||||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Imagepath, "image", "i", "", "Remote image path")
|
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Imagepath, "image", "i", "", "Remote image path")
|
||||||
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Filepath, "file", "f", "", "Local file path")
|
pushImageCmd.Flags().StringVarP(&util.pushImageParams.Filepath, "file", "f", "", "Local tar file path")
|
||||||
pushImageCmd.Flags().Uint64VarP(&util.pushImageParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
pushImageCmd.MarkFlagRequired("image")
|
pushImageCmd.MarkFlagRequired("image")
|
||||||
pushImageCmd.MarkFlagRequired("file")
|
pushImageCmd.MarkFlagRequired("file")
|
||||||
pushImageCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
subCmd.AddCommand(pushImageCmd)
|
subCmd.AddCommand(pushImageCmd)
|
||||||
|
|
||||||
@@ -70,46 +71,34 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
|||||||
Short: "Show container image info",
|
Short: "Show container image info",
|
||||||
Run: util.ImageInfo,
|
Run: util.ImageInfo,
|
||||||
}
|
}
|
||||||
imageInfoCmd.Flags().StringVarP(&util.imageInfoParams.Username, "user", "u", "", "Username")
|
|
||||||
imageInfoCmd.Flags().StringVarP(&util.imageInfoParams.Password, "pass", "p", "", "Password")
|
|
||||||
imageInfoCmd.Flags().StringVarP(&util.imageInfoParams.Imagepath, "image", "i", "", "Remote image path")
|
imageInfoCmd.Flags().StringVarP(&util.imageInfoParams.Imagepath, "image", "i", "", "Remote image path")
|
||||||
imageInfoCmd.Flags().Uint64VarP(&util.imageInfoParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
imageInfoCmd.MarkFlagRequired("image")
|
imageInfoCmd.MarkFlagRequired("image")
|
||||||
imageInfoCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
subCmd.AddCommand(imageInfoCmd)
|
subCmd.AddCommand(imageInfoCmd)
|
||||||
|
|
||||||
// PullImage
|
// PullImage
|
||||||
var pullImageCmd = &cobra.Command{
|
var pullImageCmd = &cobra.Command{
|
||||||
Use: "pull",
|
Use: "pull",
|
||||||
Short: "Pull container image into local file",
|
Short: "Pull container image from registry into local file",
|
||||||
Run: util.PullImage,
|
Run: util.PullImage,
|
||||||
}
|
}
|
||||||
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Username, "user", "u", "", "Username")
|
|
||||||
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Password, "pass", "p", "", "Password")
|
|
||||||
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Imagepath, "image", "i", "", "Remote image path")
|
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Imagepath, "image", "i", "", "Remote image path")
|
||||||
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Filepath, "file", "f", "", "Local file path")
|
pullImageCmd.Flags().StringVarP(&util.pullImageParams.Filepath, "file", "f", "", "Local file path")
|
||||||
pullImageCmd.Flags().Uint64VarP(&util.pullImageParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
pullImageCmd.MarkFlagRequired("image")
|
pullImageCmd.MarkFlagRequired("image")
|
||||||
pullImageCmd.MarkFlagRequired("file")
|
pullImageCmd.MarkFlagRequired("file")
|
||||||
pullImageCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
subCmd.AddCommand(pullImageCmd)
|
subCmd.AddCommand(pullImageCmd)
|
||||||
|
|
||||||
// DeleteImage
|
// DeleteImage
|
||||||
var deleteImageCmd = &cobra.Command{
|
var deleteImageCmd = &cobra.Command{
|
||||||
Use: "info",
|
Use: "delete",
|
||||||
Short: "Show container image info",
|
Short: "Delete container image from registry",
|
||||||
Run: util.DeleteImage,
|
Run: util.DeleteImage,
|
||||||
}
|
}
|
||||||
deleteImageCmd.Flags().StringVarP(&util.deleteImageParams.Username, "user", "u", "", "Username")
|
|
||||||
deleteImageCmd.Flags().StringVarP(&util.deleteImageParams.Password, "pass", "p", "", "Password")
|
|
||||||
deleteImageCmd.Flags().StringVarP(&util.deleteImageParams.Imagepath, "image", "i", "", "Remote image path")
|
deleteImageCmd.Flags().StringVarP(&util.deleteImageParams.Imagepath, "image", "i", "", "Remote image path")
|
||||||
deleteImageCmd.Flags().Uint64VarP(&util.deleteImageParams.Timeout, "timeout", "t", defaultTimeout, "Operation timeout")
|
|
||||||
deleteImageCmd.MarkFlagRequired("image")
|
deleteImageCmd.MarkFlagRequired("image")
|
||||||
deleteImageCmd.MarkFlagsRequiredTogether("user", "pass")
|
|
||||||
|
|
||||||
subCmd.AddCommand(imageInfoCmd)
|
subCmd.AddCommand(deleteImageCmd)
|
||||||
|
|
||||||
return subCmd
|
return subCmd
|
||||||
}
|
}
|
||||||
@@ -119,32 +108,36 @@ type ImageUtil struct {
|
|||||||
pullImageParams PullImageParams
|
pullImageParams PullImageParams
|
||||||
pushImageParams PushImageParams
|
pushImageParams PushImageParams
|
||||||
deleteImageParams DeleteImageParams
|
deleteImageParams DeleteImageParams
|
||||||
|
commonImageParams CommonImageParams
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommonImageParams struct {
|
||||||
|
Timeout uint64
|
||||||
|
Username string
|
||||||
|
Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
// PushImage
|
// PushImage
|
||||||
type PushImageParams struct {
|
type PushImageParams struct {
|
||||||
Imagepath string
|
Imagepath string
|
||||||
Filepath string
|
Filepath string
|
||||||
Timeout uint64
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type PushImageResult struct{}
|
type PushImageResult struct{}
|
||||||
|
|
||||||
func (util *ImageUtil) PushImage(cmd *cobra.Command, args []string) {
|
func (util *ImageUtil) PushImage(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.pushImage(&util.pushImageParams)
|
res, err := util.pushImage(&util.commonImageParams, &util.pushImageParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *ImageUtil) pushImage(params *PushImageParams) (*PushImageResult, error) {
|
func (util *ImageUtil) pushImage(common *CommonImageParams, params *PushImageParams) (*PushImageResult, error) {
|
||||||
var err error
|
var err error
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
res := &PushImageResult{}
|
res := &PushImageResult{}
|
||||||
|
|
||||||
cli := client.NewClient()
|
cli := client.NewClient()
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@@ -159,9 +152,6 @@ func (util *ImageUtil) pushImage(params *PushImageParams) (*PushImageResult, err
|
|||||||
// ImageInfo
|
// ImageInfo
|
||||||
type ImageInfoParams struct {
|
type ImageInfoParams struct {
|
||||||
Imagepath string
|
Imagepath string
|
||||||
Timeout uint64
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageInfoResult struct {
|
type ImageInfoResult struct {
|
||||||
@@ -169,19 +159,19 @@ type ImageInfoResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (util *ImageUtil) ImageInfo(cmd *cobra.Command, args []string) {
|
func (util *ImageUtil) ImageInfo(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.imageInfo(&util.imageInfoParams)
|
res, err := util.imageInfo(&util.commonImageParams, &util.imageInfoParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *ImageUtil) imageInfo(params *ImageInfoParams) (*ImageInfoResult, error) {
|
func (util *ImageUtil) imageInfo(common *CommonImageParams, params *ImageInfoParams) (*ImageInfoResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &ImageInfoResult{}
|
res := &ImageInfoResult{}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
cli := client.NewClient()
|
cli := client.NewClient()
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
|
|
||||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@@ -198,27 +188,24 @@ func (util *ImageUtil) imageInfo(params *ImageInfoParams) (*ImageInfoResult, err
|
|||||||
type PullImageParams struct {
|
type PullImageParams struct {
|
||||||
Imagepath string
|
Imagepath string
|
||||||
Filepath string
|
Filepath string
|
||||||
Timeout uint64
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type PullImageResult struct{}
|
type PullImageResult struct{}
|
||||||
|
|
||||||
func (util *ImageUtil) PullImage(cmd *cobra.Command, args []string) {
|
func (util *ImageUtil) PullImage(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.pullImage(&util.pullImageParams)
|
res, err := util.pullImage(&util.commonImageParams, &util.pullImageParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *ImageUtil) pullImage(params *PullImageParams) (*PullImageResult, error) {
|
func (util *ImageUtil) pullImage(common *CommonImageParams, params *PullImageParams) (*PullImageResult, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
res := &PullImageResult{}
|
res := &PullImageResult{}
|
||||||
|
|
||||||
cli := client.NewClient()
|
cli := client.NewClient()
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@@ -233,28 +220,25 @@ func (util *ImageUtil) pullImage(params *PullImageParams) (*PullImageResult, err
|
|||||||
// DeleteImage
|
// DeleteImage
|
||||||
type DeleteImageParams struct {
|
type DeleteImageParams struct {
|
||||||
Imagepath string
|
Imagepath string
|
||||||
Timeout uint64
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteImageResult struct {
|
type DeleteImageResult struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *ImageUtil) DeleteImage(cmd *cobra.Command, args []string) {
|
func (util *ImageUtil) DeleteImage(cmd *cobra.Command, args []string) {
|
||||||
res, err := util.deleteImage(&util.deleteImageParams)
|
res, err := util.deleteImage(&util.commonImageParams, &util.deleteImageParams)
|
||||||
printResponse(res, err)
|
printResponse(res, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (util *ImageUtil) deleteImage(params *DeleteImageParams) (*DeleteImageResult, error) {
|
func (util *ImageUtil) deleteImage(common *CommonImageParams, params *DeleteImageParams) (*DeleteImageResult, error) {
|
||||||
var err error
|
var err error
|
||||||
res := &DeleteImageResult{}
|
res := &DeleteImageResult{}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
cli := client.NewClient()
|
cli := client.NewClient()
|
||||||
timeout := time.Duration(params.Timeout) * time.Second
|
timeout := time.Duration(common.Timeout) * time.Second
|
||||||
|
|
||||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,15 +52,11 @@ func (util *Util) Build() error {
|
|||||||
SilenceUsage: true,
|
SilenceUsage: true,
|
||||||
}
|
}
|
||||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||||
|
|
||||||
rootCmd.AddCommand(util.CreateFileCmds())
|
rootCmd.AddCommand(util.CreateFileCmds())
|
||||||
rootCmd.AddCommand(util.CreateFilesCmds())
|
|
||||||
rootCmd.AddCommand(util.CreateImageCmds())
|
rootCmd.AddCommand(util.CreateImageCmds())
|
||||||
|
|
||||||
rootCmd.AddCommand(util.CreateAccountCmds())
|
rootCmd.AddCommand(util.CreateAccountCmds())
|
||||||
rootCmd.AddCommand(util.CreateAccountsCmds())
|
|
||||||
|
|
||||||
rootCmd.AddCommand(util.CreateGrantCmds())
|
rootCmd.AddCommand(util.CreateGrantCmds())
|
||||||
rootCmd.AddCommand(util.CreateGrantsCmds())
|
|
||||||
|
|
||||||
util.rootCmd = rootCmd
|
util.rootCmd = rootCmd
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user