@ -15,11 +15,17 @@ using a key stored with the local SSH Agent (using an [`SSHAgentSigner`][6].
To construct a Signer, use the `New*` range of methods in the `authentication`
To construct a Signer, use the `New*` range of methods in the `authentication`
package. In the case of `authentication.NewSSHAgentSigner` , the parameters are
package. In the case of `authentication.NewSSHAgentSigner` , the parameters are
the fingerprint of the key with which to sign, and the account name (normally
the fingerprint of the key with which to sign, and the account name (normally
stored in the `SDC_ACCOUNT` environment variable). For example:
stored in the `TRITON_ACCOUNT` environment variable). There is also support for
passing in a username, this will allow you to use an account other than the main
Triton account. For example:
```
```go
const fingerprint := "a4:c6:f3:75:80:27:e0:03:a9:98:79:ef:c5:0a:06:11"
input := authentication.SSHAgentSignerInput{
sshKeySigner, err := authentication.NewSSHAgentSigner(fingerprint, "AccountName")
KeyID: "a4:c6:f3:75:80:27:e0:03:a9:98:79:ef:c5:0a:06:11",
AccountName: "AccountName",
Username: "Username",
}
sshKeySigner, err := authentication.NewSSHAgentSigner(input)
if err != nil {
if err != nil {
log.Fatalf("NewSSHAgentSigner: %s", err)
log.Fatalf("NewSSHAgentSigner: %s", err)
}
}
@ -36,17 +42,18 @@ their own seperate client. In order to initialize a package client, simply pass
the global `triton.ClientConfig` struct into the client's constructor function.
the global `triton.ClientConfig` struct into the client's constructor function.
```go
```go
config := & triton.ClientConfig{
config := & triton.ClientConfig{
TritonURL: os.Getenv("SDC_URL"),
TritonURL: os.Getenv("TRITON_URL"),
MantaURL: os.Getenv("MANTA_URL"),
MantaURL: os.Getenv("MANTA_URL"),
AccountName: accountName,
AccountName: accountName,
Signers: []authentication.Signer{sshKeySigner},
Username: os.Getenv("TRITON_USER"),
}
Signers: []authentication.Signer{sshKeySigner},
}
c, err := compute.NewClient(config)
c, err := compute.NewClient(config)
if err != nil {
if err != nil {
log.Fatalf("compute.NewClient: %s", err)
log.Fatalf("compute.NewClient: %s", err)
}
}
```
```
Constructing `compute.Client` returns an interface which exposes `compute` API
Constructing `compute.Client` returns an interface which exposes `compute` API
@ -57,10 +64,10 @@ The same `triton.ClientConfig` will initialize the Manta `storage` client as
well...
well...
```go
```go
c, err := storage.NewClient(config)
c, err := storage.NewClient(config)
if err != nil {
if err != nil {
log.Fatalf("storage.NewClient: %s", err)
log.Fatalf("storage.NewClient: %s", err)
}
}
```
```
## Error Handling
## Error Handling
@ -81,13 +88,14 @@ set:
- `TRITON_TEST` - must be set to any value in order to indicate desire to create
- `TRITON_TEST` - must be set to any value in order to indicate desire to create
resources
resources
- `SDC _URL` - the base endpoint for the Triton API
- `TRITON _URL` - the base endpoint for the Triton API
- `SDC _ACCOUNT` - the account name for the Triton API
- `TRITON _ACCOUNT` - the account name for the Triton API
- `SDC _KEY_ID` - the fingerprint of the SSH key identifying the key
- `TRITON _KEY_ID` - the fingerprint of the SSH key identifying the key
Additionally, you may set `SDC _KEY_MATERIAL` to the contents of an unencrypted
Additionally, you may set `TRITON _KEY_MATERIAL` to the contents of an unencrypted
private key. If this is set, the PrivateKeySigner (see above) will be used - if
private key. If this is set, the PrivateKeySigner (see above) will be used - if
not the SSHAgentSigner will be used.
not the SSHAgentSigner will be used. You can also set `TRITON_USER` to run the tests
against an account other than the main Triton account
### Example Run
### Example Run
@ -96,9 +104,9 @@ The verbose output has been removed for brevity here.
```
```
$ HTTP_PROXY=http://localhost:8888 \
$ HTTP_PROXY=http://localhost:8888 \
TRITON_TEST=1 \
TRITON_TEST=1 \
SDC _URL=https://us-sw-1.api.joyent.com \
TRITON _URL=https://us-sw-1.api.joyent.com \
SDC _ACCOUNT=AccountName \
TRITON _ACCOUNT=AccountName \
SDC _KEY_ID=a4:c6:f3:75:80:27:e0:03:a9:98:79:ef:c5:0a:06:11 \
TRITON _KEY_ID=a4:c6:f3:75:80:27:e0:03:a9:98:79:ef:c5:0a:06:11 \
go test -v -run "TestAccKey"
go test -v -run "TestAccKey"
=== RUN TestAccKey_Create
=== RUN TestAccKey_Create
--- PASS: TestAccKey_Create (12.46s)
--- PASS: TestAccKey_Create (12.46s)
@ -118,7 +126,7 @@ referencing your SSH key file use by your active `triton` CLI profile.
```sh
```sh
$ eval "$(triton env us-sw-1)"
$ eval "$(triton env us-sw-1)"
$ SDC _KEY_FILE=~/.ssh/triton-id_rsa go run examples/compute/instances.go
$ TRITON _KEY_FILE=~/.ssh/triton-id_rsa go run examples/compute/instances.go
```
```
The following is a complete example of how to initialize the `compute` package
The following is a complete example of how to initialize the `compute` package
@ -144,15 +152,21 @@ import (
)
)
func main() {
func main() {
keyID := os.Getenv("SDC_KEY_ID")
keyID := os.Getenv("TRITON_KEY_ID")
accountName := os.Getenv("SDC_ACCOUNT")
accountName := os.Getenv("TRITON_ACCOUNT")
keyMaterial := os.Getenv("SDC_KEY_MATERIAL")
keyMaterial := os.Getenv("TRITON_KEY_MATERIAL")
userName := os.Getenv("TRITON_USER")
var signer authentication.Signer
var signer authentication.Signer
var err error
var err error
if keyMaterial == "" {
if keyMaterial == "" {
signer, err = authentication.NewSSHAgentSigner(keyID, accountName)
input := authentication.SSHAgentSignerInput{
KeyID: keyID,
AccountName: accountName,
Username: userName,
}
signer, err = authentication.NewSSHAgentSigner(input)
if err != nil {
if err != nil {
log.Fatalf("Error Creating SSH Agent Signer: {{err}}", err)
log.Fatalf("Error Creating SSH Agent Signer: {{err}}", err)
}
}
@ -180,15 +194,22 @@ func main() {
keyBytes = []byte(keyMaterial)
keyBytes = []byte(keyMaterial)
}
}
signer, err = authentication.NewPrivateKeySigner(keyID, []byte(keyMaterial), accountName)
input := authentication.PrivateKeySignerInput{
KeyID: keyID,
PrivateKeyMaterial: keyBytes,
AccountName: accountName,
Username: userName,
}
signer, err = authentication.NewPrivateKeySigner(input)
if err != nil {
if err != nil {
log.Fatalf("Error Creating SSH Private Key Signer: {{err}}", err)
log.Fatalf("Error Creating SSH Private Key Signer: {{err}}", err)
}
}
}
}
config := & triton.ClientConfig{
config := & triton.ClientConfig{
TritonURL: os.Getenv("SDC _URL"),
TritonURL: os.Getenv("TRITON _URL"),
AccountName: accountName,
AccountName: accountName,
Username: userName,
Signers: []authentication.Signer{signer},
Signers: []authentication.Signer{signer},
}
}