Pārlūkot izejas kodu

add vault credential structs

Mohammed Nafees 3 gadi atpakaļ
vecāks
revīzija
b144dded6e

+ 30 - 0
ee/integrations/vault/vault.go

@@ -13,6 +13,7 @@ import (
 	"time"
 
 	"github.com/porter-dev/porter/internal/models/integrations"
+	"github.com/porter-dev/porter/internal/models/saml"
 	"github.com/porter-dev/porter/internal/repository/credentials"
 )
 
@@ -221,6 +222,35 @@ func (c *Client) getGitlabCredentialPath(giIntegration *integrations.GitlabInteg
 	)
 }
 
+func (c *Client) WriteSAMLCredential(samlIntegration *saml.SAMLIntegration, data *credentials.GitlabCredential) error {
+	reqData := &CreateVaultSecretRequest{
+		Data: data,
+	}
+
+	return c.postRequest(fmt.Sprintf("/v1/%s", c.getSAMLCredentialPath(samlIntegration)), reqData, nil)
+}
+
+func (c *Client) GetSAMLCredential(samlIntegration *saml.SAMLIntegration) (*credentials.SAMLCredential, error) {
+	resp := &GetGitlabCredentialResponse{}
+
+	err := c.getRequest(fmt.Sprintf("/v1/%s", c.getSAMLCredentialPath(samlIntegration)), resp)
+
+	if err != nil {
+		return nil, err
+	}
+
+	return resp.Data.Data, nil
+}
+
+func (c *Client) getSAMLCredentialPath(giIntegration *integrations.GitlabIntegration) string {
+	return fmt.Sprintf(
+		"kv/data/secret/%s/%d/gitlab/%d",
+		c.secretPrefix,
+		giIntegration.ProjectID,
+		giIntegration.ID,
+	)
+}
+
 const readOnlyPolicyTemplate = `path "%s" {
   capabilities = ["read"]
 }`

+ 7 - 4
internal/repository/credentials/credentials.go

@@ -1,6 +1,9 @@
 package credentials
 
-import "github.com/porter-dev/porter/internal/models/integrations"
+import (
+	"github.com/porter-dev/porter/internal/models/integrations"
+	"github.com/porter-dev/porter/internal/models/saml"
+)
 
 type OAuthCredential struct {
 	// The ID issued to the client
@@ -63,8 +66,7 @@ type GitlabCredential struct {
 }
 
 type SAMLCredential struct {
-	AppClientID     []byte `json:"app_client_id"`
-	AppClientSecret []byte `json:"app_client_secret"`
+	CertificateData []byte `json:"certificate_data"`
 }
 
 type CredentialStorage interface {
@@ -94,5 +96,6 @@ type CredentialStorage interface {
 	CreateGitlabToken(giIntegration *integrations.GitlabIntegration) (string, error)
 
 	// SAML
-
+	WriteSAMLCredential(samlIntegration *saml.SAMLIntegration, data *SAMLCredential) error
+	GetSAMLCredential(samlIntegration *saml.SAMLIntegration) (*SAMLCredential, error)
 }