feat: update tmux and redis

This commit is contained in:
Tosone committed 2025-12-11 10:32:48 +08:00
1 parent f762d0d5ee
commit 66e00550c4
20 files changed
+23 -1321

No files matched your search

-22
View File
@@ -1,22 +0,0 @@
package cr
import (
"context"
"github.com/spf13/cobra"
)
func NewCmdCR(ctx context.Context) (cmd *cobra.Command) {
cmd = &cobra.Command{
Use: "cr",
Short: "container registry managing operation",
RunE: func(_ *cobra.Command, args []string) (err error) {
return
},
}
var commands = []*cobra.Command{
NewCmdCRPublicRepo(ctx),
}
cmd.AddCommand(commands...)
return
}
-448
View File
@@ -1,448 +0,0 @@
package cr
import (
"context"
"crypto/tls"
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
"strings"
"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/config/types"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
"code.byted.org/infcp/vecps-cli/pkg/aksk"
"code.byted.org/infcp/vecps-cli/pkg/constant"
"code.byted.org/infcp/vecps-cli/pkg/pf"
"code.byted.org/infcp/vecps-cli/pkg/vecpsdk"
)
const accountId = "1" // the admin account id
const policyName = "container-registry" // the container registry policy name
var region string
var username string
var password string
var tel string
var email string
var namespace string
var registry string
var tarball string
var images string
var externalIam string
var externalTop string
// sourceConfig contains all registries and images information read from the source YAML file
type sourceConfig map[string]map[string][]string
func NewCmdCRPublicRepo(ctx context.Context) (cmd *cobra.Command) {
cmd = &cobra.Command{
Use: "public-repo",
Short: "container registry create public repo",
RunE: func(_ *cobra.Command, _ []string) (err error) {
var userId int
if userId, err = ensureUser(ctx, externalIam); err != nil {
return
}
logrus.Info("Create user success")
var ak, sk string
if ak, sk, err = createAccessKey(ctx, externalIam); err != nil {
return
}
logrus.Info("Create access key for user success")
defer func() {
var err error
if err = deleteAccessKey(ctx, ak, externalIam); err != nil {
return
}
logrus.Info("Delete access key for the user")
}()
var reg name.Registry
if reg, err = name.NewRegistry(registry); err != nil {
return
}
var loginOpt = loginOptions{
serverAddress: reg.Name(),
user: fmt.Sprintf("%s@%d", username, userId),
password: password,
}
if err = loginRegistry(loginOpt); err != nil {
return
}
if tarball == "" {
err = fmt.Errorf("tarball should be set")
return
}
var transport = http.DefaultTransport.(*http.Transport).Clone()
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
var options []crane.Option
options = append(options, crane.WithTransport(transport))
var sourceData []byte
if sourceData, err = ioutil.ReadFile(images); err != nil {
return
}
var source sourceConfig
if err = yaml.Unmarshal(sourceData, &source); err != nil {
return
}
var srcList []string
for key, value := range source {
for k, v := range value {
for _, tag := range v {
srcList = append(srcList, fmt.Sprintf("%s/%s:%s", key, k, tag))
}
}
}
if err = ensureCR(ctx, userId, ak, sk, srcList, externalTop); err != nil {
return
}
logrus.Info("Create public repos success")
for _, src := range srcList {
var image v1.Image
if image, err = crane.LoadTag(tarball, src); err != nil {
err = fmt.Errorf("loading %s as tarball: %v", tarball, err)
return
}
var tag name.Tag
if tag, err = name.NewTag(src, name.StrictValidation); err != nil {
return
}
var repository = tag.RepositoryStr()
var repositoryList = strings.Split(repository, "/")
if len(repositoryList) == 2 {
repository = fmt.Sprintf("%s/%s", namespace, repositoryList[1])
}
logrus.WithField("image", fmt.Sprintf("%s/%s:%s", registry, repository, tag.TagStr())).Info("Image is pushing...")
if err = crane.Push(image, fmt.Sprintf("%s/%s:%s", registry, repository, tag.TagStr()), options...); err != nil {
return
}
}
logrus.Info("Create public repos success")
return
},
}
cmd.PersistentFlags().StringVarP(&externalIam, "external-iam", "", "", "external iam or will use cluster inner iam")
cmd.PersistentFlags().StringVarP(&externalTop, "external-top", "", "", "external top or will use cluster inner top")
cmd.PersistentFlags().StringVarP(&region, "region", "", "cn-north-1", "vecps region")
cmd.PersistentFlags().StringVarP(&username, "username", "", "container-registry", "container registry public repo operator username")
cmd.PersistentFlags().StringVarP(&password, "password", "", "Pwd123456!", "container registry public repo operator password")
cmd.PersistentFlags().StringVarP(&tel, "tel", "", "17010001000", "container registry public repo operator telephone")
cmd.PersistentFlags().StringVarP(&email, "email", "", "vecps@bytedance.com", "container registry public repo operator email")
cmd.PersistentFlags().StringVarP(&namespace, "image-namespace", "", "library", "container registry public repo namespace")
cmd.PersistentFlags().StringVarP(&registry, "registry", "", "registry.vecps.com", "container registry domain name")
cmd.PersistentFlags().StringVarP(&tarball, "tarball", "", "", "tarball path")
cmd.PersistentFlags().StringVarP(&images, "images", "l", "", "image list to pull")
return
}
type loginOptions struct {
serverAddress string
user string
password string
}
func loginRegistry(opts loginOptions) (err error) {
if opts.user == "" && opts.password == "" {
return errors.New("username and password required")
}
var cf *configfile.ConfigFile
if cf, err = config.Load(os.Getenv("DOCKER_CONFIG")); err != nil {
return
}
var creds = cf.GetCredentialsStore(opts.serverAddress)
if opts.serverAddress == name.DefaultRegistry {
opts.serverAddress = authn.DefaultAuthKey
}
if err = creds.Store(types.AuthConfig{
ServerAddress: opts.serverAddress,
Username: opts.user,
Password: opts.password,
}); err != nil {
return
}
if err = cf.Save(); err != nil {
return
}
logrus.Infof("Login registry success via %s", opts.serverAddress)
return
}
func createAccessKey(ctx context.Context, externalIam string) (ak, sk string, err error) {
var address string
if externalIam == "" {
var iamP *pf.PortForward
if iamP, err = pf.New(context.Background(), constant.AppsNamespace, "app=volc-iam", 6789, "localhost", 0); err != nil {
return
}
defer func() {
iamP.Clean()
}()
if len(iamP.LocalPorts) < 1 {
err = fmt.Errorf("cannot port forward volc-iam, check the volc-iam pod is healthy or not")
return
}
var iamPort = iamP.LocalPorts[0]
address = fmt.Sprintf("%s:%d", "localhost", iamPort)
} else {
address = externalIam
}
var akskResult aksk.Result
if akskResult, err = aksk.Get(ctx); err != nil {
return
}
var client = vecpsdk.New(address, akskResult.IAM.AK, akskResult.IAM.SK, region, "iam")
var keys []*vecpsdk.ListAccessKeysResp
if keys, err = client.ListAccessKeys(accountId, username); err != nil {
return
}
for _, key := range keys {
if err = client.DeleteAccessKey(accountId, key.AccessKeyId); err != nil {
return
}
}
logrus.Info("Clear all of access key")
var resp vecpsdk.CreateAccessKeyResp
if resp, err = client.CreateAccessKey(accountId, username); err != nil {
return
}
ak = resp.AccessKeyId
sk = resp.SecretAccessKey
return
}
func deleteAccessKey(ctx context.Context, ak string, externalIam string) (err error) {
var address string
if externalIam == "" {
var iamP *pf.PortForward
if iamP, err = pf.New(context.Background(), constant.AppsNamespace, "app=volc-iam", 6789, "localhost", 0); err != nil {
return
}
defer func() {
iamP.Clean()
}()
if len(iamP.LocalPorts) < 1 {
err = fmt.Errorf("cannot port forward volc-iam, check the volc-iam pod is healthy or not")
return
}
var iamPort = iamP.LocalPorts[0]
address = fmt.Sprintf("%s:%d", "localhost", iamPort)
} else {
address = externalIam
}
var akskResult aksk.Result
if akskResult, err = aksk.Get(ctx); err != nil {
return
}
var client = vecpsdk.New(address, akskResult.IAM.AK, akskResult.IAM.SK, region, "iam")
if err = client.DeleteAccessKey(accountId, ak); err != nil {
return
}
return
}
func ensureCR(_ context.Context, userId int, ak, sk string, srcList []string, externalTop string) (err error) {
var address string
if externalTop == "" {
var topP *pf.PortForward
if topP, err = pf.New(context.Background(), constant.AppsNamespace, "app=volc-top", 8000, "localhost", 0); err != nil {
return
}
defer func() {
topP.Clean()
}()
if len(topP.LocalPorts) < 1 {
err = fmt.Errorf("cannot port forward volc-top, check the volc-top pod is healthy or not")
return
}
var iamPort = topP.LocalPorts[0]
address = fmt.Sprintf("%s:%d", "localhost", iamPort)
} else {
address = externalTop
}
var client = vecpsdk.New(address, ak, sk, region, "cr")
// 1. ensure user exist in cr
{
var exist bool
if exist, err = client.CRGetUserBasic(); err != nil {
return
}
if !exist {
if err = client.CRCreateUserBasic(password); err != nil {
return
}
}
}
logrus.WithField("username", fmt.Sprintf("%s@%d", username, userId)).
WithField("password", password).
Info("Now you can login with docker")
// 2. ensure namespace
{
var exist bool
if exist, err = client.CRValidateNamespaceBasic(namespace); err != nil {
return
}
if !exist {
if err = client.CRCreateNamespaceBasic(namespace); err != nil {
return
}
}
}
// 3. ensure repos
{
for _, src := range srcList {
var tag name.Tag
if tag, err = name.NewTag(src, name.StrictValidation); err != nil {
return
}
var repository = tag.RepositoryStr()
var repositoryList = strings.Split(repository, "/")
if len(repositoryList) == 2 {
repository = fmt.Sprintf("%s/%s", namespace, repositoryList[1])
}
var exist bool
if exist, err = client.CRValidateRepositoryBasic(namespace, repository); err != nil {
return
}
if !exist {
if err = client.CRCreateRepositoryBasic(namespace, repository); err != nil {
logrus.Info(err)
return
}
logrus.WithField("repo", repository).Debug("Repo create success")
} else {
logrus.WithField("repo", repository).Debug("Repo already exist")
}
}
}
return
}
func ensureUser(ctx context.Context, externalIam string) (userId int, err error) {
var address string
if externalIam == "" {
var iamP *pf.PortForward
if iamP, err = pf.New(context.Background(), constant.AppsNamespace, "app=volc-iam", 6789, "localhost", 0); err != nil {
return
}
defer func() {
iamP.Clean()
}()
if len(iamP.LocalPorts) < 1 {
err = fmt.Errorf("cannot port forward volc-iam, check the volc-iam pod is healthy or not")
return
}
var iamPort = iamP.LocalPorts[0]
address = fmt.Sprintf("%s:%d", "localhost", iamPort)
} else {
address = externalIam
}
var akskResult aksk.Result
if akskResult, err = aksk.Get(ctx); err != nil {
return
}
var client = vecpsdk.New(address, akskResult.IAM.AK, akskResult.IAM.SK, region, "iam")
// 1. ensure user exist
{
var exist bool
if exist, err = client.CheckUserExist(accountId, username); err != nil {
return
}
if !exist {
if err = client.CreateUser(accountId, username, tel, email); err != nil {
return
}
if err = client.CreateLoginProfile(accountId, username, password); err != nil {
return
}
}
}
// 2. ensure policy exist
{
if err = client.GetPolicy(accountId, policyName); err != nil {
if err == vecpsdk.ErrResourceNotFound {
if err = client.CreatePolicy(accountId, policyName); err != nil {
return
}
} else {
return
}
}
}
// 3. ensure user attatch the policy
{
var exist bool
if exist, err = client.CheckAttachedUserPoliciesExist(accountId, username, policyName); err != nil {
return
}
if !exist {
if err = client.AttachUserPolicy(accountId, username, policyName); err != nil {
return
}
}
}
// 4. get user id
{
if userId, err = client.GetUser(accountId, username); err != nil {
return
}
}
return
}
-2
View File
@@ -18,7 +18,6 @@ import (
"code.byted.org/infcp/vecps-cli/cmd/vecps/cert"
"code.byted.org/infcp/vecps-cli/cmd/vecps/compose"
"code.byted.org/infcp/vecps-cli/cmd/vecps/cr"
"code.byted.org/infcp/vecps-cli/cmd/vecps/es8"
"code.byted.org/infcp/vecps-cli/cmd/vecps/milvus"
"code.byted.org/infcp/vecps-cli/cmd/vecps/oldexpose"
@@ -123,7 +122,6 @@ func New() (root *cobra.Command) {
var ctx = context.Background()
var commands = []*cobra.Command{
cr.NewCmdCR(ctx),
oldexpose.NewCmdExpose(ctx),
cert.NewCmdCert(ctx),
compose.NewCmdK9s(ctx),
-7
View File
@@ -4,7 +4,6 @@ go 1.24.0
require (
github.com/aws/aws-sdk-go v1.55.5
github.com/docker/cli v26.1.3+incompatible
github.com/dustin/go-humanize v1.0.1
github.com/elastic/go-elasticsearch/v8 v8.16.0
github.com/fatih/color v1.17.0
@@ -42,12 +41,8 @@ require (
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v26.1.3+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
@@ -86,7 +81,6 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/spdystream v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
@@ -107,7 +101,6 @@ require (
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/vbatts/tar-split v0.11.3 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
-19
View File
@@ -282,7 +282,6 @@ gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zum
git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc=
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno=
github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo=
@@ -363,13 +362,10 @@ github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9D
github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ=
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
github.com/containerd/stargz-snapshotter/estargz v0.14.3 h1:OqlDCK3ZVUO6C3B/5FSkDwbkEETK84kQgEeFwDC+62k=
github.com/containerd/stargz-snapshotter/estargz v0.14.3/go.mod h1:KY//uOCIkSuNAHhJogcZtrNHdKrA99/FCCRjE3HD36o=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -380,14 +376,6 @@ github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6ps
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/docker/cli v26.1.3+incompatible h1:bUpXT/N0kDE3VUHI2r5VMsYQgi38kYuoC0oL9yt3lqc=
github.com/docker/cli v26.1.3+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v26.1.3+incompatible h1:lLCzRbrVZrljpVNobJu1J2FHk8V0s4BawoZippkc+xo=
github.com/docker/docker v26.1.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A=
github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 h1:iFaUwBSo5Svw6L7HYpRu/0lE3e0BaElwnNO1qkNQxBY=
github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj60/X5sZFNxpG4HBPDHVqxNm4DfnCKgrbZOT+s=
@@ -790,7 +778,6 @@ github.com/milvus-io/milvus-sdk-go/v2 v2.4.2 h1:Xqf+S7iicElwYoS2Zly8Nf/zKHuZsNy1
github.com/milvus-io/milvus-sdk-go/v2 v2.4.2/go.mod h1:ulO1YUXKH0PGg50q27grw048GDY9ayB4FPmh7D+FFTA=
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY=
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
@@ -880,7 +867,6 @@ github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtm
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
@@ -945,15 +931,12 @@ github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oW
github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/vbatts/tar-split v0.11.3 h1:hLFqsOLQ1SsppQNTMpkpPXClLDfC2A3Zgy9OUU+RVck=
github.com/vbatts/tar-split v0.11.3/go.mod h1:9QlHN18E+fEH7RdG+QAJJcuya3rqT7eXSTY7wGrAokY=
github.com/wI2L/jsondiff v0.6.0 h1:zrsH3FbfVa3JO9llxrcDy/XLkYPLgoMX6Mz3T2PP2AI=
github.com/wI2L/jsondiff v0.6.0/go.mod h1:D6aQ5gKgPF9g17j+E9N7aasmU1O+XvfmWm1y8UMmNpw=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
@@ -1377,7 +1360,6 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220906165534-d0df966e6959/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -1799,7 +1781,6 @@ gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM=
gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
+1 -1
View File
@@ -1,4 +1,4 @@
FROM alpine:3.22
FROM alpine:3.23
LABEL maintainer="Tosone <i@tosone.cn>"
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash
version=8.2.3
version=8.4.0
clean_up () {
if [ -d redis ]; then
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash
version=3.5a
version=3.6a
clean_up () {
if [ -d tmux ]; then
+5 -5
View File
@@ -7,18 +7,18 @@ import (
"code.byted.org/infcp/vecps-cli/pkg/util"
)
//go:generate wget -c -q -O redis-linux-amd64-8.2.3.tar.gz https://fs.tosone.cn/vecps-cli/addons/redis/redis-linux-amd64-8.2.3.tar.gz
//go:generate wget -c -q -O redis-linux-amd64-8.2.3.tar.gz.sha256 https://fs.tosone.cn/vecps-cli/addons/redis/redis-linux-amd64-8.2.3.tar.gz.sha256
//go:generate shasum -a 256 -c redis-linux-amd64-8.2.3.tar.gz.sha256
//go:generate wget -c -q -O redis-linux-amd64-8.4.0.tar.gz https://fs.tosone.cn/vecps-cli/addons/redis/redis-linux-amd64-8.4.0.tar.gz
//go:generate wget -c -q -O redis-linux-amd64-8.4.0.tar.gz.sha256 https://fs.tosone.cn/vecps-cli/addons/redis/redis-linux-amd64-8.4.0.tar.gz.sha256
//go:generate shasum -a 256 -c redis-linux-amd64-8.4.0.tar.gz.sha256
//go:embed redis-linux-amd64-8.2.3.tar.gz
//go:embed redis-linux-amd64-8.4.0.tar.gz
var data embed.FS
// Initialize ...
func Initialize() (err error) {
var archive = &util.Archive{
EmbedFile: data,
Filename: "redis-linux-amd64-8.2.3.tar.gz",
Filename: "redis-linux-amd64-8.4.0.tar.gz",
Core: "redis/",
}
if err = archive.Dump(); err != nil {
+5 -5
View File
@@ -7,18 +7,18 @@ import (
"code.byted.org/infcp/vecps-cli/pkg/util"
)
//go:generate wget -c -q -O redis-linux-arm64-8.2.3.tar.gz https://fs.tosone.cn/vecps-cli/addons/redis/redis-linux-arm64-8.2.3.tar.gz
//go:generate wget -c -q -O redis-linux-arm64-8.2.3.tar.gz.sha256 https://fs.tosone.cn/vecps-cli/addons/redis/redis-linux-arm64-8.2.3.tar.gz.sha256
//go:generate shasum -a 256 -c redis-linux-arm64-8.2.3.tar.gz.sha256
//go:generate wget -c -q -O redis-linux-arm64-8.4.0.tar.gz https://fs.tosone.cn/vecps-cli/addons/redis/redis-linux-arm64-8.4.0.tar.gz
//go:generate wget -c -q -O redis-linux-arm64-8.4.0.tar.gz.sha256 https://fs.tosone.cn/vecps-cli/addons/redis/redis-linux-arm64-8.4.0.tar.gz.sha256
//go:generate shasum -a 256 -c redis-linux-arm64-8.4.0.tar.gz.sha256
//go:embed redis-linux-arm64-8.2.3.tar.gz
//go:embed redis-linux-arm64-8.4.0.tar.gz
var data embed.FS
// Initialize ...
func Initialize() (err error) {
var archive = &util.Archive{
EmbedFile: data,
Filename: "redis-linux-arm64-8.2.3.tar.gz",
Filename: "redis-linux-arm64-8.4.0.tar.gz",
Core: "redis/",
}
if err = archive.Dump(); err != nil {
+5 -5
View File
@@ -7,18 +7,18 @@ import (
"code.byted.org/infcp/vecps-cli/pkg/util"
)
//go:generate wget -c -q -O tmux-linux-amd64-3.5a.tar.gz https://fs.tosone.cn/vecps-cli/addons/tmux/tmux-linux-amd64-3.5a.tar.gz
//go:generate wget -c -q -O tmux-linux-amd64-3.5a.tar.gz.sha256 https://fs.tosone.cn/vecps-cli/addons/tmux/tmux-linux-amd64-3.5a.tar.gz.sha256
//go:generate shasum -a 256 -c tmux-linux-amd64-3.5a.tar.gz.sha256
//go:generate wget -c -q -O tmux-linux-amd64-3.6a.tar.gz https://fs.tosone.cn/vecps-cli/addons/tmux/tmux-linux-amd64-3.6a.tar.gz
//go:generate wget -c -q -O tmux-linux-amd64-3.6a.tar.gz.sha256 https://fs.tosone.cn/vecps-cli/addons/tmux/tmux-linux-amd64-3.6a.tar.gz.sha256
//go:generate shasum -a 256 -c tmux-linux-amd64-3.6a.tar.gz.sha256
//go:embed tmux-linux-amd64-3.5a.tar.gz
//go:embed tmux-linux-amd64-3.6a.tar.gz
var data embed.FS
// Initialize ...
func Initialize() error {
var archive = &util.Archive{
EmbedFile: data,
Filename: "tmux-linux-amd64-3.5a.tar.gz",
Filename: "tmux-linux-amd64-3.6a.tar.gz",
Core: "tmux/",
}
err := archive.Dump()
+5 -5
View File
@@ -7,18 +7,18 @@ import (
"code.byted.org/infcp/vecps-cli/pkg/util"
)
//go:generate wget -c -q -O tmux-linux-arm64-3.5a.tar.gz https://fs.tosone.cn/vecps-cli/addons/tmux/tmux-linux-arm64-3.5a.tar.gz
//go:generate wget -c -q -O tmux-linux-arm64-3.5a.tar.gz.sha256 https://fs.tosone.cn/vecps-cli/addons/tmux/tmux-linux-arm64-3.5a.tar.gz.sha256
//go:generate shasum -a 256 -c tmux-linux-arm64-3.5a.tar.gz.sha256
//go:generate wget -c -q -O tmux-linux-arm64-3.6a.tar.gz https://fs.tosone.cn/vecps-cli/addons/tmux/tmux-linux-arm64-3.6a.tar.gz
//go:generate wget -c -q -O tmux-linux-arm64-3.6a.tar.gz.sha256 https://fs.tosone.cn/vecps-cli/addons/tmux/tmux-linux-arm64-3.6a.tar.gz.sha256
//go:generate shasum -a 256 -c tmux-linux-arm64-3.6a.tar.gz.sha256
//go:embed tmux-linux-arm64-3.5a.tar.gz
//go:embed tmux-linux-arm64-3.6a.tar.gz
var data embed.FS
// Initialize ...
func Initialize() error {
var archive = &util.Archive{
EmbedFile: data,
Filename: "tmux-linux-arm64-3.5a.tar.gz",
Filename: "tmux-linux-arm64-3.6a.tar.gz",
Core: "tmux/",
}
err := archive.Dump()
-98
View File
@@ -1,98 +0,0 @@
package vecpsdk
import (
"encoding/json"
"fmt"
"net/http"
)
func (i Client) CreateAccessKey(account, username string) (accessKeyResp CreateAccessKeyResp, err error) {
var u = fmt.Sprintf("%s/accesskey?Action=CreateAccessKey&Version=2018-01-01&UserName=%s&X-Account-Id=%s", i.Host, username, account)
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("create access key with bad status code: %d, %s", code, string(data))
return
}
var result CommonResponse
if err = json.Unmarshal(data, &result); err != nil {
return
}
var resultAKSK = make(map[string]CreateAccessKeyResp)
if err = json.Unmarshal(result.Result, &resultAKSK); err != nil {
return
}
var ok bool
if accessKeyResp, ok = resultAKSK["AccessKey"]; !ok {
err = fmt.Errorf("get access key with error")
return
}
return
}
func (i Client) DeleteAccessKey(account, accessKeyId string) (err error) {
var u = fmt.Sprintf("%s/accesskey?Action=DeleteAccessKey&Version=2018-01-01&AccessKeyId=%s&X-Account-Id=%s", i.Host, accessKeyId, account)
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("cdelete access key with bad status code: %d, %s", code, string(data))
return
}
return
}
func (i Client) ListAccessKeys(account, username string) (keys []*ListAccessKeysResp, err error) {
var u = fmt.Sprintf("%s/accesskey?Action=ListAccessKeys&Version=2018-01-01&UserName=%s&X-Account-Id=%s", i.Host, username, account)
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("cdelete access key with bad status code: %d, %s", code, string(data))
return
}
var result CommonResponse
if err = json.Unmarshal(data, &result); err != nil {
return
}
type XResponse struct {
AccessKeyMetadata []*ListAccessKeysResp `json:"AccessKeyMetadata"`
}
var xResponse XResponse
if err = json.Unmarshal(result.Result, &xResponse); err != nil {
return
}
keys = xResponse.AccessKeyMetadata
return
}
-20
View File
@@ -1,20 +0,0 @@
package vecpsdk
import (
"fmt"
"testing"
)
func TestIAMUtil_CreateUser(t *testing.T) {
var c = New("172.19.20.86:16789", "AKLTM2M3ZjRmMTM1MDk0NDUyYWIxZmY1OWJlODlmOTk0NGY", "WkdWak5ERXlOMlUwT0dJMU5EQm1PVGt6WlRVMU9UQTRZbVEwTkRGaU5tRQ==", "cn-north-1", "iam")
// var username = "tosone13"
// fmt.Println(c.CreateUser(username, "17010209162", "tosone@qq.com"))
// fmt.Println(c.CreateLoginProfile(username, "8541539655Aa!"))
// fmt.Println(c.CreatePolicy("1", "testx"))
// fmt.Println(c.GetPolicy("1", "testx"))
// fmt.Println(c.CreateAccessKey("1", "container-registry"))
fmt.Println(c.DeleteAccessKey("1", "AKLTMmY1YTI1MjM0MjQ3NDk2Njk4NDgzMzUxNGQwMjM4NmI"))
// fmt.Println(c.AttachUserPolicy(username, "container-manager"))
// fmt.Println(c.ListAttachedUserPolicies(username))
// fmt.Println(c.ListUser("1"))
}
-220
View File
@@ -1,220 +0,0 @@
package vecpsdk
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func (i Client) CRCreateUserBasic(password string) (err error) {
var u = fmt.Sprintf("%s?Action=CreateUserBasic&Version=2021-03-03", i.Host)
type CRCreateUserReq struct {
Password string `json:"Password"`
}
var crCreateUserReq = CRCreateUserReq{Password: password}
var reqBody []byte
if reqBody, err = json.Marshal(crCreateUserReq); err != nil {
return
}
var req *http.Request
if req, err = http.NewRequest(http.MethodPost, u, bytes.NewBuffer(reqBody)); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("cr create user with bad status code: %d, %s", code, string(data))
return
}
return
}
func (i Client) CRGetUserBasic() (exist bool, err error) {
var u = fmt.Sprintf("%s?Action=GetUserBasic&Version=2021-03-03", i.Host)
var req *http.Request
if req, err = http.NewRequest(http.MethodPost, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("cr get user with bad status code: %d, %s", code, string(data))
return
}
var result CommonResponse
if err = json.Unmarshal(data, &result); err != nil {
return
}
type CRGetUserResp struct {
PasswordSet bool `json:"PasswordSet"`
}
var crGetUserResp CRGetUserResp
if err = json.Unmarshal(result.Result, &crGetUserResp); err != nil {
return
}
if crGetUserResp.PasswordSet {
exist = true
}
return
}
func (i Client) CRCreateNamespaceBasic(namespace string) (err error) {
var u = fmt.Sprintf("%s?Action=CreateNamespaceBasic&Version=2021-03-03", i.Host)
type CRCreateNamespaceBasicReq struct {
Name string `json:"Name"`
}
var crCRCreateNamespaceBasicReq = CRCreateNamespaceBasicReq{Name: namespace}
var reqBody []byte
if reqBody, err = json.Marshal(crCRCreateNamespaceBasicReq); err != nil {
return
}
var req *http.Request
if req, err = http.NewRequest(http.MethodPost, u, bytes.NewBuffer(reqBody)); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("cr create user with bad status code: %d, %s", code, string(data))
return
}
return
}
func (i Client) CRValidateNamespaceBasic(namespace string) (exist bool, err error) {
var u = fmt.Sprintf("%s?Action=ValidateNamespaceBasic&Version=2021-03-03", i.Host)
type CRValidateNamespaceBasicReq struct {
Name string `json:"Name"`
}
var crValidateNamespaceBasicReq = CRValidateNamespaceBasicReq{Name: namespace}
var reqBody []byte
if reqBody, err = json.Marshal(crValidateNamespaceBasicReq); err != nil {
return
}
var req *http.Request
if req, err = http.NewRequest(http.MethodPost, u, bytes.NewBuffer(reqBody)); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("cr get user with bad status code: %d, %s", code, string(data))
return
}
var result CommonResponse
if err = json.Unmarshal(data, &result); err != nil {
return
}
type CRValidateNamespaceBasic struct {
Existed bool `json:"Existed"`
}
var crValidateNamespaceBasic CRValidateNamespaceBasic
if err = json.Unmarshal(result.Result, &crValidateNamespaceBasic); err != nil {
return
}
if crValidateNamespaceBasic.Existed {
exist = true
}
return
}
func (i Client) CRCreateRepositoryBasic(namespace, repository string) (err error) {
var u = fmt.Sprintf("%s?Action=CreateRepositoryBasic&Version=2021-03-03", i.Host)
type CRCreateRepositoryBasicReq struct {
Namespace string `json:"Namespace"`
Name string `json:"Name"`
Type string `json:"Type"`
Description string `json:"Description"`
}
var crCreateRepositoryBasicReq = CRCreateRepositoryBasicReq{
Namespace: namespace,
Name: repository,
Type: "Public",
Description: "公共镜像集",
}
var reqBody []byte
if reqBody, err = json.Marshal(crCreateRepositoryBasicReq); err != nil {
return
}
var req *http.Request
if req, err = http.NewRequest(http.MethodPost, u, bytes.NewBuffer(reqBody)); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("cr create repository with bad status code: %d, %s", code, string(data))
return
}
return
}
func (i Client) CRValidateRepositoryBasic(namespace, repository string) (exist bool, err error) {
var u = fmt.Sprintf("%s?Action=ValidateRepositoryBasic&Version=2021-03-03", i.Host)
type CRValidateRepositoryBasicReq struct {
Namespace string `json:"Namespace"`
Name string `json:"Name"`
}
var crValidateNamespaceBasicReq = CRValidateRepositoryBasicReq{Name: repository, Namespace: namespace}
var reqBody []byte
if reqBody, err = json.Marshal(crValidateNamespaceBasicReq); err != nil {
return
}
var req *http.Request
if req, err = http.NewRequest(http.MethodPost, u, bytes.NewBuffer(reqBody)); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("cr validate repository basic with bad status code: %d, %s", code, string(data))
return
}
var result CommonResponse
if err = json.Unmarshal(data, &result); err != nil {
return
}
type CRValidateRepositoryBasic struct {
Existed bool `json:"Existed"`
}
var crValidateRepositoryBasic CRValidateRepositoryBasic
if err = json.Unmarshal(result.Result, &crValidateRepositoryBasic); err != nil {
return
}
if crValidateRepositoryBasic.Existed {
exist = true
}
return
}
-30
View File
@@ -1,30 +0,0 @@
package vecpsdk
import (
"fmt"
"strings"
)
var ErrResourceNotFound = fmt.Errorf("resource not found")
type Client struct {
Host string
AK string
SK string
Region string
ServiceName string
}
func New(host, ak, sk, region, serviceName string) Client {
var h = host
if !(strings.HasPrefix(host, "http://") || strings.HasPrefix(host, "https://")) {
h = fmt.Sprintf("http://%s", h)
}
return Client{
Host: h,
AK: ak,
SK: sk,
Region: region,
ServiceName: serviceName,
}
}
-125
View File
@@ -1,125 +0,0 @@
package vecpsdk
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
func (i Client) CreatePolicy(account, policyName string) (err error) {
var rawPolicy = `{
"Statement": [
{
"Effect": "Allow",
"Action": [
"*"
],
"Resource": [
"*"
]
}
]
}`
var policy = url.QueryEscape(rawPolicy)
var u = fmt.Sprintf("%s/policy?Action=CreatePolicy&Version=2018-01-01&PolicyName=%s&PolicyDocument=%s&X-Account-Id=%s", i.Host, policyName, policy, account)
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("create user with bad status code: %d, %s", code, string(data))
return
}
return
}
func (i Client) GetPolicy(account, policyName string) (err error) {
var u = fmt.Sprintf("%s/policy?Action=GetPolicy&Version=2018-01-01&PolicyName=%s&PolicyType=%s&X-Account-Id=%s", i.Host, policyName, PolicyTypeCustom, account)
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code == 404 {
err = ErrResourceNotFound
return
}
if code != 200 {
err = fmt.Errorf("create user with bad status code: %d, %s", code, string(data))
return
}
return
}
func (i Client) AttachUserPolicy(account, username, policyName string) (err error) {
var u = fmt.Sprintf("%s/policy?Action=AttachUserPolicy&Version=2018-01-01&UserName=%s&PolicyName=%s&PolicyType=%s&X-Account-Id=%s", i.Host, username, policyName, PolicyTypeCustom, account)
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("create user with bad status code: %d, %s", code, string(data))
return
}
return
}
func (i Client) ListAttachedUserPolicies(account, username string) (policies ListAttachedUserPoliciesResp, err error) {
var u = fmt.Sprintf("%s/policy?Action=ListAttachedUserPolicies&UserName=%s&Version=2018-01-01&X-Account-Id=%s", i.Host, username, account)
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("create user with bad status code: %d, %s", code, string(data))
return
}
var result CommonResponse
if err = json.Unmarshal(data, &result); err != nil {
return
}
if err = json.Unmarshal(result.Result, &policies); err != nil {
return
}
return
}
func (i Client) CheckAttachedUserPoliciesExist(account, username, policyName string) (exist bool, err error) {
var policies ListAttachedUserPoliciesResp
if policies, err = i.ListAttachedUserPolicies(account, username); err != nil {
return
}
for _, policy := range policies.AttachedPolicyMetadata {
if policy.PolicyName == policyName {
exist = true
return
}
}
return
}
-98
View File
@@ -1,98 +0,0 @@
package vecpsdk
import (
"encoding/json"
)
const PolicyTypeCustom = "Custom"
type CommonResponse struct {
ResponseMetadata ResponseMetadata
Result json.RawMessage `json:"Result,omitempty"`
}
type ResponseMetadata struct {
RequestId string
Action string `json:",omitempty"`
Version string `json:",omitempty"`
Service string `json:",omitempty"`
Region string `json:",omitempty"`
Error *ErrorObj `json:",omitempty"`
}
type ErrorObj struct {
CodeN int `json:",omitempty"`
Code string `json:",omitempty"`
Message string `json:",omitempty"`
}
type ListAttachedUserPoliciesResp struct {
AttachedPolicyMetadata []*AttachedPolicy
}
type AttachedPolicy struct {
PolicyTrn string
PolicyName string
PolicyType string
Description string
AttachDate string
}
type User struct {
*BaseResp
Id int `json:",omitempty"`
AccountId int
UserName string
Description string
DisplayName string
Email string
EmailIsVerify bool
Mobile string
MobileIsVerify bool
Trn string
Source string
}
// Account Account
type Account struct {
*BaseResp
Id int
AccountName string
Email string
Tel string
}
type BaseResp struct {
Id int `json:"-"`
CreateDate string
UpdateDate string
Status string
}
type ListUsersResp struct {
UserMetadata []*User
Page
}
type Page struct {
Limit int `xParam:"Query" xValidator:"CheckLimit" xDefault:"10"`
Offset int `xParam:"Query" xValidator:"CheckOffset" xDefault:"0"`
Total int
}
type CreateAccessKeyResp struct {
AccessKeyId string
SecretAccessKey string
UserName string
CreateDate string
UpdateDate string
Status string
}
type ListAccessKeysResp struct {
AccessKeyId string
UserName string
Status string
CreateDate string
UpdateDate string
}
-172
View File
@@ -1,172 +0,0 @@
package vecpsdk
import (
"encoding/json"
"fmt"
"net/http"
"strconv"
)
func (i Client) GetUserCount(account string) (total int, err error) {
var u = fmt.Sprintf("%s/user?Action=ListUsers&Version=2018-01-01&X-Account-Id=%s", i.Host, account)
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("create user with bad status code: %d, %s", code, string(data))
return
}
var result CommonResponse
if err = json.Unmarshal(data, &result); err != nil {
return
}
var listUsersResp ListUsersResp
if err = json.Unmarshal(result.Result, &listUsersResp); err != nil {
return
}
total = listUsersResp.Total
return
}
func (i Client) GetUser(account, username string) (userId int, err error) {
var u = fmt.Sprintf("%s/user?Action=GetUser&Version=2018-01-01&X-Account-Id=%s&UserName=%s", i.Host, account, username)
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("get user info with bad status code: %d, %s", code, string(data))
return
}
var result CommonResponse
if err = json.Unmarshal(data, &result); err != nil {
return
}
type UserInfo struct {
User User `json:"User"`
Account Account `json:"Account"`
}
var userInfo UserInfo
if err = json.Unmarshal(result.Result, &userInfo); err != nil {
return
}
userId = userInfo.User.Id
return
}
func (i Client) ListUser(account string) (users []*User, err error) {
var total int
if total, err = i.GetUserCount(account); err != nil {
return
}
var u = fmt.Sprintf("%s/user?Action=ListUsers&Version=2018-01-01&X-Account-Id=%s&Limit=%s", i.Host, account, strconv.Itoa(total))
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("create user with bad status code: %d, %s", code, string(data))
return
}
var result CommonResponse
if err = json.Unmarshal(data, &result); err != nil {
return
}
var listUsersResp ListUsersResp
if err = json.Unmarshal(result.Result, &listUsersResp); err != nil {
return
}
users = listUsersResp.UserMetadata
return
}
func (i Client) CheckUserExist(account, username string) (exist bool, err error) {
var users []*User
if users, err = i.ListUser(account); err != nil {
return
}
for _, u := range users {
if username == u.UserName {
exist = true
return
}
}
return
}
func (i Client) CreateUser(account, username, tel, email string) (err error) {
const description = "公共镜像仓库运维用户"
var u = fmt.Sprintf("%s/user?Action=CreateUser&UserName=%s&DisplayName=%s&MobilePhone=%s&MobilePhoneIsVerify=1&Email=%s&EmailIsVerify=1&Description=%s&Version=2018-01-01&X-Account-Id=%s", i.Host, username, username, tel, email, description, account)
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("create user with bad status code: %d, %s", code, string(data))
return
}
return
}
func (i Client) CreateLoginProfile(account, username, password string) (err error) {
var u = fmt.Sprintf("%s/user?Action=CreateLoginProfile&Version=2018-01-01&UserName=%s&Password=%s&LoginAllowed=true&X-Account-Id=%s", i.Host, username, password, account)
var req *http.Request
if req, err = http.NewRequest(http.MethodGet, u, nil); err != nil {
return
}
var data []byte
var code int
if data, code, err = i.makeRequest(req); err != nil {
return
}
if code != 200 {
err = fmt.Errorf("create user with bad status code: %d, %s", code, string(data))
return
}
return
}
-37
View File
@@ -1,37 +0,0 @@
package vecpsdk
import (
"crypto/tls"
"io/ioutil"
"net/http"
"time"
)
func (i Client) makeRequest(req *http.Request) (body []byte, code int, err error) {
req.Header.Set("Content-Type", "application/json")
// var cred = base.Credentials{
// AccessKeyID: i.AK,
// SecretAccessKey: i.SK,
// Service: i.ServiceName,
// Region: i.Region,
// }
// req = cred.Sign(req)
transport := &http.Transport{
MaxIdleConns: 1000,
MaxIdleConnsPerHost: 100,
IdleConnTimeout: 10 * time.Second,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
var c = http.Client{Transport: transport}
var resp *http.Response
if resp, err = c.Do(req); err != nil {
return
}
code = resp.StatusCode
if body, err = ioutil.ReadAll(resp.Body); err != nil {
return
}
return
}