Skip to content

Commit

Permalink
Merge pull request #25 from Infisical/ssh-cert
Browse files Browse the repository at this point in the history
Update ssh issue/sign to be based on certificate template id
  • Loading branch information
dangtony98 authored Dec 17, 2024
2 parents 318b41b + 709c3ad commit b048537
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
35 changes: 16 additions & 19 deletions packages/api/ssh/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import (
)

type SignSshPublicKeyV1Request struct {
ProjectID string `json:"projectId"`
TemplateName string `json:"templateName"`
PublicKey string `json:"publicKey"`
KeyAlgorithm util.CertKeyAlgorithm `json:"keyAlgorithm,omitempty"`
CertType util.SshCertType `json:"certType,omitempty"`
Principals []string `json:"principals"`
TTL string `json:"ttl,omitempty"`
KeyID string `json:"keyId,omitempty"`
CertificateTemplateID string `json:"certificateTemplateId"`
PublicKey string `json:"publicKey"`
CertType util.SshCertType `json:"certType,omitempty"`
Principals []string `json:"principals"`
TTL string `json:"ttl,omitempty"`
KeyID string `json:"keyId,omitempty"`
}

type SignSshPublicKeyV1Response struct {
Expand All @@ -21,19 +19,18 @@ type SignSshPublicKeyV1Response struct {
}

type IssueSshCredsV1Request struct {
ProjectID string `json:"projectId"`
TemplateName string `json:"templateName"`
KeyAlgorithm util.CertKeyAlgorithm `json:"keyAlgorithm,omitempty"`
CertType util.SshCertType `json:"certType,omitempty"`
Principals []string `json:"principals"`
TTL string `json:"ttl,omitempty"`
KeyID string `json:"keyId,omitempty"`
CertificateTemplateID string `json:"certificateTemplateId"`
KeyAlgorithm util.CertKeyAlgorithm `json:"keyAlgorithm,omitempty"`
CertType util.SshCertType `json:"certType,omitempty"`
Principals []string `json:"principals"`
TTL string `json:"ttl,omitempty"`
KeyID string `json:"keyId,omitempty"`
}

type IssueSshCredsV1Response struct {
SerialNumber string `json:"serialNumber"`
SignedKey string `json:"signedKey"`
PrivateKey string `json:"privateKey"`
PublicKey string `json:"publicKey"`
SerialNumber string `json:"serialNumber"`
SignedKey string `json:"signedKey"`
PrivateKey string `json:"privateKey"`
PublicKey string `json:"publicKey"`
KeyAlgorithm util.CertKeyAlgorithm `json:"keyAlgorithm"`
}
36 changes: 17 additions & 19 deletions test/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,37 @@ package test

// func TestSshIssueCreds(t *testing.T) {
// client := infisical.NewInfisicalClient(context.Background(), infisical.Config{
// SiteUrl: "http://localhost:8080",
// AutoTokenRefresh: true,
// })
// SiteUrl: "http://localhost:8080",
// AutoTokenRefresh: true,
// })

// // Authenticate using Universal Auth
// _, err := client.Auth().UniversalAuthLogin(os.Getenv("GO_SDK_TEST_UNIVERSAL_AUTH_CLIENT_ID"), os.Getenv("GO_SDK_TEST_UNIVERSAL_AUTH_CLIENT_SECRET"))
// if err != nil {
// fmt.Printf("Authentication failed: %v\n", err)
// os.Exit(1)
// }
// _, err := client.Auth().UniversalAuthLogin("", "")
// if err != nil {
// fmt.Printf("Authentication failed: %v\n", err)
// os.Exit(1)
// }

// // Test issuing SSH credentials
// creds, err := client.Ssh().IssueCredentials(infisical.IssueSshCredsOptions{
// ProjectID: os.Getenv("GO_SDK_TEST_PROJECT_ID"),
// TemplateName: "template-name",
// Principals: []string{"ec2-user"},
// CertificateTemplateID: "",
// Principals: []string{"ec2-user"},
// })

// if err != nil {
// if err != nil {
// t.Fatalf("Failed to issue SSH credentials: %v", err)
// }
// }

// // Test signing SSH public key
// creds2, err := client.Ssh().SignKey(infisical.SignSshPublicKeyOptions{
// ProjectID: os.Getenv("GO_SDK_TEST_PROJECT_ID"),
// TemplateName: "template-name",
// Principals: []string{"ec2-user"},
// PublicKey: "ssh-rsa ...",
// CertificateTemplateID: "",
// Principals: []string{"ec2-user"},
// PublicKey: "ssh-rsa ...",
// })

// if err != nil {
// if err != nil {
// t.Fatalf("Failed to sign SSH public key: %v", err)
// }
// }

// fmt.Print("Newly-issued SSH credentials: ", creds)
// fmt.Print("Signed SSH credential: ", creds2)
Expand Down

0 comments on commit b048537

Please sign in to comment.