Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Cleanup#179

Merged
cmoog merged 6 commits intomasterfromcleanup
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
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
15 changes: 11 additions & 4 deletionsci/steps/build.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,12 +5,13 @@ pushd() { builtin pushd "$@" >/dev/null; }
popd() { builtin popd >/dev/null; }

set -euo pipefail
cd "$(dirname "$0")"

cd "$(git rev-parse --show-toplevel)/ci/steps"

tag=$(git describe --tags)

build() {
echo "Buildingcoder-cli for $GOOS-$GOARCH..."
echo "--- buildingcoder-cli for $GOOS-$GOARCH"

tmpdir=$(mktemp -d)
go build -ldflags "-X cdr.dev/coder-cli/internal/version.Version=${tag}" -o "$tmpdir/coder" ../../cmd/coder
Expand All@@ -29,9 +30,15 @@ build() {
tar -czf "$artifact" coder
;;
"darwin")
if [[ ${CI-} ]]; then
artifact="coder-cli-$GOOS-$GOARCH.zip"
gon -log-level debug ./gon.json
mv coder.zip $artifact
else
artifact="coder-cli-$GOOS-$GOARCH.tar.gz"
tar -czf "$artifact" coder
echo "--- warning: not in ci, skipping signed release of darwin"
fi
;;
esac
popd
Expand All@@ -46,8 +53,8 @@ build() {
if [[ "$(uname)" == "Darwin" ]]; then
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 build
else
echo "Warning: Darwin builds don't work on Linux."
echo "Please use an OSX machine to build Darwin tars."
echo "--- warning: Darwin builds don't work on Linux."
echo "--- please use an OSX machine to build Darwin tars."
fi

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 build
Expand Down
3 changes: 2 additions & 1 deletionci/steps/fmt.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,8 +2,9 @@

set -euo pipefail

echo "Formatting..."
cd "$(git rev-parse --show-toplevel)"

echo "--- formatting"
go mod tidy
gofmt -w -s .
goimports -w "-local=$$(go list -m)" .
Expand Down
6 changes: 2 additions & 4 deletionsci/steps/gendocs.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,11 +2,9 @@

set -euo pipefail

echo "Generating docs..."

cd "$(dirname "$0")"
cd ../../
cd "$(git rev-parse --show-toplevel)"

echo "--- regenerating documentation"
rm -rf ./docs
mkdir ./docs
go run ./cmd/coder gen-docs ./docs
Expand Down
8 changes: 2 additions & 6 deletionsci/steps/integration.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,14 +2,10 @@

set -eo pipefail

log() {
echo "--- $@"
}

cd "$(git rev-parse --show-toplevel)"

log "building integration test image"
echo "---building integration test image"
docker build -f ./ci/integration/Dockerfile -t coder-cli-integration:latest .

log "starting integration tests"
echo "---starting integration tests"
go test ./ci/integration -count=1
5 changes: 1 addition & 4 deletionsci/steps/lint.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,10 +2,7 @@

set -euo pipefail

echo "Linting..."

cd "$(dirname "$0")"
cd ../../
cd "$(git rev-parse --show-toplevel)"

echo "--- golangci-lint"
golangci-lint run -c .golangci.yml
3 changes: 1 addition & 2 deletionsci/steps/unit_test.sh
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,5 @@ set -euo pipefail

cd "$(git rev-parse --show-toplevel)"

echo "--- go test..."

echo "--- running unit tests"
go test $(go list ./... | grep -v pkg/tcli | grep -v ci/integration | grep -v coder-sdk)
20 changes: 9 additions & 11 deletionscoder-sdk/client.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,22 +25,20 @@ type Client struct {
// WARNING: If the caller sets a custom transport to set TLS settings or a custom CA, the default
// pool will not be used and it might result in a new dns lookup/tls session/socket begin
// established each time.
func (c*Client) newHTTPClient() (*http.Client, error) {
func (c Client) newHTTPClient() (*http.Client, error) {
jar, err := cookiejar.New(nil)
if err != nil {
return nil, err
}

jar.SetCookies(c.BaseURL, []*http.Cookie{
{
Name: "session_token",
Value: c.Token,
MaxAge: 86400,
Path: "/",
HttpOnly: true,
Secure: c.BaseURL.Scheme == "https",
},
})
jar.SetCookies(c.BaseURL, []*http.Cookie{{
Name: "session_token",
Value: c.Token,
MaxAge: 86400,
Path: "/",
HttpOnly: true,
Secure: c.BaseURL.Scheme == "https",
}})

return &http.Client{Jar: jar}, nil
}
70 changes: 14 additions & 56 deletionscoder-sdk/devurl.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,75 +20,33 @@ type delDevURLRequest struct {
DevURLID string `json:"url_id"`
}

//DelDevURL deletes the specified devurl.
func (c Client)DelDevURL(ctx context.Context, envID, urlID string) error {
//DeleteDevURL deletes the specified devurl.
func (c Client)DeleteDevURL(ctx context.Context, envID, urlID string) error {
reqURL := fmt.Sprintf("/api/environments/%s/devurls/%s", envID, urlID)

resp, err := c.request(ctx, http.MethodDelete, reqURL, delDevURLRequest{
return c.requestBody(ctx, http.MethodDelete, reqURL, delDevURLRequest{
EnvID: envID,
DevURLID: urlID,
})
if err != nil {
return err
}
defer func() { _ = resp.Body.Close() }() // Best effort. Likely connection drop.

if resp.StatusCode != http.StatusOK {
return bodyError(resp)
}

return nil
}, nil)
}

type createDevURLRequest struct {
// CreateDevURLReq defines the request parameters for creating a new DevURL.
type CreateDevURLReq struct {
EnvID string `json:"environment_id"`
Port int `json:"port"`
Access string `json:"access"`
Name string `json:"name"`
}

// InsertDevURL inserts a new devurl for the authenticated user.
func (c Client) InsertDevURL(ctx context.Context, envID string, port int, name, access string) error {
reqURL := fmt.Sprintf("/api/environments/%s/devurls", envID)

resp, err := c.request(ctx, http.MethodPost, reqURL, createDevURLRequest{
EnvID: envID,
Port: port,
Access: access,
Name: name,
})
if err != nil {
return err
}
defer func() { _ = resp.Body.Close() }() // Best effort. Likely connection drop.

if resp.StatusCode != http.StatusOK {
return bodyError(resp)
}

return nil
// CreateDevURL inserts a new devurl for the authenticated user.
func (c Client) CreateDevURL(ctx context.Context, envID string, req CreateDevURLReq) error {
return c.requestBody(ctx, http.MethodPost, "/api/environments/"+envID+"/devurls", req, nil)
}

type updateDevURLRequest createDevURLRequest

// UpdateDevURL updates an existing devurl for the authenticated user.
func (c Client) UpdateDevURL(ctx context.Context, envID, urlID string, port int, name, access string) error {
reqURL := fmt.Sprintf("/api/environments/%s/devurls/%s", envID, urlID)

resp, err := c.request(ctx, http.MethodPut, reqURL, updateDevURLRequest{
EnvID: envID,
Port: port,
Access: access,
Name: name,
})
if err != nil {
return err
}
defer func() { _ = resp.Body.Close() }() // Best effort. Likefly connection drop.

if resp.StatusCode != http.StatusOK {
return bodyError(resp)
}
// PutDevURLReq defines the request parameters for overwriting a DevURL.
type PutDevURLReq CreateDevURLReq

return nil
// PutDevURL updates an existing devurl for the authenticated user.
func (c Client) PutDevURL(ctx context.Context, envID, urlID string, req PutDevURLReq) error {
return c.requestBody(ctx, http.MethodPut, "/api/environments/"+envID+"/devurls/"+urlID, req, nil)
}
14 changes: 7 additions & 7 deletionscoder-sdk/error.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,13 +17,13 @@ var ErrPermissions = xerrors.New("insufficient permissions")
// ErrAuthentication describes the error case in which the requester has invalid authentication.
var ErrAuthentication = xerrors.New("invalid authentication")

//APIError is the expected payload format for our errors.
typeAPIError struct {
ErrAPIErrorMsg `json:"error"`
//apiError is the expected payload format for our errors.
typeapiError struct {
ErrapiErrorMsg `json:"error"`
}

//APIErrorMsg contains the rich error information returned by API errors.
typeAPIErrorMsg struct {
//apiErrorMsg contains the rich error information returned by API errors.
typeapiErrorMsg struct {
Msg string `json:"msg"`
}

Expand All@@ -33,9 +33,9 @@ type HTTPError struct {
}

func (e *HTTPError) Error() string {
var msgAPIError
var msgapiError
// Try to decode the payload as an error, if it fails or if there is no error message,
// return the response URL with thedump.
// return the response URL with thestatus.
if err := json.NewDecoder(e.Response.Body).Decode(&msg); err != nil || msg.Err.Msg == "" {
return fmt.Sprintf("%s: %d %s", e.Request.URL, e.StatusCode, e.Status)
}
Expand Down
15 changes: 12 additions & 3 deletionscoder-sdk/org.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,9 +8,18 @@ import (

// Organization describes an Organization in Coder.
type Organization struct {
ID string `json:"id"`
Name string `json:"name"`
Members []OrganizationUser `json:"members"`
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Default bool `json:"default"`
Members []OrganizationUser `json:"members"`
EnvironmentCount int `json:"environment_count"`
ResourceNamespace string `json:"resource_namespace"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
AutoOffThreshold Duration `json:"auto_off_threshold"`
CPUProvisioningRate float32 `json:"cpu_provisioning_rate"`
MemoryProvisioningRate float32 `json:"memory_provisioning_rate"`
}

// OrganizationUser user wraps the basic User type and adds data specific to the user's membership of an organization.
Expand Down
30 changes: 23 additions & 7 deletionscoder-sdk/secrets.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@ import (
)

// Secret describes a Coder secret.
//
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
type Secret struct {
ID string `json:"id" table:"-"`
Name string `json:"name" table:"Name"`
Expand All@@ -17,7 +19,9 @@ type Secret struct {
}

// Secrets gets all secrets for the given user.
func (c *Client) Secrets(ctx context.Context, userID string) ([]Secret, error) {
//
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
func (c Client) Secrets(ctx context.Context, userID string) ([]Secret, error) {
var secrets []Secret
if err := c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets", nil, &secrets); err != nil {
return nil, err
Expand All@@ -26,7 +30,9 @@ func (c *Client) Secrets(ctx context.Context, userID string) ([]Secret, error) {
}

// SecretWithValueByName gets the Coder secret with its value by its name.
func (c *Client) SecretWithValueByName(ctx context.Context, name, userID string) (*Secret, error) {
//
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
func (c Client) SecretWithValueByName(ctx context.Context, name, userID string) (*Secret, error) {
// Lookup the secret from the name.
s, err := c.SecretByName(ctx, name, userID)
if err != nil {
Expand All@@ -43,7 +49,9 @@ func (c *Client) SecretWithValueByName(ctx context.Context, name, userID string)
}

// SecretWithValueByID gets the Coder secret with its value by the secret_id.
func (c *Client) SecretWithValueByID(ctx context.Context, id, userID string) (*Secret, error) {
//
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
func (c Client) SecretWithValueByID(ctx context.Context, id, userID string) (*Secret, error) {
var secret Secret
if err := c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets/"+id, nil, &secret); err != nil {
return nil, err
Expand All@@ -52,7 +60,9 @@ func (c *Client) SecretWithValueByID(ctx context.Context, id, userID string) (*S
}

// SecretByName gets a secret object by name.
func (c *Client) SecretByName(ctx context.Context, name, userID string) (*Secret, error) {
//
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
func (c Client) SecretByName(ctx context.Context, name, userID string) (*Secret, error) {
secrets, err := c.Secrets(ctx, userID)
if err != nil {
return nil, err
Expand All@@ -66,19 +76,25 @@ func (c *Client) SecretByName(ctx context.Context, name, userID string) (*Secret
}

// InsertSecretReq describes the request body for creating a new secret.
//
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
type InsertSecretReq struct {
Name string `json:"name"`
Value string `json:"value"`
Description string `json:"description"`
}

// InsertSecret adds a new secret for the authed user.
func (c *Client) InsertSecret(ctx context.Context, user *User, req InsertSecretReq) error {
return c.requestBody(ctx, http.MethodPost, "/api/users/"+user.ID+"/secrets", req, nil)
//
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
func (c Client) InsertSecret(ctx context.Context, userID string, req InsertSecretReq) error {
return c.requestBody(ctx, http.MethodPost, "/api/users/"+userID+"/secrets", req, nil)
}

// DeleteSecretByName deletes the authenticated users secret with the given name.
func (c *Client) DeleteSecretByName(ctx context.Context, name, userID string) error {
//
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
func (c Client) DeleteSecretByName(ctx context.Context, name, userID string) error {
// Lookup the secret by name to get the ID.
secret, err := c.SecretByName(ctx, name, userID)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletiondocs/coder_envs_create.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
-h, --help help for create
-i, --image string name of the image to base the environment off of.
-m, --memory float32 GB of RAM an environment should be provisioned with.
-o, --org stringID of the organization the environment should be created under.
-o, --org stringname of the organization the environment should be created under.
-t, --tag string tag of the image the environment will be based off of. (default "latest")
```

Expand Down
4 changes: 2 additions & 2 deletionsinternal/cmd/configssh.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ func configSSHCmd() *cobra.Command {
}

func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []string) error {
startToken:= "# ------------START-CODER-ENTERPRISE-----------"
conststartToken = "# ------------START-CODER-ENTERPRISE-----------"
startMessage := `# The following has been auto-generated by "coder config-ssh"
# to make accessing your Coder Enterprise environments easier.
#
Expand All@@ -46,7 +46,7 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
# coder config-ssh --remove
#
# You should not hand-edit this section, unless you are deleting it.`
endToken:= "# ------------END-CODER-ENTERPRISE------------"
constendToken = "# ------------END-CODER-ENTERPRISE------------"

return func(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
Expand Down
2 changes: 1 addition & 1 deletioninternal/cmd/envs.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -230,7 +230,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
return nil
},
}
cmd.Flags().StringVarP(&org, "org", "o", "", "ID of the organization the environment should be created under.")
cmd.Flags().StringVarP(&org, "org", "o", "", "name of the organization the environment should be created under.")
cmd.Flags().StringVarP(&tag, "tag", "t", defaultImgTag, "tag of the image the environment will be based off of.")
cmd.Flags().Float32VarP(&cpu, "cpu", "c", 0, "number of cpu cores the environment should be provisioned with.")
cmd.Flags().Float32VarP(&memory, "memory", "m", 0, "GB of RAM an environment should be provisioned with.")
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp