Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
useradm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Root
useradm
Commits
51d7b894
Commit
51d7b894
authored
4 months ago
by
Theo
Browse files
Options
Downloads
Patches
Plain Diff
Improve some stuff
parent
0ca6af4e
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
README.md
+45
-8
45 additions, 8 deletions
README.md
cmd/user.go
+1
-1
1 addition, 1 deletion
cmd/user.go
cmd/user/mod.go
+3
-2
3 additions, 2 deletions
cmd/user/mod.go
cmd/user/remove.go
+8
-9
8 additions, 9 deletions
cmd/user/remove.go
cmd/user/show.go
+5
-0
5 additions, 0 deletions
cmd/user/show.go
with
62 additions
and
20 deletions
README.md
+
45
−
8
View file @
51d7b894
...
...
@@ -10,8 +10,7 @@ To install, just clone the repo:
and build the binary:
cd useradm
go build -o useradm
cd useradm && go build -o useradm
if you want add it the go path use:
...
...
@@ -42,7 +41,6 @@ in flags the command needs identifiers to make the search, such as:
here we are searching for a user with name with pedro, grr with 2024, is part
of the group 'bcc' and -i is to make the search case insensitive.
### Create
To create a user we can use:
...
...
@@ -77,7 +75,6 @@ be removed from LDAP and Kerberos, their directories will end up at:
webdir: /home/contas_removidas/html/<Year of removal>/
webdir: /nobackup/contas_removidas/<Year of removal>/
### Modify
To modify a user we can do:
...
...
@@ -141,7 +138,9 @@ Then we generate the request that will give us all the users, get the response,
and store the result in structs.
Many other requests are made in the code and you can learn the syntax by reading
it or via the docs of the module.
it or via the docs of the module. One thing I want to add it that in LDAP, group
assingments need to be done by setting the user object to be member of the group
and set the group object to have the user as a member. Interesting...
### Kerberos
...
...
@@ -163,10 +162,48 @@ that minimizes those misfortunes.
`useradm.py`
had 3 function to generate names that used a very wierd algorithm.
At first I just copied them, then I thought it was too long and repetitive so
I merged them into one (See commit e
303dcc1
). It was VERY ugly, so Fernando K.
I merged them into one (See commit e
49eca75
). It was VERY ugly, so Fernando K.
helped and rewrote/improved the algorithm to a more mantainable state, thanks :)
(See commit e9762f8b)
TODO: explain it
There are 3 types of login generation: ini, first, last. Instead of explaining
how the algorithm works, I believe it is best to just show examples. So for the
user with name Fabiano Antunes Pereira de Souza, with GRR 20241982:
'ini' would create the following (based on
`variance`
variable):
faps24
faaps24
faanps24
faanpes24
faanpeso24
fabanpeso24
and so on. 'first' would create something like this:
fabiano
fabianoa
fabianoap
fabianoaps
fabianoanps
fabianoanpes
fabianoanpeso
and so on. 'last' would generate:
fapsouza
faapsouza
faanpsouza
faanpesouza
fabanpesouza
fabantpesouza
and so on...
Essentially we add one letter to each name part for each variance added. We also
remove any connectives (do, da, de, dos, von...) from the name. If there comes a
time a person appears with a new connective, update the formatName() function
currently at
`/cmd/user/create.go`
to account for that :)
TODO: finish...
This diff is collapsed.
Click to expand it.
cmd/user.go
+
1
−
1
View file @
51d7b894
...
...
@@ -15,7 +15,7 @@ new users, please do so with the bulk subcommand.`,
func
init
()
{
userCmd
.
AddCommand
(
user
.
CreateUserCmd
)
userCmd
.
AddCommand
(
user
.
Delet
eUserCmd
)
userCmd
.
AddCommand
(
user
.
Remov
eUserCmd
)
userCmd
.
AddCommand
(
user
.
ModCmd
)
userCmd
.
AddCommand
(
user
.
ShowCmd
)
userCmd
.
AddCommand
(
user
.
ResetCmd
)
...
...
This diff is collapsed.
Click to expand it.
cmd/user/mod.go
+
3
−
2
View file @
51d7b894
...
...
@@ -99,8 +99,8 @@ func modifyUserFunc(cmd *cobra.Command, args []string) error {
}
if
err
:=
clearCache
();
err
!=
nil
{
fmt
.
Printf
(
`Failed to reload cache
all is ok but may take a while to apply
fmt
.
Printf
(
`Failed to reload cache
!
all is ok but may take a while to apply
the changes
Output: %v`
,
err
)
}
else
{
fmt
.
Printf
(
"Changes applied!
\n
"
)
...
...
@@ -174,6 +174,7 @@ func applyChangesToUser(c model.User, n cfg) model.User {
return
c
}
// generates a yaml file of a config state for the user to edit
func
promptUserYaml
(
state
cfg
)
(
cfg
,
error
)
{
var
newState
cfg
tmpFile
,
err
:=
os
.
CreateTemp
(
""
,
"config-*.yaml"
)
...
...
This diff is collapsed.
Click to expand it.
cmd/user/
delet
e.go
→
cmd/user/
remov
e.go
+
8
−
9
View file @
51d7b894
...
...
@@ -21,20 +21,18 @@ var (
WEB_TRASH
=
"/home/contas_removidas/html/"
+
ANO
)
var
Delet
eUserCmd
=
&
cobra
.
Command
{
Use
:
"
delete
"
,
var
Remov
eUserCmd
=
&
cobra
.
Command
{
Use
:
"
remove [username]
"
,
Short
:
"Delete a user"
,
RunE
:
deleteUserFunc
,
Args
:
cobra
.
ExactArgs
(
1
),
RunE
:
removeUserFunc
,
}
func
init
()
{
DeleteUserCmd
.
Flags
()
.
StringP
(
"login"
,
"l"
,
""
,
"User login for removal"
)
DeleteUserCmd
.
Flags
()
.
BoolP
(
"confirm"
,
"y"
,
false
,
"Skip confirmation prompt"
)
DeleteUserCmd
.
MarkFlagRequired
(
"login"
)
RemoveUserCmd
.
Flags
()
.
BoolP
(
"confirm"
,
"y"
,
false
,
"Skip confirmation prompt"
)
}
func
delet
eUserFunc
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
func
remov
eUserFunc
(
cmd
*
cobra
.
Command
,
args
[]
string
)
error
{
var
opts
model
.
Opts
success
:=
false
...
...
@@ -43,7 +41,8 @@ func deleteUserFunc(cmd *cobra.Command, args []string) error {
return
err
}
u
,
err
:=
locateUser
(
opts
.
UID
)
login
:=
args
[
0
]
u
,
err
:=
locateUser
(
login
)
if
err
!=
nil
{
return
err
}
...
...
This diff is collapsed.
Click to expand it.
cmd/user/show.go
+
5
−
0
View file @
51d7b894
...
...
@@ -54,6 +54,11 @@ func searchUserFunc(cmd *cobra.Command, args []string) error {
filtered
:=
searchUser
(
users
,
o
.
Ignore
,
o
.
UID
,
o
.
GID
,
o
.
Name
,
o
.
GRR
,
o
.
Status
,
o
.
Homedir
)
if
len
(
filtered
)
==
0
{
fmt
.
Printf
(
"No user matched the search!"
)
return
nil
}
for
i
:=
range
filtered
{
fmt
.
Printf
(
"%v
\n\n
"
,
filtered
[
i
]
.
ToString
())
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment