- Notifications
You must be signed in to change notification settings - Fork1k
feat: Add "coder projects create" command#246
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
codecovbot commentedFeb 11, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
@@ Coverage Diff @@## main #246 +/- ##==========================================+ Coverage 67.24% 68.33% +1.08%========================================== Files 124 126 +2 Lines 6516 6898 +382 Branches 69 69 ==========================================+ Hits 4382 4714 +332+ Misses 1712 1707 -5- Partials 422 477 +55
Continue to review full report at Codecov.
|
"github.com/coder/coder/cli" | ||
"github.com/coder/coder/cli/config" | ||
"github.com/coder/coder/codersdk" | ||
"github.com/coder/coder/provisioner/echo" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Neat 🎉
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
// Validates and computes the value for parameters; setting the value on "parameterByName". | ||
func (c*compute)injectScope(ctx context.Context,scopeParams database.GetParameterValuesByScopeParams)error { | ||
scopedParameters,err:=c.db.GetParameterValuesByScope(ctx,scopeParams) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I wonder ifscopedParameters
can benull
if there is asql.ErrNoRows
, like we saw with projects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It can be, but in Go you can iterate over a nil array without issue!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
} | ||
require.NoError(t,err) | ||
// #nosec | ||
path:=filepath.Join(directory,header.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I wonder if we should have a check here to sanitize theheader.Name
- making sure we can't specify paths like..
that might move up the filesystem. There might be a vulnerability where you could construct atar
that has a header with improper paths (like../../
) - and let you write a file over an existing file.
This would be bad, for example, if a malicious actor could write over a critical config file, a binary (ie, they overwrite ourprovisionerd
with a malicious version that uploads secrets).
Kind of a similar to the example called out here:securego/gosec#439 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yes, and we handle this from provisionerd. But I didn't feel it was necessary forclitest
.
We should abstract the tar/untar logic out so it's in one place, then add tests for that specific functionality.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks good to me overall - I had onesecurity concern and a few small nits.
Looking forward to having this in so we can have the end-to-end flow going next week!
funcprojectCreate()*cobra.Command { | ||
return&cobra.Command{ | ||
var ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'd propose structuring these commands ascoder <verb> <subject>
similar tokubectl
. When you demoed this command to me, that was what you had typed the first time, too, suggesting that it feels more "natural" - it also reads better that way, in my opinion.
For example:coder create project
The nice thing aboutkubectl
is that most of the commands follow an identical pattern, sokubectl get pods
,kubectl get deployments
etc feel natural. Putting the verb after makes it more likely that they will diverge, which is always unexpected (e.g. cases wherekubectl project create
is a valid command butkubectl workspace create
is not)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
That is a significantly more human approach. I'm trying to think of edge-cases in which that won't work, but I'm yet to find any!
Maybe discoverability would be hurt? eg. adding the root verb for a bespoke action a specific resource has could get really messy. I'm not sure how frequently we'll need to do that though.ssh
andplan
are the only odd ones I can think of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
kubectl hasexec
andlogs
and a few other commands that don't follow the pattern, so we could havecoder ssh <workspace>
orcoder plan <workspace>
(if we anticipate that there will be other things we'll need to SSH into, we could also docoder ssh workspace <workspace>
or similar, of course - we don't have to implementcoder ssh project
, since that doesn't make much sense)
Thinking about it now, one reason thecoder create
pattern might be helpful is because of persistent flags.kubectl
has a--file
flag that applies to allcreate
verbs, so you can implement it as a persistent flag oncreate
. On the other hand, if we have separatecreate
leaf commands, then we'd have to make sure we consistently implement--file
for everything individually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We can also always make these changes after merging this PR, it's not urgent, but would be nice to do it before we publish things, because then we're on the hook to maintain stability of the interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We lose specificity and customization in output when we standardize using verbs first. eg. it'd be a bit weird for a user to run:
coder describe workspacetest
and expect the same visual output as
coder describe usertest
Maybe it's good to force us down a consistency route there though.
As you mentioned, we can polish this later. It's definitely a nice standardization forcing-function that provides consistency to our CLI experience!
} | ||
_,err=runPrompt(cmd,&promptui.Prompt{ | ||
_,err=prompt(cmd,&promptui.Prompt{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
is there an easy way to run this noninteractively, as in a script? for examplecoder project create abc --org Coder --create-workspace=true
I'd suggest inverting this logic and assuming noninteractive mode, unless the user types-i
or--interactive
, as the noninteractive mode is usually more common for CLI commands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I wanted to map out the user experience before making it non-interactive. It should work how you mentioned. With flags that allow the prompts to be bypassed.
Is defaulting to interactive bad if we detect a TTY? I'm not sure if it's expected, but it would be cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yeah, I think the best argument against making it non-interactive by default is the principle of least astonishment, that most tools don't do that. But there are examples of tools that do default to doing things interactive, likenpm init
- so we could just merge this as-is and see what it feels like
One thing I think would be useful, though, is to make sure we're testing a non-interactive use case, ideally as part of our test suite, since that will likely be something people will want (and that people are already doing with v1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Entirely agree!
No description provided.