alittle splitted mstorectl code; etc

This commit is contained in:
2026-03-05 12:26:14 +02:00
parent 80d6a244cf
commit 223ae2e96e
24 changed files with 631 additions and 104 deletions
+17 -17
View File
@@ -14,8 +14,8 @@ import (
"encoding/json"
"fmt"
"mstore/app/accoper"
"mstore/app/handler"
"mstore/app/operator"
"mstore/pkg/descr"
)
@@ -27,7 +27,7 @@ func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, passwor
if err != nil {
return res, err
}
operParams := operator.CreateAccountParams{
operParams := accoper.CreateAccountParams{
Username: username,
Password: password,
}
@@ -40,7 +40,7 @@ func (cli *Client) CreateAccount(ctx context.Context, hosturi, username, passwor
return res, err
}
operRes := handler.NewResponse[operator.CreateAccountResult]()
operRes := handler.NewResponse[accoper.CreateAccountResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return res, err
@@ -62,7 +62,7 @@ func (cli *Client) GetAccountByID(ctx context.Context, hosturi, accountID string
return res, err
}
operParams := operator.GetAccountParams{
operParams := accoper.GetAccountParams{
AccountID: accountID,
}
paramsJson, err := json.Marshal(operParams)
@@ -74,7 +74,7 @@ func (cli *Client) GetAccountByID(ctx context.Context, hosturi, accountID string
return res, err
}
operRes := handler.NewResponse[operator.GetAccountResult]()
operRes := handler.NewResponse[accoper.GetAccountResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return res, err
@@ -95,7 +95,7 @@ func (cli *Client) GetAccountByName(ctx context.Context, hosturi, username strin
if err != nil {
return res, err
}
operParams := operator.GetAccountParams{
operParams := accoper.GetAccountParams{
Username: username,
}
paramsJson, err := json.Marshal(operParams)
@@ -107,7 +107,7 @@ func (cli *Client) GetAccountByName(ctx context.Context, hosturi, username strin
return res, err
}
operRes := handler.NewResponse[operator.GetAccountResult]()
operRes := handler.NewResponse[accoper.GetAccountResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return res, err
@@ -127,7 +127,7 @@ func (cli *Client) UpdateAccountByID(ctx context.Context, hosturi string, accoun
if err != nil {
return err
}
operParams := operator.UpdateAccountParams{
operParams := accoper.UpdateAccountParams{
AccountID: accountID,
NewUsername: newUsername,
NewPassword: newPassword,
@@ -140,7 +140,7 @@ func (cli *Client) UpdateAccountByID(ctx context.Context, hosturi string, accoun
if err != nil {
return err
}
operRes := handler.NewResponse[operator.UpdateAccountResult]()
operRes := handler.NewResponse[accoper.UpdateAccountResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return err
@@ -158,7 +158,7 @@ func (cli *Client) UpdateAccountByName(ctx context.Context, hosturi, username, n
if err != nil {
return err
}
operParams := operator.UpdateAccountParams{
operParams := accoper.UpdateAccountParams{
Username: username,
NewUsername: newUsername,
NewPassword: newPassword,
@@ -171,7 +171,7 @@ func (cli *Client) UpdateAccountByName(ctx context.Context, hosturi, username, n
if err != nil {
return err
}
operRes := handler.NewResponse[operator.UpdateAccountResult]()
operRes := handler.NewResponse[accoper.UpdateAccountResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return err
@@ -190,7 +190,7 @@ func (cli *Client) DeleteAccountByName(ctx context.Context, hosturi, username st
if err != nil {
return err
}
operParams := operator.DeleteAccountParams{
operParams := accoper.DeleteAccountParams{
Username: username,
}
paramsJson, err := json.Marshal(operParams)
@@ -202,7 +202,7 @@ func (cli *Client) DeleteAccountByName(ctx context.Context, hosturi, username st
return err
}
operRes := handler.NewResponse[operator.DeleteAccountResult]()
operRes := handler.NewResponse[accoper.DeleteAccountResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return err
@@ -221,7 +221,7 @@ func (cli *Client) DeleteAccountByID(ctx context.Context, hosturi, accountID str
if err != nil {
return err
}
operParams := operator.DeleteAccountParams{
operParams := accoper.DeleteAccountParams{
AccountID: accountID,
}
paramsJson, err := json.Marshal(operParams)
@@ -233,7 +233,7 @@ func (cli *Client) DeleteAccountByID(ctx context.Context, hosturi, accountID str
return err
}
operRes := handler.NewResponse[operator.DeleteAccountResult]()
operRes := handler.NewResponse[accoper.DeleteAccountResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return err
@@ -253,7 +253,7 @@ func (cli *Client) ListAccounts(ctx context.Context, hosturi string) ([]descr.Ac
if err != nil {
return res, err
}
operParams := operator.ListAccountsParams{}
operParams := accoper.ListAccountsParams{}
paramsJson, err := json.Marshal(operParams)
if err != nil {
return res, err
@@ -263,7 +263,7 @@ func (cli *Client) ListAccounts(ctx context.Context, hosturi string) ([]descr.Ac
return res, err
}
operRes := handler.NewResponse[operator.ListAccountsResult]()
operRes := handler.NewResponse[accoper.ListAccountsResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return res, err
+15 -15
View File
@@ -14,8 +14,8 @@ import (
"encoding/json"
"fmt"
"mstore/app/accoper"
"mstore/app/handler"
"mstore/app/operator"
"mstore/pkg/descr"
)
@@ -27,7 +27,7 @@ func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi string, a
if err != nil {
return res, err
}
operParams := operator.CreateGrantParams{
operParams := accoper.CreateGrantParams{
AccountID: accountID,
Right: right,
Pattern: pattern,
@@ -41,7 +41,7 @@ func (cli *Client) CreateGrantByAccountID(ctx context.Context, hosturi string, a
return res, err
}
operRes := handler.NewResponse[operator.CreateGrantResult]()
operRes := handler.NewResponse[accoper.CreateGrantResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return res, err
@@ -62,7 +62,7 @@ func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username
if err != nil {
return res, err
}
operParams := operator.CreateGrantParams{
operParams := accoper.CreateGrantParams{
Username: username,
Right: right,
Pattern: pattern,
@@ -76,7 +76,7 @@ func (cli *Client) CreateGrantByUsername(ctx context.Context, hosturi, username
return res, err
}
operRes := handler.NewResponse[operator.CreateGrantResult]()
operRes := handler.NewResponse[accoper.CreateGrantResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return res, err
@@ -97,7 +97,7 @@ func (cli *Client) GetGrant(ctx context.Context, hosturi, grantID string) (*desc
if err != nil {
return res, err
}
operParams := operator.GetGrantParams{
operParams := accoper.GetGrantParams{
GrantID: grantID,
}
paramsJson, err := json.Marshal(operParams)
@@ -109,7 +109,7 @@ func (cli *Client) GetGrant(ctx context.Context, hosturi, grantID string) (*desc
return res, err
}
operRes := handler.NewResponse[operator.GetGrantResult]()
operRes := handler.NewResponse[accoper.GetGrantResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return res, err
@@ -129,7 +129,7 @@ func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern
if err != nil {
return err
}
operParams := operator.UpdateGrantParams{
operParams := accoper.UpdateGrantParams{
GrantID: grantID,
NewPattern: newPattern,
}
@@ -141,7 +141,7 @@ func (cli *Client) UpdateGrant(ctx context.Context, hosturi, grantID, newPattern
if err != nil {
return err
}
operRes := handler.NewResponse[operator.UpdateGrantResult]()
operRes := handler.NewResponse[accoper.UpdateGrantResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return err
@@ -160,7 +160,7 @@ func (cli *Client) DeleteGrant(ctx context.Context, hosturi, grantID string) err
if err != nil {
return err
}
operParams := operator.DeleteGrantParams{
operParams := accoper.DeleteGrantParams{
GrantID: grantID,
}
paramsJson, err := json.Marshal(operParams)
@@ -172,7 +172,7 @@ func (cli *Client) DeleteGrant(ctx context.Context, hosturi, grantID string) err
return err
}
operRes := handler.NewResponse[operator.DeleteGrantResult]()
operRes := handler.NewResponse[accoper.DeleteGrantResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return err
@@ -192,7 +192,7 @@ func (cli *Client) ListGrantsByAccountID(ctx context.Context, hosturi, accountID
if err != nil {
return res, err
}
operParams := operator.ListGrantsParams{
operParams := accoper.ListGrantsParams{
AccountID: accountID,
}
paramsJson, err := json.Marshal(operParams)
@@ -204,7 +204,7 @@ func (cli *Client) ListGrantsByAccountID(ctx context.Context, hosturi, accountID
return res, err
}
operRes := handler.NewResponse[operator.ListGrantsResult]()
operRes := handler.NewResponse[accoper.ListGrantsResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return res, err
@@ -225,7 +225,7 @@ func (cli *Client) ListGrantsByUsername(ctx context.Context, hosturi, username s
if err != nil {
return res, err
}
operParams := operator.ListGrantsParams{
operParams := accoper.ListGrantsParams{
Username: username,
}
paramsJson, err := json.Marshal(operParams)
@@ -237,7 +237,7 @@ func (cli *Client) ListGrantsByUsername(ctx context.Context, hosturi, username s
return res, err
}
operRes := handler.NewResponse[operator.ListGrantsResult]()
operRes := handler.NewResponse[accoper.ListGrantsResult]()
err = json.Unmarshal(respBytes, operRes)
if err != nil {
return res, err
+37
View File
@@ -0,0 +1,37 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*
* This work is published and licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package client
import (
"net/url"
"path"
"strings"
)
func repackServiceURI(fileuri string) (string, string, string, error) {
var err error
var res, username, password string
if !strings.Contains(fileuri, "://") {
fileuri = "https://" + fileuri
}
uri, err := url.Parse(fileuri)
if err != nil {
return res, username, password, err
}
uri.Path = path.Clean(uri.Path)
if uri.User != nil {
username = uri.User.Username()
password, _ = uri.User.Password()
}
uri.User = nil
//uri.Scheme = "https"
res = uri.String()
return res, username, password, err
}