Skip to content

Commit

Permalink
refactor: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
colin404 committed Dec 21, 2021
1 parent f73296f commit c3a0fbf
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 25 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG/CHANGELOG-1.6.0.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

<a name="v1.6.0"></a>
## [v1.6.0](https://github.com/marmotedu/iam/compare/v1.4.0...v1.6.0) (2021-12-20)
## [v1.6.0](https://github.com/marmotedu/iam/compare/v1.4.0...v1.6.0) (2021-12-21)

### Bug Fixes

* **apiserver:** do not authenticate when creating a user

### Code Refactoring

* optimize code
* support coscmd and coscli tool both
* optimize func name from `runPumps` to `pump`

8 changes: 4 additions & 4 deletions configs/iam.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ DROP TABLE IF EXISTS `policy`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `policy` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`instanceID` varchar(20) DEFAULT NULL,
`instanceID` varchar(32) DEFAULT NULL,
`name` varchar(45) NOT NULL,
`username` varchar(255) NOT NULL,
`policyShadow` longtext DEFAULT NULL,
Expand Down Expand Up @@ -80,7 +80,7 @@ DROP TABLE IF EXISTS `policy_audit`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `policy_audit` (
`id` bigint(20) unsigned NOT NULL,
`instanceID` varchar(20) DEFAULT NULL,
`instanceID` varchar(32) DEFAULT NULL,
`name` varchar(45) NOT NULL,
`username` varchar(255) NOT NULL,
`policyShadow` longtext DEFAULT NULL,
Expand Down Expand Up @@ -111,7 +111,7 @@ DROP TABLE IF EXISTS `secret`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `secret` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`instanceID` varchar(20) DEFAULT NULL,
`instanceID` varchar(32) DEFAULT NULL,
`name` varchar(45) NOT NULL,
`username` varchar(255) NOT NULL,
`secretID` varchar(36) NOT NULL,
Expand Down Expand Up @@ -146,7 +146,7 @@ DROP TABLE IF EXISTS `user`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`instanceID` varchar(20) DEFAULT NULL,
`instanceID` varchar(32) DEFAULT NULL,
`name` varchar(45) NOT NULL,
`status` int(1) DEFAULT 1 COMMENT '1:可用,0:不可用',
`nickname` varchar(30) NOT NULL,
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ require (
github.com/gosuri/uitable v0.0.4
github.com/influxdata/influxdb v1.9.4
github.com/jinzhu/gorm v1.9.16
github.com/jinzhu/now v1.1.2
github.com/jinzhu/now v1.1.3
github.com/kelseyhightower/envconfig v1.4.0
github.com/likexian/host-stat-go v0.0.0-20190516151207-c9cf36dd6ce9
github.com/marmotedu/api v1.0.5
github.com/marmotedu/component-base v1.0.1
github.com/marmotedu/api v1.6.1
github.com/marmotedu/component-base v1.6.1
github.com/marmotedu/errors v1.0.2
github.com/marmotedu/marmotedu-sdk-go v1.0.3
github.com/marmotedu/marmotedu-sdk-go v1.6.1
github.com/mattn/go-isatty v0.0.14
github.com/mitchellh/go-wordwrap v1.0.1
github.com/mitchellh/mapstructure v1.4.2
Expand Down Expand Up @@ -65,7 +65,7 @@ require (
gopkg.in/vmihailenco/msgpack.v2 v2.9.2
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
gorm.io/driver/mysql v1.1.2
gorm.io/gorm v1.21.15
gorm.io/gorm v1.22.4
k8s.io/klog v1.0.0
)

Expand Down
23 changes: 11 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,9 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI=
github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.3 h1:PlHq1bSCSZL9K0wUhbm2pGLoTWs2GwVhsP6emvGV/ZI=
github.com/jinzhu/now v1.1.3/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
Expand Down Expand Up @@ -740,19 +741,17 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/marmotedu/api v1.0.1/go.mod h1:9W9G25bxJGo34V1HQ2VcoPZTyy8WRMCve28zXWcIgl8=
github.com/marmotedu/api v1.0.5 h1:JZRKoYHy1gg3DZ2fcfwYPBAEDp0uRoVYovVouuec3Jc=
github.com/marmotedu/api v1.0.5/go.mod h1:wRkEh5yx/zB2/wMtIgdUmWbvftyEGiHIubXilqInjGo=
github.com/marmotedu/component-base v1.0.0/go.mod h1:uqOvcyTL4uNB3qxiVJXbYDbnVD4DB89/vWwQZfJgxkM=
github.com/marmotedu/component-base v1.0.1 h1:pkGSOz8thxEGduRjHv/EO50skKviyCPDbOfGH2e/d7M=
github.com/marmotedu/component-base v1.0.1/go.mod h1:YqFsxJS6hQvN7YKRRz4cDnt5h3DbikuAfs7dYMRuWg8=
github.com/marmotedu/errors v0.0.1/go.mod h1:xNqbJJRD50/RGSjbfqF01CTLegWK+gtRgeJ6ExVzQQ8=
github.com/marmotedu/api v1.6.1 h1:nFs9UfZ8VVhUluyXnRnQ3ALwr3WHDnQMrH0n9iX3/UA=
github.com/marmotedu/api v1.6.1/go.mod h1:zst/e6pLQiVCtnJl9B2HeYlO6Jr5iI3EDFR2jum7OZE=
github.com/marmotedu/component-base v1.6.0/go.mod h1:YqFsxJS6hQvN7YKRRz4cDnt5h3DbikuAfs7dYMRuWg8=
github.com/marmotedu/component-base v1.6.1 h1:eo7RaayM9VCGXUlktY0TIdv8PqSgzdPEN3/D/DOQYAw=
github.com/marmotedu/component-base v1.6.1/go.mod h1:rvpc1f0WN4iEUMN4pzU/nBOEEym0Yj2hQFA+mQxTRt4=
github.com/marmotedu/errors v1.0.2 h1:qx9GtOljmAL+wLuemahe3WSWdXyEpJvLBlpXK8y2rdI=
github.com/marmotedu/errors v1.0.2/go.mod h1:xNqbJJRD50/RGSjbfqF01CTLegWK+gtRgeJ6ExVzQQ8=
github.com/marmotedu/log v0.0.1 h1:3jSFCRM3LW46vAd8t/fu5+S4wPXwvesdhj+iXU3OKVQ=
github.com/marmotedu/log v0.0.1/go.mod h1:EsU1dxbgXmzan4NXzYhnYZ7H/soLrBZrTXlfN6svSNM=
github.com/marmotedu/marmotedu-sdk-go v1.0.3 h1:fSmPj0nFe11gI5GhSMQ/J40d5NbVk4LiboclfRePauY=
github.com/marmotedu/marmotedu-sdk-go v1.0.3/go.mod h1:xkZ96kUfCbIgnMB7G0kjAudheRpn/3ZoSnkLXt3jKuI=
github.com/marmotedu/marmotedu-sdk-go v1.6.1 h1:1HTAB6V9nwpPMXzhNYy5cMgbbqeIywkkVFE+u8DjvW0=
github.com/marmotedu/marmotedu-sdk-go v1.6.1/go.mod h1:5Go6CssEaEUj3fWC8mMUHNEshVbnTdYTdo8TWoPkLX0=
github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down Expand Up @@ -1693,8 +1692,8 @@ gorm.io/driver/mysql v1.1.2 h1:OofcyE2lga734MxwcCW9uB4mWNXMr50uaGRVwQL2B0M=
gorm.io/driver/mysql v1.1.2/go.mod h1:4P/X9vSc3WTrhTLZ259cpFd6xKNYiSSdSZngkSBGIMM=
gorm.io/gorm v1.21.4/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.21.12/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.21.15 h1:gAyaDoPw0lCyrSFWhBlahbUA1U4P5RViC1uIqoB+1Rk=
gorm.io/gorm v1.21.15/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0=
gorm.io/gorm v1.22.4 h1:8aPcyEJhY0MAt8aY6Dc524Pn+pO29K+ydu+e/cXSpQM=
gorm.io/gorm v1.22.4/go.mod h1:1aeVC+pe9ZmvKZban/gW4QPra7PRoTEssyc922qCAkk=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
Expand Down
2 changes: 1 addition & 1 deletion internal/apiserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (s *apiServer) PrepareRun() preparedAPIServer {
s.gs.AddShutdownCallback(shutdown.ShutdownFunc(func(string) error {
mysqlStore, _ := mysql.GetMySQLFactoryOr(nil)
if mysqlStore != nil {
return mysqlStore.Close()
_ = mysqlStore.Close()
}

s.gRPCAPIServer.Close()
Expand Down
1 change: 0 additions & 1 deletion internal/apiserver/service/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func (u *userService) List(ctx context.Context, opts metav1.ListOptions) (*v1.Us
return nil, err
}

// infos := make([]*v1.User, 0)
infos := make([]*v1.User, 0, len(users.Items))
for _, user := range users.Items {
info, _ := m.Load(user.ID)
Expand Down
2 changes: 1 addition & 1 deletion internal/apiserver/store/mysql/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type users struct {
}

func newUsers(ds *datastore) *users {
return &users{db: ds.db}
return &users{ds.db}
}

// Create creates a new user account.
Expand Down

0 comments on commit c3a0fbf

Please sign in to comment.