Skip to content

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 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 21 commits into from
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix requested changes
  • Loading branch information
kylecarbs committed Feb 12, 2022
commit c6cee947fd78f47ec82c74972ff48a4217cff2a4
1 change: 1 addition & 0 deletions cli/clitest/clitest.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

var (
// Used to ensure terminal output doesn't have anything crazy!
// See: https://stackoverflow.com/a/29497680
stripAnsi = regexp.MustCompile("[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))")
)

Expand Down
1 change: 0 additions & 1 deletion cli/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func projects() *cobra.Command {
cmd := &cobra.Command{
Use: "projects",
Aliases: []string{"project"},
Long: "Testing something",
Example: `
- Create a project for developers to create workspaces

Expand Down
3 changes: 2 additions & 1 deletion cli/workspacecreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ func workspaceCreate() *cobra.Command {
_, _ = fmt.Printf("Terraform: %s\n", log.Output)
}

_, _ = fmt.Printf("Created workspace! %s\n", name)
// This command is WIP, and output will change!

_, _ = fmt.Printf("Created workspace! %s\n", name)
return nil
},
}
Expand Down
14 changes: 12 additions & 2 deletions coderd/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,18 @@ func (api *api) postFiles(rw http.ResponseWriter, r *http.Request) {
return
}
hashBytes := sha256.Sum256(data)
file, err := api.Database.InsertFile(r.Context(), database.InsertFileParams{
Hash: hex.EncodeToString(hashBytes[:]),
hash := hex.EncodeToString(hashBytes[:])
file, err := api.Database.GetFileByHash(r.Context(), hash)
if err == nil {
// The file already exists!
render.Status(r, http.StatusOK)
render.JSON(rw, r, UploadFileResponse{
Hash: file.Hash,
})
return
}
file, err = api.Database.InsertFile(r.Context(), database.InsertFileParams{
Hash: hash,
CreatedBy: apiKey.UserID,
CreatedAt: database.Now(),
Mimetype: contentType,
Expand Down
11 changes: 11 additions & 0 deletions coderd/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ func TestPostFiles(t *testing.T) {
_, err := client.UploadFile(context.Background(), codersdk.ContentTypeTar, make([]byte, 1024))
require.NoError(t, err)
})

t.Run("InsertAlreadyExists", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t)
_ = coderdtest.CreateInitialUser(t, client)
data := make([]byte, 1024)
_, err := client.UploadFile(context.Background(), codersdk.ContentTypeTar, data)
require.NoError(t, err)
_, err = client.UploadFile(context.Background(), codersdk.ContentTypeTar, data)
require.NoError(t, err)
})
}
2 changes: 1 addition & 1 deletion coderd/parameter/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Compute(ctx context.Context, db database.Store, scope ComputeScope, options
continue
}
if _, ok := compute.computedParameterByName[parameterSchema.Name]; ok {
// We already have a value! No need to use th default.
// We already have a value! No need to use the default.
continue
}

Expand Down
1 change: 0 additions & 1 deletion coderd/provisionerjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ func (api *api) provisionerJobLogsByID(rw http.ResponseWriter, r *http.Request)
})
if errors.Is(err, sql.ErrNoRows) {
err = nil
provisionerJobLogs = []database.ProvisionerJobLog{}
}
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
Expand Down
2 changes: 1 addition & 1 deletion codersdk/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (c *Client) UploadFile(ctx context.Context, contentType string, content []b
return coderd.UploadFileResponse{}, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusCreated {
if res.StatusCode != http.StatusCreated && res.StatusCode != http.StatusOK {
return coderd.UploadFileResponse{}, readBodyAsError(res)
}
var resp coderd.UploadFileResponse
Expand Down