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

Commit50a42dc

Browse files
committed
Add commands for workspace providers
1 parent82f5615 commit50a42dc

File tree

12 files changed

+399
-99
lines changed

12 files changed

+399
-99
lines changed

‎.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ linters:
3939
-structcheck
4040
-stylecheck
4141
-typecheck
42-
-noctx
4342
-nolintlint
4443
-rowserrcheck
4544
-scopelint

‎coder-sdk/resourcepools.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

‎coder-sdk/workspace_providers.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package coder
2+
3+
import (
4+
"context"
5+
"net/http"
6+
7+
"golang.org/x/xerrors"
8+
)
9+
10+
// WorkspaceProvider defines an entity capable of deploying and acting as an ingress for Coder environments.
11+
typeWorkspaceProviderstruct {
12+
IDstring`json:"id" table:"-"`
13+
Namestring`json:"name" table:"Name"`
14+
StatusWorkspaceProviderStatus`json:"status" table:"Status"`
15+
Localbool`json:"local" table:"-"`
16+
ClusterAddressstring`json:"cluster_address" table:"Cluster Address"`
17+
DefaultNamespacestring`json:"default_namespace" table:"Namespace"`
18+
StorageClassstring`json:"storage_class" table:"Storage Class"`
19+
ClusterDomainSuffixstring`json:"cluster_domain_suffix" table:"Cluster Domain Suffix"`
20+
EnvproxyAccessURLstring`json:"envproxy_access_url" validate:"required" table:"Access URL"`
21+
DevurlHoststring`json:"devurl_host" table:"Devurl Host"`
22+
SSHEnabledbool`json:"ssh_enabled" table:"SSH Enabled"`
23+
NamespaceWhitelist []string`json:"namespace_whitelist" table:"Namespace Allowlist"`
24+
OrgWhitelist []string`json:"org_whitelist" table:"-"`
25+
}
26+
27+
// WorkspaceProviderStatus represents the configuration state of a workspace provider.
28+
typeWorkspaceProviderStatusstring
29+
30+
// Workspace Provider statuses.
31+
const (
32+
WorkspaceProviderPendingWorkspaceProviderStatus="pending"
33+
WorkspaceProviderReadyWorkspaceProviderStatus="ready"
34+
)
35+
36+
// WorkspaceProviderByID fetches a workspace provider entity by its unique ID.
37+
func (c*Client)WorkspaceProviderByID(ctx context.Context,idstring) (*WorkspaceProvider,error) {
38+
varwpWorkspaceProvider
39+
err:=c.requestBody(ctx,http.MethodGet,"/api/private/resource-pools/"+id,nil,&wp)
40+
iferr!=nil {
41+
returnnil,err
42+
}
43+
return&wp,nil
44+
}
45+
46+
// WorkspaceProviders fetches all workspace providers known to the Coder control plane.
47+
func (c*Client)WorkspaceProviders(ctx context.Context) ([]WorkspaceProvider,error) {
48+
varproviders []WorkspaceProvider
49+
err:=c.requestBody(ctx,http.MethodGet,"/api/private/resource-pools",nil,&providers)
50+
iferr!=nil {
51+
returnnil,err
52+
}
53+
returnproviders,nil
54+
}
55+
56+
// CreateWorkspaceProviderReq defines the request parameters for creating a new workspace provider entity.
57+
typeCreateWorkspaceProviderReqstruct {
58+
Namestring`json:"name"`
59+
}
60+
61+
// CreateWorkspaceProviderRes defines the response from creating a new workspace provider entity.
62+
typeCreateWorkspaceProviderResstruct {
63+
IDstring`json:"id"`
64+
Namestring`json:"name"`
65+
StatusWorkspaceProviderStatus`json:"status"`
66+
EnvproxyTokenstring`json:"envproxy_token"`
67+
}
68+
69+
// CreateWorkspaceProvider creates a new WorkspaceProvider entity.
70+
func (c*Client)CreateWorkspaceProvider(ctx context.Context,reqCreateWorkspaceProviderReq) (*CreateWorkspaceProviderRes,error) {
71+
varresCreateWorkspaceProviderRes
72+
err:=c.requestBody(ctx,http.MethodPost,"/api/private/resource-pools",req,&res)
73+
iferr!=nil {
74+
returnnil,err
75+
}
76+
return&res,nil
77+
}
78+
79+
// DeleteWorkspaceProviderByName deletes a workspace provider entity from the Coder control plane.
80+
func (c*Client)DeleteWorkspaceProviderByName(ctx context.Context,namestring)error {
81+
wps,err:=c.WorkspaceProviders(ctx)
82+
iferr!=nil {
83+
returnxerrors.Errorf("listing workspace providers: %w",err)
84+
}
85+
86+
varidstring
87+
for_,wp:=rangewps {
88+
ifwp.Name==name {
89+
id=wp.ID
90+
}
91+
}
92+
ifid=="" {
93+
returnxerrors.Errorf(`no workspace provider found by name "%s"`,name)
94+
}
95+
96+
returnc.requestBody(ctx,http.MethodDelete,"/api/private/resource-pools/"+id,nil,nil)
97+
}

