working commit

This commit is contained in:
2026-03-08 21:11:45 +02:00
parent efdabf3efc
commit 2f80ce8543
29 changed files with 1437 additions and 886 deletions
-235
View File
@@ -1,235 +0,0 @@
/*
* 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 accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
"mstore/pkg/descr"
)
func (cli *Client) CreateAccount(ctx context.Context, host, user, pass string) (string, error) {
var err error
var res string
params := accoper.CreateAccountParams{
Username: user,
Password: pass,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "accont", "create", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.CreateAccountResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.AccountID
return res, err
}
func (cli *Client) GetAccountByID(ctx context.Context, host, accountID string) (*descr.AccountShort, error) {
var err error
res := &descr.AccountShort{}
params := accoper.GetAccountParams{
AccountID: accountID,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "get", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.GetAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Account
return res, err
}
func (cli *Client) GetAccountByName(ctx context.Context, host, username string) (*descr.AccountShort, error) {
var err error
res := &descr.AccountShort{}
params := accoper.GetAccountParams{
Username: username,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "get", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.GetAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Account
return res, err
}
func (cli *Client) UpdateAccountByID(ctx context.Context, host string, accountID, newUsername, newPassword string) error {
var err error
params := accoper.UpdateAccountParams{
AccountID: accountID,
NewUsername: newUsername,
NewPassword: newPassword,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "update", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.UpdateAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}
func (cli *Client) UpdateAccountByName(ctx context.Context, host, username, newUsername, newPassword string) error {
var err error
params := accoper.UpdateAccountParams{
Username: username,
NewUsername: newUsername,
NewPassword: newPassword,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "update", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.UpdateAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}
func (cli *Client) DeleteAccountByName(ctx context.Context, host, username string) error {
var err error
params := accoper.DeleteAccountParams{
Username: username,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "delete", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.DeleteAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}
func (cli *Client) DeleteAccountByID(ctx context.Context, host, accountID string) error {
var err error
params := accoper.DeleteAccountParams{
AccountID: accountID,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "delete", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.DeleteAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}
func (cli *Client) ListAccounts(ctx context.Context, host string) ([]descr.AccountShort, error) {
var err error
res := make([]descr.AccountShort, 0)
params := accoper.ListAccountsParams{}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
resdata, err := cli.doHTTPCall(ctx, host, "accounts", "list", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.ListAccountsResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Accounts
return res, err
}
+38
View File
@@ -0,0 +1,38 @@
package accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
)
func (cli *Client) CreateAccount(ctx context.Context, host, user, pass string) (string, error) {
var err error
var res string
params := accoper.CreateAccountParams{
Username: user,
Password: pass,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "accont", "create", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.CreateAccountResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.AccountID
return res, err
}
+71
View File
@@ -0,0 +1,71 @@
package accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
)
func (cli *Client) CreateGrantByAccountID(ctx context.Context, host string, accountID, right, pattern string) (string, error) {
var err error
var res string
params := accoper.CreateGrantParams{
AccountID: accountID,
Right: right,
Pattern: pattern,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "create", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.CreateGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.GrantID
return res, err
}
func (cli *Client) CreateGrantByUsername(ctx context.Context, host, username string, right string, pattern string) (string, error) {
var err error
var res string
params := accoper.CreateGrantParams{
Username: username,
Right: right,
Pattern: pattern,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "create", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.CreateGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.GrantID
return res, err
}
+62
View File
@@ -0,0 +1,62 @@
package accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
)
func (cli *Client) DeleteAccountByName(ctx context.Context, host, username string) error {
var err error
params := accoper.DeleteAccountParams{
Username: username,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "delete", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.DeleteAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}
func (cli *Client) DeleteAccountByID(ctx context.Context, host, accountID string) error {
var err error
params := accoper.DeleteAccountParams{
AccountID: accountID,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "delete", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.DeleteAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}
+36
View File
@@ -0,0 +1,36 @@
package accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
)
func (cli *Client) DeleteGrant(ctx context.Context, host, grantID string) error {
var err error
params := accoper.DeleteGrantParams{
GrantID: grantID,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "delete", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.DeleteGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}
+67
View File
@@ -0,0 +1,67 @@
package accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
"mstore/pkg/descr"
)
func (cli *Client) GetAccountByName(ctx context.Context, host, username string) (*descr.AccountShort, error) {
var err error
res := &descr.AccountShort{}
params := accoper.GetAccountParams{
Username: username,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "get", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.GetAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Account
return res, err
}
func (cli *Client) GetAccountByID(ctx context.Context, host, accountID string) (*descr.AccountShort, error) {
var err error
res := &descr.AccountShort{}
params := accoper.GetAccountParams{
AccountID: accountID,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "get", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.GetAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Account
return res, err
}
+39
View File
@@ -0,0 +1,39 @@
package accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
"mstore/pkg/descr"
)
func (cli *Client) GetGrant(ctx context.Context, host, grantID string) (*descr.Grant, error) {
var err error
res := &descr.Grant{}
params := accoper.GetGrantParams{
GrantID: grantID,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "get", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.GetGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Grant
return res, err
}
-216
View File
@@ -1,216 +0,0 @@
/*
* 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 accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
"mstore/pkg/descr"
)
func (cli *Client) CreateGrantByAccountID(ctx context.Context, host string, accountID, right, pattern string) (string, error) {
var err error
var res string
params := accoper.CreateGrantParams{
AccountID: accountID,
Right: right,
Pattern: pattern,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "create", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.CreateGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.GrantID
return res, err
}
func (cli *Client) CreateGrantByUsername(ctx context.Context, host, username string, right string, pattern string) (string, error) {
var err error
var res string
params := accoper.CreateGrantParams{
Username: username,
Right: right,
Pattern: pattern,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "create", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.CreateGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.GrantID
return res, err
}
func (cli *Client) GetGrant(ctx context.Context, host, grantID string) (*descr.Grant, error) {
var err error
res := &descr.Grant{}
params := accoper.GetGrantParams{
GrantID: grantID,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "get", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.GetGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Grant
return res, err
}
func (cli *Client) UpdateGrant(ctx context.Context, host, grantID, newPattern string) error {
var err error
params := accoper.UpdateGrantParams{
GrantID: grantID,
NewPattern: newPattern,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "update", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.UpdateGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}
func (cli *Client) DeleteGrant(ctx context.Context, host, grantID string) error {
var err error
params := accoper.DeleteGrantParams{
GrantID: grantID,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "delete", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.DeleteGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}
func (cli *Client) ListGrantsByAccountID(ctx context.Context, host, accountID string) ([]descr.Grant, error) {
var err error
res := make([]descr.Grant, 0)
params := accoper.ListGrantsParams{
AccountID: accountID,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grants", "list", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.ListGrantsResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Grants
return res, err
}
func (cli *Client) ListGrantsByUsername(ctx context.Context, host, username string) ([]descr.Grant, error) {
var err error
res := make([]descr.Grant, 0)
params := accoper.ListGrantsParams{
Username: username,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grants", "list", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.ListGrantsResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Grants
return res, err
}
@@ -12,43 +12,12 @@ package accntcli
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"strconv"
"mstore/app/handler"
"mstore/app/imageoper"
)
func (cli *Client) ServiceHello(ctx context.Context, host string) (bool, error) {
var res bool
var err error
params := imageoper.SendHelloParams{}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
resdata, err := cli.doHTTPCall(ctx, host, "service", "hello", reqdata)
if err != nil {
return res, err
}
response := handler.Response[imageoper.SendHelloResult]{}
err = json.Unmarshal(resdata, &response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Alive
return res, err
}
func (cli *Client) doHTTPCall(ctx context.Context, host, obj, oper string, req []byte) ([]byte, error) {
var err error
var res []byte
+37
View File
@@ -0,0 +1,37 @@
package accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
"mstore/pkg/descr"
)
func (cli *Client) ListAccounts(ctx context.Context, host string) ([]descr.AccountShort, error) {
var err error
res := make([]descr.AccountShort, 0)
params := accoper.ListAccountsParams{}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
resdata, err := cli.doHTTPCall(ctx, host, "accounts", "list", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.ListAccountsResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Accounts
return res, err
}
+66
View File
@@ -0,0 +1,66 @@
package accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
"mstore/pkg/descr"
)
func (cli *Client) ListGrantsByUsername(ctx context.Context, host, username string) ([]descr.Grant, error) {
var err error
res := make([]descr.Grant, 0)
params := accoper.ListGrantsParams{
Username: username,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grants", "list", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.ListGrantsResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Grants
return res, err
}
func (cli *Client) ListGrantsByAccountID(ctx context.Context, host, accountID string) ([]descr.Grant, error) {
var err error
res := make([]descr.Grant, 0)
params := accoper.ListGrantsParams{
AccountID: accountID,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grants", "list", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.ListGrantsResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Grants
return res, err
}
+23
View File
@@ -34,6 +34,29 @@ func NewReferer(hostname, object, operation string) (*Referer, error) {
return ref, err
}
func ParseHostinfo(hostname string) (*Referer, error) {
ref := &Referer{}
if !strings.Contains(hostname, "://") {
hostname = "https://" + hostname
}
urlobj, err := url.Parse(hostname)
if err != nil {
return ref, err
}
if urlobj.User != nil {
ref.user = urlobj.User.Username()
ref.pass, _ = urlobj.User.Password()
urlobj.User = nil
}
urlobj.Path = "/"
ref.urlobj = urlobj
return ref, err
}
func (ref *Referer) Host() string {
return ref.urlobj.Host
}
func (ref *Referer) Raw() string {
return path.Join(ref.urlobj.Host, "/v3/api/", ref.obj, ref.oper)
}
+36
View File
@@ -0,0 +1,36 @@
package accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/handler"
"mstore/app/imageoper"
)
func (cli *Client) ServiceHello(ctx context.Context, host string) (bool, error) {
var res bool
var err error
params := imageoper.SendHelloParams{}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
resdata, err := cli.doHTTPCall(ctx, host, "service", "hello", reqdata)
if err != nil {
return res, err
}
response := handler.Response[imageoper.SendHelloResult]{}
err = json.Unmarshal(resdata, &response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.Alive
return res, err
}
+64
View File
@@ -0,0 +1,64 @@
package accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
)
func (cli *Client) UpdateAccountByName(ctx context.Context, host, username, newUsername, newPassword string) error {
var err error
params := accoper.UpdateAccountParams{
Username: username,
NewUsername: newUsername,
NewPassword: newPassword,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "update", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.UpdateAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}
func (cli *Client) UpdateAccountByID(ctx context.Context, host string, accountID, newUsername, newPassword string) error {
var err error
params := accoper.UpdateAccountParams{
AccountID: accountID,
NewUsername: newUsername,
NewPassword: newPassword,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
resdata, err := cli.doHTTPCall(ctx, host, "account", "update", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.UpdateAccountResult]()
err = json.Unmarshal(resdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}
+36
View File
@@ -0,0 +1,36 @@
package accntcli
import (
"context"
"encoding/json"
"errors"
"mstore/app/accoper"
"mstore/app/handler"
)
func (cli *Client) UpdateGrant(ctx context.Context, host, grantID, newPattern string) error {
var err error
params := accoper.UpdateGrantParams{
GrantID: grantID,
NewPattern: newPattern,
}
reqdata, err := json.Marshal(params)
if err != nil {
return err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "update", reqdata)
if err != nil {
return err
}
response := handler.NewResponse[accoper.UpdateGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return err
}
if response.Error {
err = errors.New(response.Message)
return err
}
return err
}