-
Notifications
You must be signed in to change notification settings - Fork 894
fix(enterprise/cli): correctly set default tags for PSK auth #9436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
95b51ed
fix(provisionerd): correctly mutate default tags for PSK auth
johnstcn 4fda818
address PR comments
johnstcn 79717aa
ignore error log in test
johnstcn 89030f2
do not log context.Canceled errors
johnstcn 3e1a94b
address PR comment
johnstcn 34ef0a7
unconditionally set tag scope to org for psk auth
johnstcn 475311a
cli: add some informational logging statements around provisionerd tags
johnstcn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,80 @@ | ||
package provisionerdserver_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/coder/coder/v2/coderd/provisionerdserver" | ||
) | ||
|
||
func TestMutateTags(t *testing.T) { | ||
t.Parallel() | ||
|
||
testUserID := uuid.New() | ||
|
||
for _, tt := range []struct { | ||
name string | ||
userID uuid.UUID | ||
tags map[string]string | ||
want map[string]string | ||
}{ | ||
{ | ||
name: "nil tags", | ||
userID: uuid.Nil, | ||
tags: nil, | ||
want: map[string]string{ | ||
provisionerdserver.TagScope: provisionerdserver.ScopeOrganization, | ||
}, | ||
}, | ||
{ | ||
name: "empty tags", | ||
userID: uuid.Nil, | ||
tags: map[string]string{}, | ||
want: map[string]string{ | ||
provisionerdserver.TagScope: provisionerdserver.ScopeOrganization, | ||
}, | ||
}, | ||
{ | ||
name: "user scope", | ||
tags: map[string]string{provisionerdserver.TagScope: provisionerdserver.ScopeUser}, | ||
userID: testUserID, | ||
want: map[string]string{ | ||
provisionerdserver.TagScope: provisionerdserver.ScopeUser, | ||
provisionerdserver.TagOwner: testUserID.String(), | ||
}, | ||
}, | ||
{ | ||
name: "organization scope", | ||
tags: map[string]string{provisionerdserver.TagScope: provisionerdserver.ScopeOrganization}, | ||
userID: testUserID, | ||
want: map[string]string{ | ||
provisionerdserver.TagScope: provisionerdserver.ScopeOrganization, | ||
}, | ||
}, | ||
{ | ||
name: "invalid scope", | ||
tags: map[string]string{provisionerdserver.TagScope: "360noscope"}, | ||
userID: testUserID, | ||
want: map[string]string{ | ||
provisionerdserver.TagScope: provisionerdserver.ScopeOrganization, | ||
}, | ||
}, | ||
} { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
// make a copy of the map because the function under test | ||
// mutates the map | ||
bytes, err := json.Marshal(tt.tags) | ||
require.NoError(t, err) | ||
var tags map[string]string | ||
err = json.Unmarshal(bytes, &tags) | ||
require.NoError(t, err) | ||
got := provisionerdserver.MutateTags(tt.userID, tags) | ||
require.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -83,6 +83,9 @@ func (r *RootCmd) provisionerDaemonStart() *clibase.Cmd { | |
}() | ||
|
||
logger := slog.Make(sloghuman.Sink(inv.Stderr)) | ||
if ok, _ := inv.ParsedFlags().GetBool("verbose"); ok { | ||
logger = logger.Leveled(slog.LevelDebug) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
errCh := make(chan error, 1) | ||
go func() { | ||
defer cancel() | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.