‎docs/coder.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ coder provides a CLI for working with an existing Coder Enterprise installation
1717
*[coder images](coder_images.md) - Manage Coder images
1818
*[coder login](coder_login.md) - Authenticate this client for future operations
1919
*[coder logout](coder_logout.md) - Remove local authentication credentials if any exist
20+
*[coder providers](coder_providers.md) - Interact with Coder workspace providers
2021
*[coder sh](coder_sh.md) - Open a shell and execute commands in a Coder environment
2122
*[coder sync](coder_sync.md) - Establish a one way directory sync to a Coder environment
2223
*[coder tokens](coder_tokens.md) - manage Coder API tokens for the active user

‎docs/coder_providers.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
##coder providers
2+
3+
Interact with Coder workspace providers
4+
5+
###Synopsis
6+
7+
Perform operations on the Coder Workspace Providers for the platform.
8+
9+
###Options
10+
11+
```
12+
-h, --help help for providers
13+
```
14+
15+
###Options inherited from parent commands
16+
17+
```
18+
-v, --verbose show verbose output
19+
```
20+
21+
###SEE ALSO
22+
23+
*[coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
24+
*[coder providers create](coder_providers_create.md) - create a new workspace provider.
25+
*[coder providers ls](coder_providers_ls.md) - list workspace providers.
26+
*[coder providers rm](coder_providers_rm.md) - remove a workspace provider.
27+

‎docs/coder_providers_create.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
##coder providers create
2+
3+
create a new workspace provider.
4+
5+
###Synopsis
6+
7+
Create a new Coder workspace provider.
8+
9+
```
10+
coder providers create [workspace_provider_name] [flags]
11+
```
12+
13+
###Examples
14+
15+
```
16+
# create a new workspace provider in a pending state
17+
coder providers create my-new-workspace-provider
18+
```
19+
20+
###Options
21+
22+
```
23+
-h, --help help for create
24+
```
25+
26+
###Options inherited from parent commands
27+
28+
```
29+
-v, --verbose show verbose output
30+
```
31+
32+
###SEE ALSO
33+
34+
*[coder providers](coder_providers.md) - Interact with Coder workspace providers
35+

‎docs/coder_providers_ls.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
##coder providers ls
2+
3+
list workspace providers.
4+
5+
###Synopsis
6+
7+
List all Coder workspace providers.
8+
9+
```
10+
coder providers ls [flags]
11+
```
12+
13+
###Examples
14+
15+
```
16+
# list workspace providers
17+
coder providers ls
18+
```
19+
20+
###Options
21+
22+
```
23+
-h, --help help for ls
24+
```
25+
26+
###Options inherited from parent commands
27+
28+
```
29+
-v, --verbose show verbose output
30+
```
31+
32+
###SEE ALSO
33+
34+
*[coder providers](coder_providers.md) - Interact with Coder workspace providers
35+

‎docs/coder_providers_rm.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
##coder providers rm
2+
3+
remove a workspace provider.
4+
5+
###Synopsis
6+
7+
Remove an existing Coder workspace provider by name.
8+
9+
```
10+
coder providers rm [workspace_provider_name] [flags]
11+
```
12+
13+
###Examples
14+
15+
```
16+
# remove an existing workspace provider by name
17+
coder providers rm my-workspace-provider
18+
```
19+
20+
###Options
21+
22+
```
23+
-h, --help help for rm
24+
```
25+
26+
###Options inherited from parent commands
27+
28+
```
29+
-v, --verbose show verbose output
30+
```
31+
32+
###SEE ALSO
33+
34+
*[coder providers](coder_providers.md) - Interact with Coder workspace providers
35+

‎internal/cmd/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func Make() *cobra.Command {
3737
resourceCmd(),
3838
completionCmd(),
3939
imgsCmd(),
40+
providersCmd(),
4041
genDocsCmd(app),
4142
)
4243
app.PersistentFlags().BoolVarP(&verbose,"verbose","v",false,"show verbose output")

‎internal/cmd/configssh.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
104104
returnxerrors.New("no environments found")
105105
}
106106

