Skip to content

Commit 6310ffa

Browse files
committed
refactor(api): standardize extend key prefix and improve permission structure
- Replace hardcoded CoSec prefixes with COSEC_EXTEND_KEY_PREFIX constant - Add new ExtendKey.kt file defining COSEC_EXTEND_KEY_PREFIX constant - Update AppIdCapable, DeviceIdCapable, RequestIdCapable, and SpaceIdCapable interfaces - Modify permissionIndexer to use PermissionId as key instead of String - Add Permission and PermissionId imports to AppPermissionData - Add spaced property to PermissionGroup interface and PermissionGroupData - Update request ID, device ID, app ID, and space ID key constants to use prefix template Signed-off-by: Ahoo Wang <ahoowang@qq.com>
1 parent 9af16d0 commit 6310ffa

File tree

8 files changed

+30
-9
lines changed

8 files changed

+30
-9
lines changed

cosec-api/src/main/kotlin/me/ahoo/cosec/api/context/request/AppIdCapable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typealias AppId = String
1717

1818
interface AppIdCapable {
1919
companion object {
20-
const val APP_ID_KEY = "CoSec-App-Id"
20+
const val APP_ID_KEY = "${COSEC_EXTEND_KEY_PREFIX}App-Id"
2121
}
2222

2323
val appId: AppId

cosec-api/src/main/kotlin/me/ahoo/cosec/api/context/request/DeviceIdCapable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typealias DeviceId = String
1717

1818
interface DeviceIdCapable {
1919
companion object {
20-
const val DEVICE_ID_KEY = "CoSec-Device-Id"
20+
const val DEVICE_ID_KEY = "${COSEC_EXTEND_KEY_PREFIX}Device-Id"
2121
}
2222
val deviceId: DeviceId
2323
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
14+
package me.ahoo.cosec.api.context.request
15+
16+
const val COSEC_EXTEND_KEY_PREFIX = "CoSec-"

cosec-api/src/main/kotlin/me/ahoo/cosec/api/context/request/RequestIdCapable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typealias RequestId = String
1717

1818
interface RequestIdCapable {
1919
companion object {
20-
const val REQUEST_ID_KEY = "CoSec-Request-Id"
20+
const val REQUEST_ID_KEY = "${COSEC_EXTEND_KEY_PREFIX}Request-Id"
2121
}
2222

2323
val requestId: RequestId

cosec-api/src/main/kotlin/me/ahoo/cosec/api/context/request/SpaceIdCapable.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typealias SpaceId = String
1717

1818
interface SpaceIdCapable {
1919
companion object {
20-
const val SPACE_ID_KEY = "CoSec-Space-Id"
20+
const val SPACE_ID_KEY = "${COSEC_EXTEND_KEY_PREFIX}Space-Id"
2121
const val DEFAULT = ""
2222
}
2323

cosec-api/src/main/kotlin/me/ahoo/cosec/api/permission/PermissionGroup.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ package me.ahoo.cosec.api.permission
1515

1616
import me.ahoo.cosec.api.Named
1717

18-
/**
19-
* Permission group.
20-
*/
2118
interface PermissionGroup : Named {
2219
override val name: String
2320
val description: String
2421
val permissions: List<Permission>
22+
23+
/**
24+
* Whether it is a space resource
25+
*/
26+
val spaced: Boolean
2527
}

cosec-core/src/main/kotlin/me/ahoo/cosec/permission/AppPermissionData.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
package me.ahoo.cosec.permission
1515

1616
import me.ahoo.cosec.api.permission.AppPermission
17+
import me.ahoo.cosec.api.permission.Permission
1718
import me.ahoo.cosec.api.permission.PermissionGroup
19+
import me.ahoo.cosec.api.permission.PermissionId
1820
import me.ahoo.cosec.api.policy.ConditionMatcher
1921
import me.ahoo.cosec.policy.condition.AllConditionMatcher
2022

@@ -24,7 +26,7 @@ data class AppPermissionData(
2426
override val groups: List<PermissionGroup> = listOf()
2527
) : AppPermission {
2628
@delegate:Transient
27-
override val permissionIndexer: Map<String, me.ahoo.cosec.api.permission.Permission> by lazy(this) {
29+
override val permissionIndexer: Map<PermissionId, Permission> by lazy(this) {
2830
super.permissionIndexer
2931
}
3032

cosec-core/src/main/kotlin/me/ahoo/cosec/permission/PermissionGroupData.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ import me.ahoo.cosec.api.permission.PermissionGroup
1919
data class PermissionGroupData(
2020
override val name: String,
2121
override val description: String = "",
22-
override val permissions: List<Permission> = listOf()
22+
override val permissions: List<Permission> = listOf(),
23+
override val spaced: Boolean = false
2324
) : PermissionGroup

0 commit comments

Comments
 (0)