Skip to content

Commit

Permalink
Add a command line helper for adding users
Browse files Browse the repository at this point in the history
  • Loading branch information
zenhack committed Apr 19, 2023
1 parent 4a857fe commit 0f30fbe
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cmd/tempest-make-user/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"encoding/base64"
"flag"

"zenhack.net/go/tempest/internal/common/types"
"zenhack.net/go/tempest/internal/server/database"
"zenhack.net/go/tempest/internal/server/tokenutil"
"zenhack.net/go/util"
)

var (
typ = flag.String("type", "", "credential type to use")
scopedID = flag.String("id", "", "type-specific credential id")
roleStr = flag.String("role", string(types.RoleUser), "role the user should have")
)

func main() {
accountID := base64.RawStdEncoding.EncodeToString(tokenutil.GenToken()[:16])
flag.Parse()
role := types.Role(*roleStr)
if !role.IsValid() {
panic("Invalid role: " + role)
}

db, err := database.Open()
util.Chkfatal(err)
defer db.Close()
tx, err := db.Begin()
util.Chkfatal(err)
defer tx.Rollback()
util.Chkfatal(tx.AddAccount(database.NewAccount{
ID: accountID,
Role: role,
}))
util.Chkfatal(tx.AddCredential(database.NewCredential{
AccountID: accountID,
Login: true,
Credential: types.Credential{
Type: types.CredentialType(*typ),
ScopedID: *scopedID,
},
}))
util.Chkfatal(tx.Commit())
}
1 change: 1 addition & 0 deletions internal/make/make.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ func buildGo(r *BuildRecord) error {
}{
{"sandstorm-import-tool", false},
{"tempest", false},
{"tempest-make-user", false},
{"tempest-grain-agent", true},
{"test-app", true},
}
Expand Down

0 comments on commit 0f30fbe

Please sign in to comment.