This repository was archived by the owner on Aug 30, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork18
Cleanup and export entclient#95
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 2 additions & 2 deletionsci/integration/users_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletionsinternal/entclient/activity.go → coder-sdk/activity.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletioninternal/entclient/client.go → coder-sdk/client.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
packagecoder | ||
import ( | ||
"net/http" | ||
8 changes: 4 additions & 4 deletionsinternal/entclient/devurl.go → coder-sdk/devurl.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletionsinternal/entclient/env.go → coder-sdk/env.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletioninternal/entclient/error.go → coder-sdk/error.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
packagecoder | ||
import ( | ||
"encoding/json" | ||
9 changes: 6 additions & 3 deletionsinternal/entclient/org.go → coder-sdk/org.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletioninternal/entclient/request.go → coder-sdk/request.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
packagecoder | ||
import ( | ||
"bytes" | ||
79 changes: 79 additions & 0 deletionscoder-sdk/secrets.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package coder | ||
import ( | ||
"context" | ||
"net/http" | ||
"time" | ||
) | ||
// Secret describes a Coder secret | ||
type Secret struct { | ||
ID string `json:"id" tab:"-"` | ||
Name string `json:"name"` | ||
Value string `json:"value,omitempty"` | ||
Description string `json:"description"` | ||
CreatedAt time.Time `json:"created_at"` | ||
UpdatedAt time.Time `json:"updated_at" tab:"-"` | ||
} | ||
// Secrets gets all secrets for the given user | ||
func (c *Client) Secrets(ctx context.Context, userID string) ([]Secret, error) { | ||
var secrets []Secret | ||
err := c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets", nil, &secrets) | ||
return secrets, err | ||
} | ||
// SecretWithValueByName gets the Coder secret with its value by its name. | ||
func (c *Client) SecretWithValueByName(ctx context.Context, name, userID string) (*Secret, error) { | ||
s, err := c.SecretByName(ctx, name, userID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var secret Secret | ||
err = c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets/"+s.ID, nil, &secret) | ||
return &secret, err | ||
} | ||
// SecretWithValueByID gets the Coder secret with its value by the secret_id. | ||
func (c *Client) SecretWithValueByID(ctx context.Context, id, userID string) (*Secret, error) { | ||
var secret Secret | ||
err := c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets/"+id, nil, &secret) | ||
return &secret, err | ||
} | ||
// SecretByName gets a secret object by name | ||
func (c *Client) SecretByName(ctx context.Context, name, userID string) (*Secret, error) { | ||
secrets, err := c.Secrets(ctx, userID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, s := range secrets { | ||
if s.Name == name { | ||
return &s, nil | ||
} | ||
} | ||
return nil, ErrNotFound | ||
} | ||
// InsertSecretReq describes the request body for creating a new secret | ||
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 { | ||
var resp interface{} | ||
return c.requestBody(ctx, http.MethodPost, "/api/users/"+user.ID+"/secrets", req, &resp) | ||
} | ||
// DeleteSecretByName deletes the authenticated users secret with the given name | ||
func (c *Client) DeleteSecretByName(ctx context.Context, name, userID string) error { | ||
secret, err := c.SecretByName(ctx, name, userID) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = c.request(ctx, http.MethodDelete, "/api/users/"+userID+"/secrets/"+secret.ID, nil) | ||
return err | ||
} |
75 changes: 75 additions & 0 deletionscoder-sdk/users.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package coder | ||
import ( | ||
"context" | ||
"net/http" | ||
"time" | ||
) | ||
// User describes a Coder user account. | ||
type User struct { | ||
ID string `json:"id" tab:"-"` | ||
Email string `json:"email"` | ||
Username string `json:"username"` | ||
Name string `json:"name"` | ||
CreatedAt time.Time `json:"created_at"` | ||
UpdatedAt time.Time `json:"updated_at" tab:"-"` | ||
} | ||
// Me gets the details of the authenticated user. | ||
func (c Client) Me(ctx context.Context) (*User, error) { | ||
return c.UserByID(ctx, Me) | ||
} | ||
// UserByID get the details of a user by their id. | ||
func (c Client) UserByID(ctx context.Context, id string) (*User, error) { | ||
var u User | ||
err := c.requestBody(ctx, http.MethodGet, "/api/users/"+id, nil, &u) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &u, nil | ||
} | ||
// SSHKey describes an SSH keypair | ||
type SSHKey struct { | ||
PublicKey string `json:"public_key"` | ||
PrivateKey string `json:"private_key"` | ||
} | ||
// SSHKey gets the current SSH kepair of the authenticated user. | ||
func (c Client) SSHKey(ctx context.Context) (*SSHKey, error) { | ||
var key SSHKey | ||
err := c.requestBody(ctx, http.MethodGet, "/api/users/me/sshkey", nil, &key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &key, nil | ||
} | ||
// Users gets the list of user accounts. | ||
func (c Client) Users(ctx context.Context) ([]User, error) { | ||
var u []User | ||
err := c.requestBody(ctx, http.MethodGet, "/api/users", nil, &u) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return u, nil | ||
} | ||
// UserByEmail gets a user by email. | ||
func (c Client) UserByEmail(ctx context.Context, email string) (*User, error) { | ||
if email == Me { | ||
return c.Me(ctx) | ||
} | ||
users, err := c.Users(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, u := range users { | ||
if u.Email == email { | ||
return &u, nil | ||
} | ||
} | ||
return nil, ErrNotFound | ||
} |
6 changes: 3 additions & 3 deletionsinternal/activity/pusher.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletionsinternal/cmd/auth.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.