From 1be5254b241d8ad3cd2cb4265630c6aed5f959da Mon Sep 17 00:00:00 2001 From: DEV Date: Wed, 11 Dec 2024 23:17:00 +0100 Subject: [PATCH] vigil --- brbac/active.go | 3 +- brbac/actor.go | 47 +++++++ brbac/actor_flags.go | 8 +- brbac/actor_state.go | 2 +- brbac/brbac_i/d_role_manager.go | 55 ++++++++ brbac/brbac_i/d_role_provider.go | 53 ++++++++ brbac/brbac_i/d_role_repository.go | 50 ++++++++ brbac/brbac_i/d_user_manager.go | 54 ++++++++ brbac/brbac_i/d_user_provider.go | 56 +++++++++ brbac/brbac_i/d_user_repository.go | 51 ++++++++ brbac/brbac_i/go.mod | 3 + brbac/role.go | 84 ++++--------- brbac/role_manager.go | 95 ++++++++++++++ brbac/role_provider.go | 6 +- brbac/role_repository.go | 33 +++++ brbac/roles.go | 30 +++++ brbac/roles_test.go | 6 +- brbac/session.go | 39 ++++++ brbac/session_manager.go | 27 ++++ brbac/session_provider.go | 27 ++++ brbac/session_repository.go | 27 ++++ brbac/user.go | 39 ++++++ brbac/user_manager.go | 36 ++++++ brbac/user_provider.go | 37 ++++++ brbac/user_repository.go | 37 ++++++ core/rsls/r_bool.go | 45 ------- core/rsls/r_bool_error.go | 58 +++++++++ core/rsls/r_bool_ok.go | 49 ++++++++ core/rsls/rboolBench_test.go | 2 +- go.work | 2 + vigil/active.go | 196 +++++++++++++++++++++++++++++ vigil/actor_id.go | 52 ++++++++ vigil/actor_mode.go | 49 ++++++++ vigil/actor_state.go | 75 +++++++++++ vigil/actor_state_flags.go | 41 ++++++ vigil/actor_type.go | 104 +++++++++++++++ vigil/actor_type_atts.go | 45 +++++++ vigil/go.mod | 3 + 38 files changed, 1509 insertions(+), 117 deletions(-) create mode 100644 brbac/actor.go create mode 100644 brbac/brbac_i/d_role_manager.go create mode 100644 brbac/brbac_i/d_role_provider.go create mode 100644 brbac/brbac_i/d_role_repository.go create mode 100644 brbac/brbac_i/d_user_manager.go create mode 100644 brbac/brbac_i/d_user_provider.go create mode 100644 brbac/brbac_i/d_user_repository.go create mode 100644 brbac/brbac_i/go.mod create mode 100644 brbac/role_manager.go create mode 100644 brbac/role_repository.go create mode 100644 brbac/roles.go create mode 100644 brbac/session.go create mode 100644 brbac/session_manager.go create mode 100644 brbac/session_provider.go create mode 100644 brbac/session_repository.go create mode 100644 brbac/user.go create mode 100644 brbac/user_manager.go create mode 100644 brbac/user_provider.go create mode 100644 brbac/user_repository.go create mode 100644 core/rsls/r_bool_error.go create mode 100644 core/rsls/r_bool_ok.go create mode 100644 vigil/active.go create mode 100644 vigil/actor_id.go create mode 100644 vigil/actor_mode.go create mode 100644 vigil/actor_state.go create mode 100644 vigil/actor_state_flags.go create mode 100644 vigil/actor_type.go create mode 100644 vigil/actor_type_atts.go create mode 100644 vigil/go.mod diff --git a/brbac/active.go b/brbac/active.go index c4bc5aa..17dcdb8 100644 --- a/brbac/active.go +++ b/brbac/active.go @@ -35,7 +35,8 @@ var ( ErrInvalidIDRole errs.ErrCode ErrRoleCycle errs.ErrCode - RoleProvider RoleProvider + RoleManager RoleManager + UserManager UserManager } { diff --git a/brbac/actor.go b/brbac/actor.go new file mode 100644 index 0000000..8334ad6 --- /dev/null +++ b/brbac/actor.go @@ -0,0 +1,47 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name actor.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + +import "time" + +type ( + + + Actor struct { + ID ActorID + State ActorState + Flags ActorFlags + + CreatedBy ActorID + CreatedAt time.Time + ModifiedBy ActorID + ModifiedAt time.Time + + Name string + Description string + } +) + + diff --git a/brbac/actor_flags.go b/brbac/actor_flags.go index 279f159..93ef0a9 100644 --- a/brbac/actor_flags.go +++ b/brbac/actor_flags.go @@ -2,7 +2,7 @@ // ๐Ÿš€ Project Active8 // ๐Ÿ”— Active Thing (activething.com) git.activething.com/go // -// File name actor_flags.go +// File name actor_state_flags.go // โœ๏ธ Created by DEV // ๐Ÿ“… Modified 07/12/2024 // @@ -31,6 +31,7 @@ const ( ActorFlagRequired ActorFlags = 0b00000010 ActorFlagRestricted ActorFlags = 0b00000011 ActorFlagLimited ActorFlags = 0b00000100 + ActorFlagUnique ActorFlags = 0b00000101 // Solo puede existir un actor simultaneamente ) @@ -61,6 +62,11 @@ func (a ActorFlags) HasLimited() bool { return a&ActorFlagLimited != 0 } +func (a ActorFlags) HasUnique () bool { + return a&ActorFlagUnique != 0 +} + + func (a ActorFlags) Count() int { if a == 0 { return 0 diff --git a/brbac/actor_state.go b/brbac/actor_state.go index 722727c..9cd92b1 100644 --- a/brbac/actor_state.go +++ b/brbac/actor_state.go @@ -2,7 +2,7 @@ // ๐Ÿš€ Project Active8 // ๐Ÿ”— Active Thing (activething.com) git.activething.com/go // -// File name actor_state.go +// File name actor_mode.go // โœ๏ธ Created by DEV // ๐Ÿ“… Modified 07/12/2024 // diff --git a/brbac/brbac_i/d_role_manager.go b/brbac/brbac_i/d_role_manager.go new file mode 100644 index 0000000..1560f1d --- /dev/null +++ b/brbac/brbac_i/d_role_manager.go @@ -0,0 +1,55 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name d_role_manager.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac_i + +import "brbac" + +type ( + + + DRoleManager struct { + provider brbac.RoleProvider + repository brbac.RoleRepository + } + + + DRoleManagerFnc func (rm *DRoleManager) error + +) + + + +func NewDRoleManager (provider brbac.RoleProvider, repository brbac.RoleRepository, ops ... DRoleManagerFnc) (*DRoleManager, error) { + rm := &DRoleManager { + provider : provider, + repository : repository, + } + for _,o := range ops { + if e:=o(rm); e!=nil { + return nil,e + } + } + return rm,nil +} diff --git a/brbac/brbac_i/d_role_provider.go b/brbac/brbac_i/d_role_provider.go new file mode 100644 index 0000000..0c509bf --- /dev/null +++ b/brbac/brbac_i/d_role_provider.go @@ -0,0 +1,53 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name d_role_provider.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac_i + +import "brbac" + +type ( + + DRoleProvider struct { + repository brbac.RoleRepository + } + + + DRoleProviderFnc func(rp *DRoleProvider) error + +) + + +func NewDRoleProvider (repository brbac.RoleRepository, ops ...DRoleProviderFnc) (*DRoleProvider,error) { + rp := &DRoleProvider{ + repository: repository, + } + for _,o := range ops { + if e := o(rp); e != nil { + return nil,e + } + } + return rp,nil +} + + diff --git a/brbac/brbac_i/d_role_repository.go b/brbac/brbac_i/d_role_repository.go new file mode 100644 index 0000000..dfec27d --- /dev/null +++ b/brbac/brbac_i/d_role_repository.go @@ -0,0 +1,50 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name d_role_repository.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac_i + + + + +type ( + + + DRoleRepository struct { + + } + + DRoleRepositoryFnc func (rr *DRoleRepository) error + +) + + +func NewDRoleRepository (ops ...DRoleRepositoryFnc) (*DRoleRepository,error) { + rr := &DRoleRepository{} + for _,o := range ops { + if e:=o(rr); e != nil { + return nil,e + } + } + return rr,nil +} \ No newline at end of file diff --git a/brbac/brbac_i/d_user_manager.go b/brbac/brbac_i/d_user_manager.go new file mode 100644 index 0000000..b320ee5 --- /dev/null +++ b/brbac/brbac_i/d_user_manager.go @@ -0,0 +1,54 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name d_user_manager.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac_i + +import "brbac" + +type ( + + DUserManager struct { + provider brbac.UserProvider + repository brbac.UserRepository + } + + + DUserManagerFnc func (um *DUserManager) error + +) + +func NewDUserManager (provider brbac.UserProvider, repository brbac.UserRepository, ops ... DUserManagerFnc) (*DUserManager, error) { + um := &DUserManager { + provider : provider, + repository : repository, + } + for _,o := range ops { + if e:=o(um); e!=nil { + return nil,e + } + } + return um,nil +} + + diff --git a/brbac/brbac_i/d_user_provider.go b/brbac/brbac_i/d_user_provider.go new file mode 100644 index 0000000..f6f3417 --- /dev/null +++ b/brbac/brbac_i/d_user_provider.go @@ -0,0 +1,56 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name d_user_provider.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac_i + +import "brbac" + +type ( + + DUserProvider struct { + repository brbac.UserRepository + } + + + DUserProviderFnc func(rp *DUserProvider) error + +) + + +func NewDUserProvider (repository brbac.UserRepository, ops ...DUserProviderFnc) (*DUserProvider,error) { + rp := &DUserProvider{ + repository: repository, + } + for _,o := range ops { + if e := o(rp); e != nil { + return nil,e + } + } + return rp,nil +} + + + + + diff --git a/brbac/brbac_i/d_user_repository.go b/brbac/brbac_i/d_user_repository.go new file mode 100644 index 0000000..f1a9168 --- /dev/null +++ b/brbac/brbac_i/d_user_repository.go @@ -0,0 +1,51 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name d_user_repository.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac_i + + + +type ( + + + DUserRepository struct { + + } + + DUserRepositoryFnc func (rr *DUserRepository) error + +) + + +func NewDUserRepository (ops ...DUserRepositoryFnc) (*DUserRepository,error) { + rr := &DUserRepository{} + for _,o := range ops { + if e:=o(rr); e != nil { + return nil,e + } + } + return rr,nil +} + + diff --git a/brbac/brbac_i/go.mod b/brbac/brbac_i/go.mod new file mode 100644 index 0000000..445a9d3 --- /dev/null +++ b/brbac/brbac_i/go.mod @@ -0,0 +1,3 @@ +module brbac_i + +go 1.22 diff --git a/brbac/role.go b/brbac/role.go index 79047fe..52e3ffc 100644 --- a/brbac/role.go +++ b/brbac/role.go @@ -24,25 +24,35 @@ package brbac -import "rsls" - type ( Role struct { - roleID ActorID - State ActorState - Flags ActorFlags - name string - actors []ActorID - subRoles []ActorID + Actor + roles Roles } + RoleFnc func (role *Role) error ) + +func NewRole (ops ... RoleFnc) (*Role,error) { + r := &Role {} + for _,o := range ops { + if e := o(r); e != nil { + return nil,e + } + } + return r,nil +} + + + + +/* func (r *Role) AddRole (roleID ...ActorID) error { if len(roleID) == 0 { return nil @@ -52,7 +62,7 @@ func (r *Role) AddRole (roleID ...ActorID) error { state := make(map[ActorID]byte) for _,ri := range roleID { - if ri == r.roleID { + if ri == r.ID { return G.ErrRoleCycle } // Check if is RoleID @@ -60,12 +70,12 @@ func (r *Role) AddRole (roleID ...ActorID) error { return G.ErrInvalidIDRole } // Check if already exists - if HasActor(r.subRoles,ri) { + if HasActor(r.roles,ri) { continue } // **Verificaciรณn de ciclo antes de agregar el rol** - cycleResult := detectRoleCycleInHierarchy(r.roleID, ri, G.RoleProvider, &state) + cycleResult := detectRoleCycleInHierarchy(r.ID, ri, &state) if !cycleResult.IsOk() { return cycleResult.Fail() } else if cycleResult.Result() { @@ -73,10 +83,11 @@ func (r *Role) AddRole (roleID ...ActorID) error { } // Agregar el rol a los subroles - r.subRoles = append(r.subRoles, ri) + r.roles = append(r.roles, ri) } return nil } +*/ @@ -84,52 +95,3 @@ func (r *Role) AddRole (roleID ...ActorID) error { -func DetectRoleCycleInHierarchy(roleID, newRoleID ActorID, provider RoleProvider) rsls.RBool { - state := make(map[ActorID]byte) - return detectRoleCycleInHierarchy(roleID, newRoleID, G.RoleProvider, &state) -} - - - - -// detectRoleCycleInHierarchy realiza la verificaciรณn recursiva de si se forma un ciclo -func detectRoleCycleInHierarchy(roleID, newRoleID ActorID, provider RoleProvider, state *map[ActorID]byte) rsls.RBool { - - // Si el nuevo rol ya estรก en la jerarquรญa del rol actual, entonces hemos encontrado un ciclo - if (*state)[newRoleID] == 1 { - return rsls.BoolSuccessTrue // Ciclo detectado - } - - // Si el rol ha sido visitado completamente, entonces no es necesario revisarlo de nuevo - if (*state)[newRoleID] == 2 { - return rsls.BoolSuccessFalse - } - - // Marcar el rol como "en proceso" - (*state)[newRoleID] = 1 - - // Obtener los subroles del nuevo rol - subRoles, err := provider.GetSubRoles(newRoleID) - if err != nil { - return rsls.MakeBoolError(err) // Error al obtener los subroles - } - - // Realizar DFS para cada subrol del nuevo rol - for _, subRoleID := range subRoles { - if subRoleID == roleID { - // Detectar referencia directa al rol original, indicando un ciclo - return rsls.BoolSuccessTrue - } - cycleCheck := detectRoleCycleInHierarchy(roleID, subRoleID, provider, state) - if !cycleCheck.IsOk() ||cycleCheck.Result() { - return cycleCheck - } - } - - // Marcar el rol como "visitado" despuรฉs de procesar todos sus subroles - (*state)[newRoleID] = 2 - return rsls.BoolSuccessFalse // No se ha detectado un ciclo -} - - - diff --git a/brbac/role_manager.go b/brbac/role_manager.go new file mode 100644 index 0000000..84da417 --- /dev/null +++ b/brbac/role_manager.go @@ -0,0 +1,95 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name role_manager.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + +import "rsls" + +type ( + + + RoleManager interface { + + Create () (*Role,error) + Update (role *Role) error + Delete (roleID ActorID) error + + DelSubRole (roleID ...ActorID) error + AddSubRole (roleID ...ActorID) error + } +) + + + + + +func DetectRoleCycle(roleID, newRoleID ActorID, provider RoleProvider) rsls.RBool { + state := make(map[ActorID]byte) + return detectRoleCycle(roleID, newRoleID, provider, &state) +} + + + + +// detectRoleCycle realiza la verificaciรณn recursiva de si se forma un ciclo +func detectRoleCycle(roleID, newRoleID ActorID, provider RoleProvider, state *map[ActorID]byte) rsls.RBool { + + // Si el nuevo rol ya estรก en la jerarquรญa del rol actual, entonces hemos encontrado un ciclo + if (*state)[newRoleID] == 1 { + return rsls.RBoolOkTrue // Ciclo detectado + } + + // Si el rol ha sido visitado completamente, entonces no es necesario revisarlo de nuevo + if (*state)[newRoleID] == 2 { + return rsls.RBoolOkFalse + } + + // Marcar el rol como "en proceso" + (*state)[newRoleID] = 1 + + // Obtener los subroles del nuevo rol + subRoles, err := provider.GetSubRoles(newRoleID) + if err != nil { + return rsls.MakeBoolError(err) // Error al obtener los subroles + } + + // Realizar DFS para cada subrol del nuevo rol + for _, subRoleID := range subRoles { + if subRoleID == roleID { + // Detectar referencia directa al rol original, indicando un ciclo + return rsls.RBoolOkTrue + } + cycleCheck := detectRoleCycle(roleID, subRoleID, provider, state) + if !cycleCheck.IsOk() ||cycleCheck.Result() { + return cycleCheck + } + } + + // Marcar el rol como "visitado" despuรฉs de procesar todos sus subroles + (*state)[newRoleID] = 2 + return rsls.RBoolOkFalse // No se ha detectado un ciclo +} + + + diff --git a/brbac/role_provider.go b/brbac/role_provider.go index 0dd3f15..d62ba16 100644 --- a/brbac/role_provider.go +++ b/brbac/role_provider.go @@ -24,14 +24,12 @@ package brbac - - type ( RoleProvider interface { - //GetRole (roleID ActorID) (*Role,error) - GetSubRoles(roleID ActorID) ([]ActorID,error) + GetSubRoles (roleID ActorID) (Roles, error) } ) + diff --git a/brbac/role_repository.go b/brbac/role_repository.go new file mode 100644 index 0000000..4fbedd4 --- /dev/null +++ b/brbac/role_repository.go @@ -0,0 +1,33 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name role_repository.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + +type ( + + RoleRepository interface { + } +) + + diff --git a/brbac/roles.go b/brbac/roles.go new file mode 100644 index 0000000..cced139 --- /dev/null +++ b/brbac/roles.go @@ -0,0 +1,30 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name roles.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + + +type Roles []ActorID + + diff --git a/brbac/roles_test.go b/brbac/roles_test.go index c97aa4b..ddba475 100644 --- a/brbac/roles_test.go +++ b/brbac/roles_test.go @@ -40,7 +40,7 @@ func (m *MockRoleProvider) GetSubRoles(roleID ActorID) ([]ActorID, error) { func TestAddRole(t *testing.T) { - // Crear un RoleProvider simulado con algunos roles y subroles + // Crear un RoleManager simulado con algunos roles y subroles provider := &MockRoleProvider{ roles: map[ActorID][]ActorID{ @@ -49,7 +49,7 @@ func TestAddRole(t *testing.T) { 0x12: {}, // El rol 0x12 no tiene subroles }, } - G.RoleProvider = provider + G.RoleManager = provider // Crear un rol inicial role := &Role{ @@ -86,7 +86,7 @@ func TestAddRole(t *testing.T) { } func TestDetectRoleCycleInHierarchy(t *testing.T) { - // Crear un RoleProvider simulado con algunos roles y subroles + // Crear un RoleManager simulado con algunos roles y subroles provider := &MockRoleProvider{ roles: map[ActorID][]ActorID{ 0x10: {0x11, 0x12}, // El rol 0x10 tiene subroles 0x11 y 0x12 diff --git a/brbac/session.go b/brbac/session.go new file mode 100644 index 0000000..ffb5591 --- /dev/null +++ b/brbac/session.go @@ -0,0 +1,39 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name session.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 10/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + + + +type ( + + + Session interface { + + Principal () *User + } + +) + + diff --git a/brbac/session_manager.go b/brbac/session_manager.go new file mode 100644 index 0000000..9c039b6 --- /dev/null +++ b/brbac/session_manager.go @@ -0,0 +1,27 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name session_manager.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 10/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + + diff --git a/brbac/session_provider.go b/brbac/session_provider.go new file mode 100644 index 0000000..21e7f32 --- /dev/null +++ b/brbac/session_provider.go @@ -0,0 +1,27 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name session_provider.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 10/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + + diff --git a/brbac/session_repository.go b/brbac/session_repository.go new file mode 100644 index 0000000..5f46e13 --- /dev/null +++ b/brbac/session_repository.go @@ -0,0 +1,27 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name session_repository.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 10/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + + diff --git a/brbac/user.go b/brbac/user.go new file mode 100644 index 0000000..d2dc2ca --- /dev/null +++ b/brbac/user.go @@ -0,0 +1,39 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name user.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + + + +type ( + + User struct { + Actor + roles Roles + } + + +) + + diff --git a/brbac/user_manager.go b/brbac/user_manager.go new file mode 100644 index 0000000..b4879b7 --- /dev/null +++ b/brbac/user_manager.go @@ -0,0 +1,36 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name user_manager.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + + +type ( + + + UserManager interface { + + } +) + + diff --git a/brbac/user_provider.go b/brbac/user_provider.go new file mode 100644 index 0000000..fed70de --- /dev/null +++ b/brbac/user_provider.go @@ -0,0 +1,37 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name user_provider.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + + +type ( + + + UserProvider interface { + + + } +) + + diff --git a/brbac/user_repository.go b/brbac/user_repository.go new file mode 100644 index 0000000..590ef60 --- /dev/null +++ b/brbac/user_repository.go @@ -0,0 +1,37 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name user_repository.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 brbac + + + +type ( + + + UserRepository interface { + + } +) + + diff --git a/core/rsls/r_bool.go b/core/rsls/r_bool.go index c2191ea..1ef2a5b 100644 --- a/core/rsls/r_bool.go +++ b/core/rsls/r_bool.go @@ -25,12 +25,6 @@ package rsls -const ( - BoolSuccessTrue BoolSuccess = true - BoolSuccessFalse BoolSuccess = false -) - - type ( RBool interface { @@ -39,47 +33,8 @@ type ( Fail () error } - BoolSuccess bool - - BoolError struct { - error - } - ) -func (s BoolSuccess) IsOk () bool { - return true } - -func (s BoolSuccess) Result() bool { - return bool(s) } - -func (s BoolSuccess) Fail () error { - return nil } - - - -func MakeBoolError (err error) BoolError { - return BoolError{ err } -} - -func (s BoolError) IsOk () bool { - return false } - -func (s BoolError) Result() bool { - return false } - -func (s BoolError) Fail () error { - return s.error } - - - - - - - - - - diff --git a/core/rsls/r_bool_error.go b/core/rsls/r_bool_error.go new file mode 100644 index 0000000..060775a --- /dev/null +++ b/core/rsls/r_bool_error.go @@ -0,0 +1,58 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name r_bool_error.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 rsls + + +type ( + + RBoolError struct { + error + } + +) + + + + +func MakeBoolError (err error) RBoolError { + return RBoolError{err } } + + +func (_ RBoolError) IsOk () bool { + return false } + +func (_ RBoolError) Result() bool { + return false } + +func (s RBoolError) Fail () error { + return s.error } + + + + + + + + diff --git a/core/rsls/r_bool_ok.go b/core/rsls/r_bool_ok.go new file mode 100644 index 0000000..3c5c322 --- /dev/null +++ b/core/rsls/r_bool_ok.go @@ -0,0 +1,49 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name r_bool_ok.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 09/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 rsls + + + + + +const ( + RBoolOkTrue RBoolOk = true + RBoolOkFalse RBoolOk = false +) + + +type RBoolOk bool + + + +func (_ RBoolOk) IsOk () bool { + return true } + +func (s RBoolOk) Result() bool { + return bool(s) } + +func (_ RBoolOk) Fail () error { + return nil } + diff --git a/core/rsls/rboolBench_test.go b/core/rsls/rboolBench_test.go index 564dcf1..5e085fb 100644 --- a/core/rsls/rboolBench_test.go +++ b/core/rsls/rboolBench_test.go @@ -41,7 +41,7 @@ func traditionalBoolError(input int) (bool, error) { // Mรฉtodo con RBool func rboolMethod(input int) RBool { if input > 0 { - return BoolSuccessTrue + return RBoolOkTrue } return MakeBoolError(errors.New("input must be greater than zero")) } diff --git a/go.work b/go.work index 37c7150..f891dce 100644 --- a/go.work +++ b/go.work @@ -5,6 +5,8 @@ use ( core core/errs core/rsls + vigil brbac + brbac/brbac_i ) \ No newline at end of file diff --git a/vigil/active.go b/vigil/active.go new file mode 100644 index 0000000..ed3e131 --- /dev/null +++ b/vigil/active.go @@ -0,0 +1,196 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name active.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 11/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 vigil + +import "errs" + +var ( + + // G Public vars + G = struct { + ErrInvalidActor errs.ErrCode + } { + ErrInvalidActor : errs.ErrCode("invalid-actor-type"), + } + + + // g Private vars + g = struct { + actorFlags []ActorStateFlags + actorFlagNames []string + + actorModeNames []string + + actorTypeAtts []ActorTypeAtts + actorTypeNames []string + }{ + + actorFlags: []ActorStateFlags{ + ActorFlagVerified, + ActorFlagRequired, + ActorFlagRestricted, + ActorFlagLimited, + ActorFlagCompromised, + }, + + actorFlagNames: []string { + "Verified", + "Required", + "Restricted", + "Limited", + "Compromised", + }, + + + actorModeNames: []string{ + "Active", + "Inactive", + "Pending", + "Suspended ", + "Revoked", + "Paused", + "Expired", + "Deleted", + }, + + + actorTypeNames: []string{ + "User", // 0x00 + "Role", // 0x01 + "Service", // 0x02 + "Device", // 0x03 + "Group", // 0x04 + "Organization", // 0x05 + "APIKey", // 0x06 + "System", // 0x07 + "Admin", // 0x08 + "Visitor", // 0x09 + "Auditor", // 0x0A + "ExternalClient", // 0x0B + "Provider", // 0x0C + "TemporaryToken", // 0x0D + "Bot", // 0x0E + "Reserved", // 0x0F + "BlockchainNode", // 0x10 + "BlockchainUser", // 0x11 + "SmartContract", // 0x12 + "BlockchainAPI", // 0x13 + "Wallet", // 0x14 + "Miner", // 0x15 + "Validator", // 0x16 + "DApp", // 0x17 + "Token", // 0x18 + "BlockchainOracle", // 0x19 + "BlockchainExplorer", // 0x1A + "DAO", // 0x1B + "NFT", // 0x1C + "BlockchainBridge", // 0x1D + "Staking", // 0x1E + "DefiPlatform", // 0x1F + "BlockchainWallet", // 0x20 + "BlockchainExplorerAPI", // 0x21 + "BlockchainTransaction", // 0x22 + "BlockchainBackup", // 0x23 + "SecurityModule", // 0x24 + "QuantumComputer", // 0x25 + "QuantumWallet", // 0x26 + "AI", // 0x30 + "CloudService", // 0x31 + "Microservice", // 0x32 + "ThirdParty", // 0x33 + "ExternalSystem", // 0x34 + "MobileDevice", // 0x35 + "ExternalAPI", // 0x36 + "Server", // 0x37 + "UserAgent", // 0x38 + "Container", // 0x39 + "Network", // 0x3A + "EdgeDevice", // 0x3B + "VirtualMachine", // 0x3C + "Hypervisor", // 0x3D + }, + + + actorTypeAtts: []ActorTypeAtts { + ActorTypeAttCanLogin | ActorTypeAttExclusive, // User", 0x00 + 0, // Role", 0x01 + 0, // Service", 0x02 + 0, // Device", 0x03 + 0, // Group", 0x04 + 0, // Organization", 0x05 + 0, // APIKey", 0x06 + 0, // System", 0x07 + 0, // Admin", 0x08 + 0, // Visitor", 0x09 + 0, // Auditor", 0x0A + 0, // ExternalClient", 0x0B + 0, // Provider", 0x0C + 0, // TemporaryToken", 0x0D + 0, // Bot", 0x0E + 0, // Reserved", 0x0F + 0, // BlockchainNode", 0x10 + 0, // BlockchainUser", 0x11 + 0, // SmartContract", 0x12 + 0, // BlockchainAPI", 0x13 + 0, // Wallet", 0x14 + 0, // Miner", 0x15 + 0, // Validator", 0x16 + 0, // DApp", 0x17 + 0, // Token", 0x18 + 0, // BlockchainOracle", 0x19 + 0, // BlockchainExplorer", 0x1A + 0, // DAO", 0x1B + 0, // NFT", 0x1C + 0, // BlockchainBridge", 0x1D + 0, // Staking", 0x1E + 0, // DefiPlatform", 0x1F + 0, // BlockchainWallet", 0x20 + 0, // BlockchainExplorerAPI", 0x21 + 0, // BlockchainTransaction", 0x22 + 0, // BlockchainBackup", 0x23 + 0, // SecurityModule", 0x24 + 0, // QuantumComputer", 0x25 + 0, // QuantumWallet", 0x26 + 0, // AI", 0x30 + 0, // CloudService", 0x31 + 0, // Microservice", 0x32 + 0, // ThirdParty", 0x33 + 0, // ExternalSystem", 0x34 + 0, // MobileDevice", 0x35 + 0, // ExternalAPI", 0x36 + 0, // Server", 0x37 + 0, // UserAgent", 0x38 + 0, // Container", 0x39 + 0, // Network", 0x3A + 0, // EdgeDevice", 0x3B + 0, // VirtualMachine", 0x3C + 0, // Hypervisor", 0x3D + }, + } + +) + + + diff --git a/vigil/actor_id.go b/vigil/actor_id.go new file mode 100644 index 0000000..c69cd10 --- /dev/null +++ b/vigil/actor_id.go @@ -0,0 +1,52 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name actor_id.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 11/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 vigil + + + + +type ActorID uint64 + + +// GetActorType extrae los 6 bits mรกs significativos para determinar el tipo de Actor. +func (a ActorID) GetActorType() ActorType { + // Desplazar el ActorID 58 bits a la derecha para que los 6 bits mรกs significativos estรฉn al inicio, + // y luego convertirlos en un ActorType. + return ActorType(a >> 58) // Extraemos los 6 bits mรกs significativos +} + + +// SetActorType establece los 6 bits mรกs significativos como el tipo de Actor. +func (a ActorID) SetActorType(actorType ActorType) ActorID { + // Verificar que el tipo estรก dentro del rango de 6 bits (0-63). + if actorType > 0x3F { // 0x3F es 63 en decimal, el rango de 6 bits + panic(G.ErrInvalidActor) + } + // Establecer el nuevo tipo en los 6 bits mรกs significativos. + return ActorID((a &^ (ActorID(0x3F) << 58)) | (ActorID(actorType) << 58)) +} + + + diff --git a/vigil/actor_mode.go b/vigil/actor_mode.go new file mode 100644 index 0000000..fee7f88 --- /dev/null +++ b/vigil/actor_mode.go @@ -0,0 +1,49 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name actor_mode.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 11/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 vigil + + + + + +const ( + // Modo (primeros 4 bits) + ActorModeActive ActorMode = 0b000 // El usuario estรก activo y no tiene restricciones + ActorModeInactive ActorMode = 0b001 // El usuario estรก inactivo y temporalmente deshabilitado + ActorModePending ActorMode = 0b010 // El usuario estรก pendiente de activaciรณn (por ejemplo, verificaciรณn de correo electrรณnico) + ActorModeSuspended ActorMode = 0b011 // El usuario estรก suspendido debido a problemas de seguridad o polรญticas + ActorModeRevoked ActorMode = 0b100 // El acceso del usuario ha sido revocado permanentemente + ActorModePaused ActorMode = 0b101 // El usuario ha pausado su cuenta (puede reactivarse) + ActorModeExpired ActorMode = 0b110 // La cuenta del usuario ha expirado (por ejemplo, acceso temporal) + ActorModeDeleted ActorMode = 0b111 // La cuenta del usuario estรก eliminada y ya no existe +) + + +type ActorMode uint8 + + + + + diff --git a/vigil/actor_state.go b/vigil/actor_state.go new file mode 100644 index 0000000..16de00c --- /dev/null +++ b/vigil/actor_state.go @@ -0,0 +1,75 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name actor_state.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 11/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 vigil + +import "math/bits" + + +const ( + modeBits = 4 + modeMask ActorState = 0b1111 +) + + + +type ActorState uint16 + + + + +func (s ActorState) GetMode() ActorMode { + return ActorMode(s & modeMask) } + +func (s ActorState) SetMode(state ActorMode) ActorState { + return (s &^ modeMask) | (ActorState(state) & modeMask) } + + + + +func (s ActorState) HasFlag (flag ActorStateFlags) bool { + return s & ActorState(flag) != 0 } + +func (s ActorState) SetFlag (flag ActorStateFlags) ActorState { + return (s &^ modeMask) | ((s | ActorState(flag)) &^ modeMask) } + +func (s ActorState) DelFlag (flag ActorStateFlags) ActorState { + return (s &^ modeMask) | ((s &^ ActorState(flag)) &^ modeMask) } + +func (s ActorState) ClearFlags () ActorState { + return s & modeMask } + + +func (s ActorState) Count() int { + return bits.OnesCount16(uint16(s) >> modeBits) } + +func (s ActorState) Flags() []ActorStateFlags { + var flags []ActorStateFlags + for _, flag := range g.actorFlags { + if s.HasFlag(flag) { + flags = append(flags, flag) + } + } + return flags +} diff --git a/vigil/actor_state_flags.go b/vigil/actor_state_flags.go new file mode 100644 index 0000000..9132cc3 --- /dev/null +++ b/vigil/actor_state_flags.go @@ -0,0 +1,41 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name actor_state_flags.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 11/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 vigil + + + + +const ( + // Flags (รบltimos 16 - modeBits ) + _ ActorStateFlags = iota + ActorFlagVerified ActorStateFlags = 1 << (modeBits + iota - 1) + ActorFlagRequired + ActorFlagRestricted + ActorFlagLimited + ActorFlagCompromised +) + + +type ActorStateFlags uint16 \ No newline at end of file diff --git a/vigil/actor_type.go b/vigil/actor_type.go new file mode 100644 index 0000000..153b715 --- /dev/null +++ b/vigil/actor_type.go @@ -0,0 +1,104 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name actor_type.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 11/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 vigil + + + +// Definiciรณn de los valores posibles para ActorType (64 tipos con 8 bits). +const ( + // Tipos Generales + ActorTypeUser ActorType = iota + ActorTypeRole // Rol + ActorTypeService // Servicio + ActorTypeDevice // Dispositivo (IoT, hardware) + ActorTypeGroup // Grupo + ActorTypeOrganization // Organizaciรณn + ActorTypeAPIKey // API Key + ActorTypeSystem // Sistema interno + ActorTypeAdmin // Administrador + ActorTypeVisitor // Visitante + ActorTypeAuditor // Auditor + ActorTypeExternalClient // Cliente Externo + ActorTypeProvider // Proveedor + ActorTypeTemporaryToken // Token Temporal + ActorTypeBot // Bot o script + ActorTypeReserved // Reservado para futuras expansiones + + // Tipos Relacionados con Blockc + ActorTypeBlockchainNode // Nodo de blockchain + ActorTypeBlockchainUser // Usuario de blockchain + ActorTypeSmartContract // Contrato inteligente (smart contract) + ActorTypeBlockchainAPI // API de blockchain + ActorTypeWallet // Billetera (wallet) de blockchain + ActorTypeMiner // Minero de blockchain + ActorTypeValidator // Validador de transacciones o bloques + ActorTypeDApp // Aplicaciรณn descentralizada (DApp) + ActorTypeToken // Token o criptomoneda + ActorTypeBlockchainOracle // Orรกculo de blockchain (proveedor de datos externos) + ActorTypeBlockchainExplorer // Explorador de blockchain + ActorTypeDAO // Organizaciรณn Autรณnoma Descentralizada (DAO) + ActorTypeNFT // Token No Fungible (NFT) + ActorTypeBlockchainBridge // Puente entre blockchains + ActorTypeStaking // Participante en staking + ActorTypeDefiPlatform // Plataforma de Finanzas Descentralizadas (DeFi) + ActorTypeBlockchainWallet // Billetera especรญfica de blockchain + ActorTypeBlockchainExplorerAPI // API para exploradores de blockchain + ActorTypeBlockchainTransaction // Transacciรณn de blockchain + ActorTypeBlockchainBackup // Copia de seguridad o servicio de respaldo de blockchain + ActorTypeSecurityModule // Mรณdulo de seguridad de blockchain + ActorTypeQuantumComputer // Computadora cuรกntica (relacionada con blockchain) + ActorTypeQuantumWallet // Billetera cuรกntica (relacionada con blockchain) + + // Otros Tipos + ActorTypeAI // Actor basado en inteligencia artificial + ActorTypeCloudService // Servicio en la nube + ActorTypeMicroservice // Microservicio + ActorTypeThirdParty // Actor externo o tercero + ActorTypeExternalSystem // Sistema Externo + ActorTypeMobileDevice // Dispositivo mรณvil + ActorTypeExternalAPI // API externa + ActorTypeServer // Servidor fรญsico o virtual + ActorTypeUserAgent // Agente de usuario (navegador, app, etc.) + ActorTypeContainer // Contenedor (Docker, etc.) + ActorTypeNetwork // Red o infraestructura de red + ActorTypeEdgeDevice // Dispositivo en la periferia de la red + ActorTypeVirtualMachine // Mรกquina virtual + ActorTypeHypervisor // Hypervisor o administrador de mรกquinas virtuales +) + + +type ActorType uint8 + + + +func (a ActorType) Name () string { + i := int(a) + if i < len(g.actorTypeNames) { + return g.actorTypeNames[i] + } + return "" +} + + diff --git a/vigil/actor_type_atts.go b/vigil/actor_type_atts.go new file mode 100644 index 0000000..72bf837 --- /dev/null +++ b/vigil/actor_type_atts.go @@ -0,0 +1,45 @@ +// ------------------------------------------------------------------------ +// ๐Ÿš€ Project Active8 +// ๐Ÿ”— Active Thing (activething.com) git.activething.com/go +// +// File name actor_type_atts.go +// โœ๏ธ Created by DEV +// ๐Ÿ“… Modified 11/12/2024 +// +// ๐Ÿ”’ Copyright 2024 activething.com +// +// ๐Ÿ“œ LICENSE -------------------------------------------------------------- +// Licensed 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 vigil + + + +const ( + + ActorTypeAttCanLogin ActorTypeAtts =1 << iota + ActorTypeAttExclusive + ActorTypeAttSameTypes + ActorTypeAttNotSameTypes + +) + + + +type ActorTypeAtts uint8 + + + + + diff --git a/vigil/go.mod b/vigil/go.mod new file mode 100644 index 0000000..5500f16 --- /dev/null +++ b/vigil/go.mod @@ -0,0 +1,3 @@ +module vigil + +go 1.22