Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 258c918

Browse files
authored
Merge branch 'main' into jawnsy/chore-cryptorand-err-coverage
2 parents a77d5b6 + 0c005ce commit 258c918

20 files changed

+1274
-213
lines changed

Makefile

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
INSTALL_DIR=$(shell go env GOPATH)/bin
2+
GOOS=$(shell go env GOOS)
3+
GOARCH=$(shell go env GOARCH)
24

35
bin/coder:
46
mkdir -p bin
5-
go build -o bin/coder cmd/coder/main.go
7+
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o bin/coder-$(GOOS)-$(GOARCH) cmd/coder/main.go
68
.PHONY: bin/coder
79

810
bin/coderd:
911
mkdir -p bin
1012
go build -o bin/coderd cmd/coderd/main.go
1113
.PHONY: bin/coderd
1214

13-
build: site/out bin/coder bin/coderd
15+
bin/terraform-provider-coder:
16+
mkdir -p bin
17+
go build -o bin/terraform-provider-coder cmd/terraform-provider-coder/main.go
18+
.PHONY: bin/terraform-provider-coder
19+
20+
build: site/out bin/coder bin/coderd bin/terraform-provider-coder
1421
.PHONY: build
1522

1623
# Runs migrations to output a dump of the database.
@@ -59,6 +66,11 @@ install:
5966
@echo "-- CLI available at $(shell ls $(INSTALL_DIR)/coder*)"
6067
.PHONY: install
6168

69+
install/terraform-provider-coder: bin/terraform-provider-coder
70+
$(eval OS_ARCH := $(shell go env GOOS)_$(shell go env GOARCH))
71+
mkdir -p ~/.terraform.d/plugins/coder.com/internal/coder/0.2/$(OS_ARCH)
72+
cp bin/terraform-provider-coder ~/.terraform.d/plugins/coder.com/internal/coder/0.2/$(OS_ARCH)
73+
6274
peerbroker/proto: peerbroker/proto/peerbroker.proto
6375
protoc \
6476
--go_out=. \

cmd/terraform-provider-coder/main.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
5+
6+
"github.com/coder/coder/provisioner/terraform/provider"
7+
)
8+
9+
func main() {
10+
plugin.Serve(&plugin.ServeOpts{
11+
ProviderFunc: provider.New,
12+
})
13+
}

coderd/coderd.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ func New(options *Options) (http.Handler, func()) {
116116
})
117117
})
118118