107-
envsWithPools,err:=coderutil.EnvsWithPool(ctx,client,envs)
107+
envsWithProviders,err:=coderutil.EnvsWithProvider(ctx,client,envs)
108108
iferr!=nil {
109-
returnxerrors.Errorf("resolve envpools: %w",err)
109+
returnxerrors.Errorf("resolve envworkspace providers: %w",err)
110110
}
111111

112-
if!sshAvailable(envsWithPools) {
112+
if!sshAvailable(envsWithProviders) {
113113
returnxerrors.New("SSH is disabled or not available for any environments in your Coder Enterprise deployment.")
114114
}
115115

116-
newConfig:=makeNewConfigs(user.Username,envsWithPools,privateKeyFilepath)
116+
newConfig:=makeNewConfigs(user.Username,envsWithProviders,privateKeyFilepath)
117117

118118
err=os.MkdirAll(filepath.Dir(*configpath),os.ModePerm)
119119
iferr!=nil {
@@ -157,9 +157,9 @@ func removeOldConfig(config string) (string, bool) {
157157
}
158158

159159
// sshAvailable returns true if SSH is available for at least one environment.
160-
funcsshAvailable(envs []coderutil.EnvWithPool)bool {
160+
funcsshAvailable(envs []coderutil.EnvWithWorkspaceProvider)bool {
161161
for_,env:=rangeenvs {
162-
ifenv.Pool.SSHEnabled {
162+
ifenv.WorkspaceProvider.SSHEnabled {
163163
returntrue
164164
}
165165
}
@@ -174,19 +174,19 @@ func writeSSHKey(ctx context.Context, client *coder.Client, privateKeyPath strin
174174
returnioutil.WriteFile(privateKeyPath, []byte(key.PrivateKey),0600)
175175
}
176176

177-
funcmakeNewConfigs(userNamestring,envs []coderutil.EnvWithPool,privateKeyFilepathstring)string {
177+
funcmakeNewConfigs(userNamestring,envs []coderutil.EnvWithWorkspaceProvider,privateKeyFilepathstring)string {
178178
newConfig:=fmt.Sprintf("\n%s\n%s\n\n",sshStartToken,sshStartMessage)
179179
for_,env:=rangeenvs {
180-
if!env.Pool.SSHEnabled {
181-
clog.LogWarn(fmt.Sprintf("SSH is not enabled forpool%q",env.Pool.Name),
180+
if!env.WorkspaceProvider.SSHEnabled {
181+
clog.LogWarn(fmt.Sprintf("SSH is not enabled forworkspace provider%q",env.WorkspaceProvider.Name),
182182
clog.BlankLine,
183-
clog.Tipf("ask an infrastructure administrator to enable SSH for thisresource pool"),
183+
clog.Tipf("ask an infrastructure administrator to enable SSH for thisworkspace provider"),
184184
)
185185
continue
186186
}
187-
u,err:=url.Parse(env.Pool.AccessURL)
187+
u,err:=url.Parse(env.WorkspaceProvider.EnvproxyAccessURL)
188188
iferr!=nil {
189-
clog.LogWarn("invalid access url",clog.Causef("malformed url: %q",env.Pool.AccessURL))
189+
clog.LogWarn("invalid access url",clog.Causef("malformed url: %q",env.WorkspaceProvider.EnvproxyAccessURL))
190190
continue
191191
}
192192
newConfig+=makeSSHConfig(u.Host,userName,env.Env.Name,privateKeyFilepath)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp