chore: checkpoint 第一版
ci / verify (push) Canceled after 0s

This commit is contained in:
Codex Local
2026-09-06 17:04:11 +08:00
parent a8cdec98d1
commit 0c2151ace9
659 changed files with 185855 additions and 554 deletions
+38
View File
@@ -31,3 +31,41 @@ func DeviceAuth(verifier DeviceRequestVerifier, next http.Handler) http.Handler
next.ServeHTTP(writer, request.WithContext(deviceauth.WithIdentity(request.Context(), identity)))
})
}
func RequireDeviceActivation(allowed []string, next http.Handler) http.Handler {
allowedSet := make(map[string]struct{}, len(allowed))
for _, state := range allowed {
allowedSet[state] = struct{}{}
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
identity, ok := deviceauth.FromContext(r.Context())
if !ok {
WriteError(w, r, http.StatusUnauthorized, "DEVICE_AUTHENTICATION_FAILED", "设备身份验证失败")
return
}
state := identity.ActivationState
if state == "" {
state = "ACTIVE"
}
if _, ok := allowedSet[state]; !ok {
WriteAPIError(w, r, http.StatusConflict, Error{Code: "DEVICE_ACTIVATION_REQUIRED", Message: "当前设备激活状态不能执行该操作", Details: map[string]any{"activation_state": state, "allowed_states": allowed}})
return
}
next.ServeHTTP(w, r)
})
}
func RequireHardwareLicense(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
identity, ok := deviceauth.FromContext(r.Context())
if !ok {
WriteError(w, r, http.StatusUnauthorized, "DEVICE_AUTHENTICATION_FAILED", "设备身份验证失败")
return
}
if identity.VoiceRuntime == "volc_hardware_agent" && !identity.HardwareLicenseReady {
WriteError(w, r, http.StatusConflict, "HARDWARE_LICENSE_REQUIRED", "设备没有已激活且未到期的硬件智能体License")
return
}
next.ServeHTTP(w, r)
})
}