119-
r.Route("/files", func(r chi.Router) {
119+
r.Route("/upload", func(r chi.Router) {
120120
r.Use(httpmw.ExtractAPIKey(options.Database, nil))
121-
r.Post("/", api.postFiles)
121+
r.Post("/", api.postUpload)
122122
})
123123

124124
r.Route("/projectimport/{organization}", func(r chi.Router) {

coderd/files.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type UploadFileResponse struct {
1818
Hash string `json:"hash"`
1919
}
2020

21-
func (api *api) postFiles(rw http.ResponseWriter, r *http.Request) {
21+
func (api *api) postUpload(rw http.ResponseWriter, r *http.Request) {
2222
apiKey := httpmw.APIKey(r)
2323
contentType := r.Header.Get("Content-Type")
2424

coderd/files_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/coder/coder/codersdk"
1111
)
1212

13-
func TestPostFiles(t *testing.T) {
13+
func TestPostUpload(t *testing.T) {
1414
t.Parallel()
1515
t.Run("BadContentType", func(t *testing.T) {
1616
t.Parallel()

coderd/provisionerdaemons.go

+10-6
Original file line numberDiff line numberDiff line change
@@ -516,16 +516,20 @@ func (server *provisionerdServer) CompleteJob(ctx context.Context, completed *pr
516516
}
517517
// This could be a bulk insert to improve performance.
518518
for _, protoResource := range jobType.WorkspaceProvision.Resources {
519+
var instanceID sql.NullString
520+
if protoResource.Agent != nil && protoResource.Agent.GetGoogleInstanceIdentity() != nil {
521+
instanceID = sql.NullString{
522+
String: protoResource.Agent.GetGoogleInstanceIdentity().InstanceId,
523+
Valid: true,
524+
}
525+
}
519526
_, err = db.InsertWorkspaceResource(ctx, database.InsertWorkspaceResourceParams{
520527
ID: uuid.New(),
521528
CreatedAt: database.Now(),
522529
WorkspaceHistoryID: input.WorkspaceHistoryID,
523-
InstanceID: sql.NullString{
524-
Valid: protoResource.InstanceId != "",
525-
String: protoResource.InstanceId,
526-
},
527-
Type: protoResource.Type,
528-
Name: protoResource.Name,
530+
Type: protoResource.Type,
531+
Name: protoResource.Name,
532+
InstanceID: instanceID,
529533
// TODO: Generate this at the variable validation phase.
530534
// Set the value in `default_source`, and disallow overwrite.
531535
WorkspaceAgentToken: uuid.NewString(),

coderd/workspaceagent_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,15 @@ func TestPostWorkspaceAgentAuthenticateGoogleInstanceIdentity(t *testing.T) {
7474
Type: &proto.Provision_Response_Complete{
7575
Complete: &proto.Provision_Complete{
7676
Resources: []*proto.Resource{{
77-
Name: "somename",
78-
Type: "someinstance",
79-
InstanceId: instanceID,
77+
Name: "somename",
78+
Type: "someinstance",
79+
Agent: &proto.Agent{
80+
Auth: &proto.Agent_GoogleInstanceIdentity{
81+
GoogleInstanceIdentity: &proto.GoogleInstanceIdentityAuth{
82+
InstanceId: instanceID,
83+
},
84+
},
85+
},
8086
}},
8187
},
8288
},

codersdk/files.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package codersdk
33
import (
44
"context"
55
"encoding/json"
6+
"fmt"
67
"net/http"
8+
"net/url"
79

810
"github.com/coder/coder/coderd"
911
)
@@ -13,7 +15,7 @@ const (
1315
)
1416

1517
func (c *Client) UploadFile(ctx context.Context, contentType string, content []byte) (coderd.UploadFileResponse, error) {
16-
res, err := c.request(ctx, http.MethodPost, "/api/v2/files", content, func(r *http.Request) {
18+
res, err := c.request(ctx, http.MethodPost, "/api/v2/upload", content, func(r *http.Request) {
1719
r.Header.Set("Content-Type", contentType)
1820
})
1921
if err != nil {
@@ -26,3 +28,8 @@ func (c *Client) UploadFile(ctx context.Context, contentType string, content []b
2628
var resp coderd.UploadFileResponse
2729
return resp, json.NewDecoder(res.Body).Decode(&resp)
2830
}
31+
32+
// DownloadURL returns the download URL for the specified asset
33+
func (c *Client) DownloadURL(asset string) (*url.URL, error) {
34+
return c.URL.Parse(fmt.Sprintf("/api/v2/downloads/%s", asset))
35+
}

go.mod

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ require (
3737
github.com/hashicorp/go-version v1.4.0
3838
github.com/hashicorp/terraform-config-inspect v0.0.0-20211115214459-90acf1ca460f
3939
github.com/hashicorp/terraform-exec v0.15.0
40+
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.1
4041
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87
4142
github.com/justinas/nosurf v1.1.1
4243
github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f
@@ -96,19 +97,35 @@ require (
9697
github.com/google/go-cmp v0.5.7 // indirect
9798
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
9899
github.com/hashicorp/errwrap v1.1.0 // indirect
100+
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
101+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
102+
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
103+
github.com/hashicorp/go-hclog v1.0.0 // indirect
99104
github.com/hashicorp/go-multierror v1.1.1 // indirect
105+
github.com/hashicorp/go-plugin v1.4.1 // indirect
106+
github.com/hashicorp/go-uuid v1.0.2 // indirect
107+
github.com/hashicorp/hc-install v0.3.1 // indirect
100108
github.com/hashicorp/hcl v1.0.0 // indirect
101109
github.com/hashicorp/hcl/v2 v2.11.1 // indirect
110+
github.com/hashicorp/logutils v1.0.0 // indirect
102111
github.com/hashicorp/terraform-json v0.13.0 // indirect
112+
github.com/hashicorp/terraform-plugin-go v0.5.0 // indirect
113+
github.com/hashicorp/terraform-plugin-log v0.2.0 // indirect
114+
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 // indirect
115+
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
103116
github.com/imdario/mergo v0.3.12 // indirect
104117
github.com/inconshreveable/mousetrap v1.0.0 // indirect
105118
github.com/juju/ansiterm v0.0.0-20210929141451-8b71cc96ebdc // indirect
106119
github.com/klauspost/compress v1.14.3 // indirect
107120
github.com/leodido/go-urn v1.2.1 // indirect
108121
github.com/lunixbochs/vtclean v1.0.0 // indirect
109122
github.com/mattn/go-colorable v0.1.12 // indirect
123+
github.com/mitchellh/copystructure v1.2.0 // indirect
124+
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
110125
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
126+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
111127
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
128+
github.com/oklog/run v1.0.0 // indirect
112129
github.com/opencontainers/go-digest v1.0.0 // indirect
113130
github.com/opencontainers/image-spec v1.0.2 // indirect
114131
github.com/opencontainers/runc v1.1.0 // indirect
@@ -129,6 +146,7 @@ require (
129146
github.com/pmezard/go-difflib v1.0.0 // indirect
130147
github.com/sirupsen/logrus v1.8.1 // indirect
131148
github.com/spf13/pflag v1.0.5 // indirect
149+
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
132150
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
133151
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
134152
github.com/xeipuuv/gojsonschema v1.2.0 // indirect

0 commit comments

Comments
 (0)