tianxiaoliang commented on a change in pull request #736:
URL: 
https://github.com/apache/servicecomb-service-center/pull/736#discussion_r517092871



##########
File path: server/resource/register.go
##########
@@ -31,6 +31,7 @@ func init() {
 func initRouter() {
        if rbac.Enabled() {
                roa.RegisterServant(&v4.AuthResource{})
+               roa.RegisterServant(&v4.RBACRole{})

Review comment:
       风格保持一致,role resource

##########
File path: pkg/rbacframe/resource.go
##########
@@ -0,0 +1,108 @@
+/*
+ * 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 rbacframe
+
+const (
+       ResourceAccount    = "account"
+       ResourceRole       = "role"
+       ResourceService    = "service"
+       ResourceInstance   = "instance"
+       ResourceDep        = "dependencies"
+       ResourceRule       = "rule"
+       ResourceTag        = "tag"
+       ResourceGovern     = "governance"
+       ResourceSchema     = "schema"
+       ResourceAdminister = "administer"
+)
+
+// HTTP METHODS
+var (
+       GET    = "GET"
+       POST   = "POST"
+       UPDATE = "PUT"
+       DELETE = "DELETE"
+)
+
+var (
+       // WhiteList API's
+       Health       = "/v4/:project/registry/health"

Review comment:
       
rbacframe包是给sc,kie共用的通用开发库,所以这些特性的API,应该挪到server/service/rbac/resource.go 

##########
File path: server/service/rbac/decision.go
##########
@@ -21,24 +21,35 @@ import (
        "context"
        "github.com/apache/servicecomb-service-center/pkg/log"
        "github.com/apache/servicecomb-service-center/server/service/rbac/dao"
+       "strings"
 )
 
-func Allow(ctx context.Context, role, project, resource, verbs string) (bool, 
error) {
-       r := dao.GetRole(ctx, role)
+func Allow(ctx context.Context, role, project, api, verbs string) (bool, 
error) {

Review comment:
       api参数,更准确的命名是apiPattern

##########
File path: server/service/rbac/permission.go
##########
@@ -0,0 +1,112 @@
+/*
+ * 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 rbac
+
+import "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+
+// verbs
+var (
+       GET    = "GET"

Review comment:
       verbs不应该是http的,而是get, create, delete, update

##########
File path: pkg/rbacframe/role.go
##########
@@ -0,0 +1,30 @@
+/*
+ * 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 rbacframe
+
+type RoleResponse struct {
+       Roles []*Role `json:"data,omitempty"`
+}
+
+type Role struct {
+       ID          string            `json:"id,omitempty"`
+       Name        string            `json:"name,omitempty"`
+       Project     []string          `json:"project,omitempty"`

Review comment:
       role不该属于一个project

##########
File path: server/resource/v4/rbac_role.go
##########
@@ -0,0 +1,141 @@
+/*
+ * 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 v4
+
+import (
+       "context"
+       "encoding/json"
+       errorsEx "github.com/apache/servicecomb-service-center/pkg/errors"
+       "github.com/apache/servicecomb-service-center/pkg/log"
+       "github.com/apache/servicecomb-service-center/pkg/rbacframe"
+       "github.com/apache/servicecomb-service-center/pkg/rest"
+       "github.com/apache/servicecomb-service-center/server/rest/controller"
+       "github.com/apache/servicecomb-service-center/server/scerror"
+       "github.com/apache/servicecomb-service-center/server/service/rbac/dao"
+       "io/ioutil"
+       "net/http"
+)
+
+type RBACRole struct {
+}
+
+//URLPatterns define htp pattern
+func (r *RBACRole) URLPatterns() []rest.Route {
+       return []rest.Route{
+               {Method: http.MethodGet, Path: "/v4/permission/account/role", 
Func: r.GetRolePermission},

Review comment:
       简化为 /v4/role

##########
File path: server/service/rbac/decision.go
##########
@@ -21,24 +21,35 @@ import (
        "context"
        "github.com/apache/servicecomb-service-center/pkg/log"
        "github.com/apache/servicecomb-service-center/server/service/rbac/dao"
+       "strings"
 )
 
-func Allow(ctx context.Context, role, project, resource, verbs string) (bool, 
error) {
-       r := dao.GetRole(ctx, role)
+func Allow(ctx context.Context, role, project, api, verbs string) (bool, 
error) {
+       r, err := dao.GetRole(ctx, role)

Review comment:
       如果每次校验都要查数据库,太慢了,做缓存

##########
File path: pkg/rbacframe/resource.go
##########
@@ -0,0 +1,108 @@
+/*
+ * 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 rbacframe
+
+const (
+       ResourceAccount    = "account"
+       ResourceRole       = "role"
+       ResourceService    = "service"
+       ResourceInstance   = "instance"
+       ResourceDep        = "dependencies"
+       ResourceRule       = "rule"
+       ResourceTag        = "tag"
+       ResourceGovern     = "governance"
+       ResourceSchema     = "schema"
+       ResourceAdminister = "administer"
+)
+
+// HTTP METHODS
+var (
+       GET    = "GET"

Review comment:
       用户定义时看到的方法应该是create,get,delete,update,而不是原生的http method,所以也要做映射




----------------------------------------------------------------
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.

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


Reply via email to