Copilot commented on code in PR #1582:
URL: https://github.com/apache/dubbo-admin/pull/1582#discussion_r4142151568


##########
pkg/store/dbcommon/gorm_store.go:
##########
@@ -482,24 +649,35 @@ func (gs *GormStore) GetByKeys(keys []string) 
([]model.Resource, error) {
                return []model.Resource{}, nil
        }
 
-       var models []ResourceModel
        db := gs.pool.GetDB()
-       err := 
db.Scopes(TableScope(gs.kind.ToString())).Model(&ResourceModel{}).
-               Where("resource_key IN ?", keys).
-               Find(&models).Error
-       if err != nil {
+       resources := make([]model.Resource, 0, len(keys))
+       if store.IsVersionedResourceKind(gs.kind) {
+               var models []VersionedResourceModel
+               if err := 
db.Scopes(TableScope(gs.kind.ToString())).Model(&VersionedResourceModel{}).
+                       Where("resource_key IN ?", keys).Find(&models).Error; 
err != nil {
+                       return nil, err
+               }
+               for _, m := range models {
+                       resource, err := 
m.ResourceModel.ToResourceWithVersion(m.Version)
+                       if err != nil {
+                               return nil, err
+                       }
+                       resources = append(resources, resource)
+               }
+               return resources, nil

Review Comment:
   This versioned query appends rows in database-return order, but 
`PageListByIndexes` passes a sorted page-key slice here and returns these 
resources without sorting again. Because SQL `IN` queries have no ordering 
guarantee, MCP pagination can return nondeterministic key order; preserve the 
input-key order before returning.



##########
pkg/mcp/repository/credential.go:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package repository
+
+import (
+       "crypto/rand"
+       "crypto/sha256"
+       "crypto/subtle"
+       "encoding/hex"
+       "fmt"
+       "strings"
+       "time"
+
+       "github.com/google/uuid"
+
+       meshproto "github.com/apache/dubbo-admin/api/mesh/v1alpha1"
+       "github.com/apache/dubbo-admin/pkg/core/manager"
+       meshresource 
"github.com/apache/dubbo-admin/pkg/core/resource/apis/mesh/v1alpha1"
+       coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
+       "github.com/apache/dubbo-admin/pkg/core/store/index"
+)
+
+type Credentials struct {
+       resources   manager.ResourceManager
+       conditional manager.ConditionalResourceManager
+}
+
+func NewCredentials(resources manager.ResourceManager) (*Credentials, error) {
+       conditional, ok := resources.(manager.ConditionalResourceManager)
+       if !ok {
+               return nil, fmt.Errorf("resource manager does not support 
conditional mutations")
+       }
+       return &Credentials{resources: resources, conditional: conditional}, nil
+}
+
+func (r *Credentials) Create(mesh, serverID, displayName string, expiresAt 
time.Time) (*meshresource.MCPCredentialResource, string, error) {
+       if mesh == "" || serverID == "" || strings.TrimSpace(displayName) == "" 
|| !expiresAt.After(time.Now()) {
+               return nil, "", fmt.Errorf("mesh, server, display name and a 
future expiration are required")

Review Comment:
   The linked proposal makes expiration optional and defaults credentials to 
never expiring, but this validation rejects `time.Time{}` and therefore 
requires every credential to expire. Allow a zero value, serialize it as an 
unset `expires_at`, and only reject nonzero timestamps that are not in the 
future.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to