-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a command line helper for adding users
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters