Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit f6bdf43

Browse files
committed
Use the workspace as username for demo repos in a shared workspace
1 parent e810f9d commit f6bdf43

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

internals/demo/init.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@ func (cmd *InitCommand) Run() error {
4949
return err
5050
}
5151

52-
me, err := client.Me().GetUser()
53-
if err != nil {
54-
return err
55-
}
56-
57-
repoPath := secretpath.Join(me.Username, defaultDemoRepo)
58-
if cmd.repo != "" {
52+
var repoPath string
53+
var username string
54+
if cmd.repo == "" {
55+
me, err := client.Me().GetUser()
56+
if err != nil {
57+
return err
58+
}
59+
username = me.Username
60+
repoPath = secretpath.Join(me.Username, defaultDemoRepo)
61+
} else {
62+
username = secretpath.Namespace(cmd.repo.Value())
5963
repoPath = cmd.repo.Value()
6064
}
6165

@@ -66,13 +70,13 @@ func (cmd *InitCommand) Run() error {
6670
return err
6771
}
6872

69-
_, err = client.Secrets().Write(secretpath.Join(repoPath, "username"), []byte(me.Username))
73+
_, err = client.Secrets().Write(secretpath.Join(repoPath, "username"), []byte(username))
7074
if err != nil {
7175
return err
7276
}
7377

7478
h := hmac.New(sha256.New, []byte("this-is-no-good-way-to-generate-a-password-that-is-why-we-only-use-it-for-demo-purposes"))
75-
password := base64.RawStdEncoding.EncodeToString(h.Sum([]byte(me.Username)))[:20]
79+
password := base64.RawStdEncoding.EncodeToString(h.Sum([]byte(username)))[:20]
7680

7781
_, err = client.Secrets().Write(secretpath.Join(repoPath, "password"), []byte(password))
7882
if err != nil {

0 commit comments

Comments
 (0)