This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-kie.git


The following commit(s) were added to refs/heads/master by this push:
     new 03833db  [feat]return the same ID when input the same kvDoc request 
(#260)
03833db is described below

commit 03833dbb5e93a9ed351191fcd5483201f99fbf93
Author: little-cui <[email protected]>
AuthorDate: Mon Sep 19 20:01:03 2022 +0800

    [feat]return the same ID when input the same kvDoc request (#260)
---
 pkg/model/db_schema.go      |  4 ++--
 server/service/kv/kv_svc.go | 25 +++++++++++++------------
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/pkg/model/db_schema.go b/pkg/model/db_schema.go
index 7e4be22..748f2c3 100644
--- a/pkg/model/db_schema.go
+++ b/pkg/model/db_schema.go
@@ -76,7 +76,7 @@ type PollingDetail struct {
 
 // UpdateKVRequest is db struct, it contains kv update request params
 type UpdateKVRequest struct {
-       ID      string `json:"id,omitempty" bson:"id,omitempty" 
yaml:"id,omitempty" swag:"string" validate:"uuid"`
+       ID      string `json:"id,omitempty" bson:"id,omitempty" 
yaml:"id,omitempty" swag:"string" validate:"min=1,max=64"`
        Value   string `json:"value,omitempty" yaml:"value,omitempty" 
validate:"max=131072,value"`
        Project string `json:"project,omitempty" yaml:"project,omitempty" 
validate:"min=1,max=256,commonName"`
        Domain  string `json:"domain,omitempty" yaml:"domain,omitempty" 
validate:"min=1,max=256,commonName"` //redundant
@@ -87,7 +87,7 @@ type UpdateKVRequest struct {
 type GetKVRequest struct {
        Project string `json:"project,omitempty" yaml:"project,omitempty" 
validate:"min=1,max=256,commonName"`
        Domain  string `json:"domain,omitempty" yaml:"domain,omitempty" 
validate:"min=1,max=256,commonName"` //redundant
-       ID      string `json:"id,omitempty" bson:"id,omitempty" 
yaml:"id,omitempty" swag:"string" validate:"uuid"`
+       ID      string `json:"id,omitempty" bson:"id,omitempty" 
yaml:"id,omitempty" swag:"string" validate:"min=1,max=64"`
 }
 
 // ListKVRequest contains kv list request params
diff --git a/server/service/kv/kv_svc.go b/server/service/kv/kv_svc.go
index 9d15534..1b539c2 100644
--- a/server/service/kv/kv_svc.go
+++ b/server/service/kv/kv_svc.go
@@ -19,16 +19,11 @@ package kv
 
 import (
        "context"
+       "crypto/sha256"
        "fmt"
+       "strings"
        "time"
 
-       "github.com/go-chassis/cari/config"
-       "github.com/go-chassis/cari/pkg/errsvc"
-       "github.com/go-chassis/foundation/validator"
-       "github.com/go-chassis/go-chassis/v2/pkg/backends/quota"
-       "github.com/go-chassis/openlog"
-       "github.com/gofrs/uuid"
-
        "github.com/apache/servicecomb-kie/pkg/common"
        "github.com/apache/servicecomb-kie/pkg/concurrency"
        "github.com/apache/servicecomb-kie/pkg/model"
@@ -36,6 +31,11 @@ import (
        "github.com/apache/servicecomb-kie/server/datasource"
        "github.com/apache/servicecomb-kie/server/pubsub"
        "github.com/apache/servicecomb-kie/server/service/sync"
+       "github.com/go-chassis/cari/config"
+       "github.com/go-chassis/cari/pkg/errsvc"
+       "github.com/go-chassis/foundation/validator"
+       "github.com/go-chassis/go-chassis/v2/pkg/backends/quota"
+       "github.com/go-chassis/openlog"
 )
 
 var listSema = concurrency.NewSemaphore(concurrency.DefaultConcurrency)
@@ -131,11 +131,12 @@ func Create(ctx context.Context, kv *model.KVDoc) 
(*model.KVDoc, *errsvc.Error)
 }
 
 func completeKV(kv *model.KVDoc, revision int64) error {
-       id, err := uuid.NewV4()
-       if err != nil {
-               return err
-       }
-       kv.ID = id.String()
+       kv.ID = fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join([]string{
+               kv.Domain,
+               kv.Project,
+               kv.Key,
+               kv.LabelFormat,
+       }, "/"))))
        kv.UpdateRevision = revision
        kv.CreateRevision = revision
        now := time.Now().Unix()

Reply via email to