Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
galene
Commits
5ef4bcb4
Commit
5ef4bcb4
authored
Oct 23, 2024
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement set- and delete-password.
parent
9d07dd27
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
+100
-0
galenectl/galenectl.go
galenectl/galenectl.go
+100
-0
No files found.
galenectl/galenectl.go
View file @
5ef4bcb4
...
...
@@ -12,6 +12,7 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"path/filepath"
"slices"
...
...
@@ -44,6 +45,14 @@ var commands = map[string]command{
command
:
hashPasswordCmd
,
description
:
"generate a hashed password"
,
},
"set-password"
:
{
command
:
setPasswordCmd
,
description
:
"set a user's password"
,
},
"delete-password"
:
{
command
:
deletePasswordCmd
,
description
:
"delete a user's password"
,
},
}
func
main
()
{
...
...
@@ -351,3 +360,94 @@ func deleteValue(url string) error {
}
return
nil
}
func
setPasswordCmd
(
cmdname
string
,
args
[]
string
)
{
var
groupname
string
var
algorithm
string
var
iterations
int
var
cost
int
var
length
int
var
saltlen
int
cmd
:=
flag
.
NewFlagSet
(
cmdname
,
flag
.
ExitOnError
)
setUsage
(
cmd
,
cmdname
,
"%v [option...] %v [option...] username password
\n
"
,
os
.
Args
[
0
],
cmdname
,
)
cmd
.
StringVar
(
&
groupname
,
"group"
,
""
,
"group `name`"
)
cmd
.
StringVar
(
&
algorithm
,
"hash"
,
"pbkdf2"
,
"hashing `algorithm`"
)
cmd
.
IntVar
(
&
iterations
,
"iterations"
,
4096
,
"`number` of iterations (pbkdf2)"
)
cmd
.
IntVar
(
&
cost
,
"cost"
,
bcrypt
.
DefaultCost
,
"`cost` (bcrypt)"
)
cmd
.
IntVar
(
&
length
,
"key"
,
32
,
"key `length` (pbkdf2)"
)
cmd
.
IntVar
(
&
saltlen
,
"salt"
,
8
,
"salt `length` (pbkdf2)"
)
cmd
.
Parse
(
args
)
if
cmd
.
NArg
()
!=
2
{
cmd
.
Usage
()
os
.
Exit
(
1
)
}
if
groupname
==
""
{
fmt
.
Fprintf
(
cmd
.
Output
(),
"option
\"
-group
\"
is mandatory"
)
os
.
Exit
(
1
)
}
pw
,
err
:=
makePassword
(
cmd
.
Args
()[
1
],
algorithm
,
iterations
,
length
,
saltlen
,
cost
,
)
if
err
!=
nil
{
log
.
Fatalf
(
"Make password: %v"
,
err
)
}
url
,
err
:=
url
.
JoinPath
(
serverURL
,
"/galene-api/v0/.groups"
,
groupname
,
".users"
,
cmd
.
Args
()[
0
],
".password"
,
)
if
err
!=
nil
{
log
.
Fatalf
(
"Build URL: %v"
,
err
)
}
err
=
putJSON
(
url
,
pw
,
true
)
if
err
!=
nil
{
log
.
Fatalf
(
"Set password: %v"
,
err
)
}
}
func
deletePasswordCmd
(
cmdname
string
,
args
[]
string
)
{
var
groupname
string
cmd
:=
flag
.
NewFlagSet
(
cmdname
,
flag
.
ExitOnError
)
setUsage
(
cmd
,
cmdname
,
"%v [option...] %v [option...] username
\n
"
,
os
.
Args
[
0
],
cmdname
,
)
cmd
.
StringVar
(
&
groupname
,
"group"
,
""
,
"group `name`"
)
cmd
.
Parse
(
args
)
if
cmd
.
NArg
()
!=
1
{
cmd
.
Usage
()
os
.
Exit
(
1
)
}
if
groupname
==
""
{
fmt
.
Fprintf
(
cmd
.
Output
(),
"option
\"
-group
\"
is mandatory"
)
os
.
Exit
(
1
)
}
url
,
err
:=
url
.
JoinPath
(
serverURL
,
"/galene-api/v0/.groups"
,
groupname
,
".users"
,
cmd
.
Args
()[
0
],
".password"
,
)
if
err
!=
nil
{
log
.
Fatalf
(
"Build URL: %v"
,
err
)
}
err
=
deleteValue
(
url
)
if
err
!=
nil
{
log
.
Fatalf
(
"Delete password: %v"
,
err
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment