{"id":28600945,"url":"https://github.com/oldthreefeng/syncd-cli","last_synced_at":"2025-09-06T01:33:39.926Z","repository":{"id":64306122,"uuid":"216306915","full_name":"oldthreefeng/syncd-cli","owner":"oldthreefeng","description":"syncd-cli 是自动化部署工具 syncd 的一个命令行客户端，用于批量添加server,user，实现一键自动添加，提高开发效率。diprecated","archived":false,"fork":false,"pushed_at":"2023-10-11T23:27:51.000Z","size":36,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-11T14:59:53.632Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oldthreefeng.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-20T04:23:34.000Z","updated_at":"2023-04-26T15:55:24.000Z","dependencies_parsed_at":"2024-06-20T12:59:12.088Z","dependency_job_id":"3de6cd1e-abdb-4aa2-ace4-4eb4d5c5235c","html_url":"https://github.com/oldthreefeng/syncd-cli","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/oldthreefeng/syncd-cli","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldthreefeng%2Fsyncd-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldthreefeng%2Fsyncd-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldthreefeng%2Fsyncd-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldthreefeng%2Fsyncd-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oldthreefeng","download_url":"https://codeload.github.com/oldthreefeng/syncd-cli/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldthreefeng%2Fsyncd-cli/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273846970,"owners_count":25178628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-11T14:39:29.345Z","updated_at":"2025-09-06T01:33:39.898Z","avatar_url":"https://github.com/oldthreefeng.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 介绍\n\n\u003e syncd-cli 是自动化部署工具 [syncd](https://github.com/dreamans/syncd) 的一个命令行客户端，用于批量添加server，实现一键自动添加，提高开发效率。\n\u003e\n\u003e Syncd是一款开源的代码部署工具，它具有简单、高效、易用等特点，可以提高团队的工作效率。\n\n## 安装\n\nrequired要求\n\n- [X] go1.8+\n- [X] syncd2.0+\n\n`go get` 方式\n\n```shell\n$ go get gogs.wangke.co/go/syncd-cli\n$ syncd-cli -h\n```\n\n`git clone` 方式\n\n```shell\n$ git clone https://gogs.wangke.co/go/syncd-cli.git\n$ cd syncd-cli \u0026\u0026 go build -o syncd-cli syncd-cli.go\n$ ./syncd-cli -h\n```\n\n## Usage\n\n```shell\n# ./syncd-cli -h                                                                                                  [12:18:53]\nsyncd-cli version:1.0.0\nUsage syncd-cli \u003ccommand\u003e [-aupginsh]\n\ncommand [--add] [--list]  [user|server]\n\nadd server example:\n        1) syncd-cli -d server -g 2 -i 192.168.1.1,test.example.com -n test01,test02 -s 9527,22\n        2) syncd-cli --add server  --roleGroupId 2 --ipEmail 192.168.1.1 --names test01 --sshPort 9527\nadd user example:\n        1) syncd-cli --add user  --ipEmail text@wangke.co --names test01\n        2) syncd-cli  -d user  -i text@wangke.co -n test01\nlist server and user example:\n        1) syncd-cli -l user\n        2) syncd-cli -l server \n        3) syncd-cli --list \n        4) syncd-cli --list server \n\nOptions:\n  -d, --add string        add user or server\n  -h, --help              this help\n  -a, --hostApi string    sycnd server addr api (default \"http//127.0.0.1:8878/\")\n  -i, --ipEmail strings   set ip/hostname to the cluster with names // or email for add user, use ',' to split\n  -l, --list string       list server or user\n  -n, --names strings     set names to the cluster with ips, use ',' to split\n  -p, --password string   password for syncd tools (default \"111111\")\n  -g, --roleGroupId int   group_id for cluster // or role_id for user, must be needed (default 1)\n  -s, --sshPort ints      set sshPort to the cluster server, use ',' to split\n  -u, --user string       user for syncd tools (default \"syncd\")\n\n```\n\n### @v1.1.0\n\n从命令行读取批量文件的信息,感觉太冗余了, 不方便创建,还是以文件的方式创建批量容易一点,\n所用想了一个从文件里面读取信息,然后根据信息创建相应资源的方法.\n\n```\n@v1.1.0  \n$ go run syncd-cli.go -h\nsyncd-cli version:1.1.0\nUsage syncd-cli \u003ccommand\u003e [-afhpu]\n\ncommand \u003capply\u003e \u003cget\u003e  [user|server] \u003c?-f files\u003e\n\nadd server example:\n        1) syncd-cli apply user -f files\n        2) syncd-cli apply server -f files\nlist server and user example:\n        1) syncd-cli get user\n        2) syncd-cli get server\n\nOptions:\n  -f, --file string       add server/user from files\n  -h, --help              this help\n  -a, --hostApi string    sycnd server addr api (default \"http://127.0.0.1:8878\")\n  -p, --password string   password for syncd tools (default \"111111\")\n  -u, --user string       user for syncd tools (default \"syncd\")\n  \n\n```\n\n\n**file文件的格式**\n\n`testserver`,`testuser`等文件名称无要求, 但是对文件的格式要求.以一个空格进行分割.\n\n```shell\n# 第一列是groupid,对应的集群id;\n# 第二列是name, 对应的是server的名字\n# 第三列是ip/hostname, 对应server的ip或者域名\n# 第四列是sshport, 对应的是server的ssh端口\n$ cat testserver\n1 test01 test.wangke.co 22\n1 test02 test01.wangke.co 9527\n1 test03 test02.wangke.co 6822\n```\n`testuser`文件内容以空格区分,共四列.(后续可以添加至6列,源码的user还有电话号码,真实姓名等,非必须 批量创建的默认密码为`111111`)\n\n```shell\n# 第一列是role_id, 对应的是角色, 比如1是管理员\n# 第二列是name, 对应的是用户名\n# 第三列是email, 对应的是用户的邮箱\n# 第四列是status, 对应的是用户能否登陆.\n$ cat testuser\n1 test01 test01@wangke.co 1\n1 test02 test02@wangke.co 1\n\n```\n\n因为`testuser`和`testserver`的的文件格式和数据类型是一样的, 所用到的方法是一样的, 唯一的区分就是利用`apply user`还是`apply server`\n\n```go\ntype server struct {\n    id int\n    name string\n    ip string\n    port int\n}\n\ntype user struct {\n\tid int\n\tname string\n\temail string\n\tstatus int\n}\n\n```\n### 重要提醒\n```\n\n方法是一样的. 所以标志位很重要, 不然创建错了就是连环错误了.\n\n$ syncd-cli apply user -f testuser\n$ syncd-cli apply server -f testserver\n```\n\n\n\n## example\n### @v1.0.0\n\n```shell\nroot@master-louis: ~/go/src/github.com/oldthreefeng/syncd-cli master ⚡\n# ./syncd-cli -i 192.168.1.2,text.example.com -n test1,texte -s 9527,22              [12:18:58]\nINFO[0000] your token is under .syncd-token             \nINFO[0000] group_id=1\u0026name=test1\u0026ip=192.168.1.2\u0026ssh_port=9527  \nINFO[0000] {\"code\":0,\"message\":\"success\"}               \nINFO[0000] group_id=1\u0026name=texte\u0026ip=text.example.com\u0026ssh_port=22  \nINFO[0000] {\"code\":0,\"message\":\"success\"}\n\n# 将test01邮箱为text@wangke.co加入管理员,默认密码为111111\n$./syncd-cli -d user -i text@wangke.co -n test01   \ntime=\"2019-10-20T17:59:08+08:00\" level=info msg=\"your token is under .syncd-token\\n\"\ntime=\"2019-10-20T17:59:08+08:00\" level=info msg=\"role_id=1\u0026username=test01\u0026password=1111111\u0026email=text@wangke.co\u0026status=1\"\ntime=\"2019-10-20T17:59:08+08:00\" level=info msg=\"{\\\"code\\\":0,\\\"message\\\":\\\"success\\\"}\"\n```\n\n### @v1.1.0\n\n```\n@v1.1.0\n# 采用从文件读取方式创建server\n$ go run syncd-cli.go apply server -f test.log\ntime=\"2019-10-21T00:25:03+08:00\" level=info msg=\"your token is under .syncd-token\\n\"\ntime=\"2019-10-21T00:25:03+08:00\" level=info msg=\"group_id=1\u0026name=test01\u0026ip=test.wangke.co\u0026ssh_port=22\\n\"\ntime=\"2019-10-21T00:25:03+08:00\" level=info msg=\"{\\\"code\\\":0,\\\"message\\\":\\\"success\\\"}\"\ntime=\"2019-10-21T00:25:03+08:00\" level=info msg=\"group_id=1\u0026name=test02\u0026ip=test01.wangke.co\u0026ssh_port=9527\\n\"\ntime=\"2019-10-21T00:25:03+08:00\" level=info msg=\"{\\\"code\\\":0,\\\"message\\\":\\\"success\\\"}\"\ntime=\"2019-10-21T00:25:04+08:00\" level=info msg=\"group_id=1\u0026name=test03\u0026ip=test02.wangke.co\u0026ssh_port=6822\\n\"\ntime=\"2019-10-21T00:25:04+08:00\" level=info msg=\"{\\\"code\\\":0,\\\"message\\\":\\\"success\\\"}\"\n\n$ go run syncd-cli.go apply user -f testuser.log\ntime=\"2019-10-21T00:27:03+08:00\" level=info msg=\"your token is under .syncd-token\\n\"\ntime=\"2019-10-21T00:27:03+08:00\" level=info msg=\"role_id=1\u0026username=test01\u0026password=111111\u0026email=test01@wangke.co\u0026status=1\"\ntime=\"2019-10-21T00:27:03+08:00\" level=info msg=\"{\\\"code\\\":0,\\\"message\\\":\\\"success\\\"}\"\ntime=\"2019-10-21T00:27:03+08:00\" level=info msg=\"role_id=1\u0026username=test02\u0026password=111111\u0026email=test02@wangke.co\u0026status=1\"\ntime=\"2019-10-21T00:27:03+08:00\" level=info msg=\"{\\\"code\\\":0,\\\"message\\\":\\\"success\\\"}\"\n\n$ go run syncd-cli.go get user\n[map[ctime:0 email:louis@wangke.co id:2 last_login_ip: last_login_time:0 mobile: password: role_id:1 role_name:管理员 salt: status:1 truename: username:louis] map[ctime:0 email: id:1 last_login_ip: last_login_time:0 mobile: password: role_id:1 role_name:管理员 salt: status:1 truename: username:syncd]]\n2\n\n$ go run syncd-cli.go get server\n[map[ctime:1.571545269e+09 group_id:1 group_name:aliyun id:5 ip:text.example.com name:texte ssh_port:22] map[ctime:1.571545269e+09 group_id:1 group_name:aliyun id:4 ip:192.168.1.2 name:test1 ssh_port:9527] map[ctime:1.571541399e+09 group_id:1 group_name:aliyun id:3 ip:192.168.1.1 name:test01 ssh_port:22] map[ctime:1.57140845e+09 group_id:3 group_name:vrtul id:2 ip:vps.wangke.co name:vrtest ssh_port:9527] map[ctime:1.571408398e+09 group_id:1 group_name:aliyun id:1 ip:gogs.wangke.co name:alitest ssh_port:9527]]\n5\n```\n添加如下:\n![](https://pic.fenghong.tech/syncd-cli.png)\n![](https://pic.fenghong.tech/syncd-cli-add-user.png)\n\n## 算法思路 ##\n\n本来想开发和`kubectl`,`go`,`kubeadm`等类似的管理cli. 奈何时间水平有限. \n\n脑子里想的是这样的@v1.1.0实现的比较简陋\n\n```cgo\n$ syncd get user \n$ syncd get server \n$ syncd apply -f adduser.yaml\n```\n实际上...\n\n```cgo\n$ syncd-cli --list user\n$ syncd-cli --list server\n\n$ syncd-cli --add user -i test@wangke.co -n test01 \n```\n\n\u003e 整体上, 利用`http`的`GET`还有`POST`完成显示和添加动作的. [gorequest](https://github.com/parnurzeal/gorequest)的`GET/POST`的确好用,可以试试. \n\u003e\n\u003e 记录日志当然是用的[logrus](https://github.com/sirupsen/logrus), 当时用的`go mod`学习教程就是用的这个模板, 日志的格式也可以, 方便阅读.\n\u003e\n\u003e 命令行的开发主要就是用的[pflag](https://github.com/spf13/pflag), 看了`kubernetes`和`docker`源码相关, `kubectl`等命令行管理工具也是基于这个开发的.\n\n首先, 登录验证, 获取token, 将token存入当前目录下的`.syncd-token`, 其次, 获取user/server列表或者添加user/server, 逻辑都是一样的,发送`POST`请求, 同时携带cookie, 将cookie的`name`和`value`封装成`http.cookie`, 每次需要用到,直接调用即可. \n\n## TODO\n- [x] add server from cli\n- [x] add user from cli\n- [x] list server\n- [x] list user\n- [ ] list project\n- [x] add server info from file\n- [x] add user info from file\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foldthreefeng%2Fsyncd-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foldthreefeng%2Fsyncd-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foldthreefeng%2Fsyncd-cli/lists"}