From 532ec751dace9498982974ab267e300b3b9dd818 Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Tue, 17 Dec 2024 11:07:45 -0800 Subject: [PATCH 1/2] Update ssh issue/sign to be based on certificate template id --- packages/api/ssh/models.go | 35 ++++++++++++++++------------------- test/ssh_test.go | 38 ++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 39 deletions(-) diff --git a/packages/api/ssh/models.go b/packages/api/ssh/models.go index 843cefe..e4610c2 100644 --- a/packages/api/ssh/models.go +++ b/packages/api/ssh/models.go @@ -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 { @@ -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"` } diff --git a/test/ssh_test.go b/test/ssh_test.go index b361a36..8e0eb5c 100644 --- a/test/ssh_test.go +++ b/test/ssh_test.go @@ -1,4 +1,4 @@ -package test +// package test // import ( // "context" @@ -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) From 709c3ad4861d67351b1d88911ba402f26e46c60b Mon Sep 17 00:00:00 2001 From: Tuan Dang Date: Tue, 17 Dec 2024 11:10:42 -0800 Subject: [PATCH 2/2] Clear linter --- test/ssh_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/ssh_test.go b/test/ssh_test.go index 8e0eb5c..dd60b80 100644 --- a/test/ssh_test.go +++ b/test/ssh_test.go @@ -1,4 +1,4 @@ -// package test +package test // import ( // "context"