ソースを参照

create saml integration in DB

Mohammed Nafees 3 年 前
コミット
5ca4a7a481

+ 1 - 1
api/server/handlers/saml/create_integration.go

@@ -73,7 +73,7 @@ func (h *CreateSAMLIntegrationHandler) ServeHTTP(w http.ResponseWriter, r *http.
 		ProjectID:       project.ID,
 		Domains:         strings.Join(request.Domains, ","),
 		SignOnURL:       request.SignOnURL,
-		CertificateData: request.CertificateData,
+		CertificateData: []byte(request.CertificateData),
 	}
 
 	if _, err := h.Repo().SAMLIntegration().CreateSAMLIntegration(integ); err != nil {

+ 2 - 2
api/types/saml.go

@@ -11,8 +11,8 @@ type ValidateSAMLRequest struct {
 }
 
 type CreateSAMLIntegrationRequest struct {
-	Domains         []string `json:"domains" form:"required,fqdn"`
+	Domains         []string `json:"domains" form:"required"`
 	Type            IDPType  `json:"type" form:"required,oneof=okta"`
 	SignOnURL       string   `json:"sign_on_url" form:"required,url"`
-	CertificateData []byte   `json:"certificate_data" form:"required"`
+	CertificateData string   `json:"certificate_data" form:"required"`
 }

+ 10 - 0
ee/integrations/vault/types.go

@@ -69,6 +69,16 @@ type GetGitlabCredentialData struct {
 	Data     *credentials.GitlabCredential `json:"data"`
 }
 
+type GetSAMLCredentialResponse struct {
+	*VaultGetResponse
+	Data *GetSAMLCredentialData `json:"data"`
+}
+
+type GetSAMLCredentialData struct {
+	Metadata *VaultMetadata              `json:"metadata"`
+	Data     *credentials.SAMLCredential `json:"data"`
+}
+
 type CreatePolicyRequest struct {
 	Policy string `json:"policy"`
 }

+ 6 - 6
ee/integrations/vault/vault.go

@@ -222,7 +222,7 @@ func (c *Client) getGitlabCredentialPath(giIntegration *integrations.GitlabInteg
 	)
 }
 
-func (c *Client) WriteSAMLCredential(samlIntegration *saml.SAMLIntegration, data *credentials.GitlabCredential) error {
+func (c *Client) WriteSAMLCredential(samlIntegration *saml.SAMLIntegration, data *credentials.SAMLCredential) error {
 	reqData := &CreateVaultSecretRequest{
 		Data: data,
 	}
@@ -231,7 +231,7 @@ func (c *Client) WriteSAMLCredential(samlIntegration *saml.SAMLIntegration, data
 }
 
 func (c *Client) GetSAMLCredential(samlIntegration *saml.SAMLIntegration) (*credentials.SAMLCredential, error) {
-	resp := &GetGitlabCredentialResponse{}
+	resp := &GetSAMLCredentialResponse{}
 
 	err := c.getRequest(fmt.Sprintf("/v1/%s", c.getSAMLCredentialPath(samlIntegration)), resp)
 
@@ -242,12 +242,12 @@ func (c *Client) GetSAMLCredential(samlIntegration *saml.SAMLIntegration) (*cred
 	return resp.Data.Data, nil
 }
 
-func (c *Client) getSAMLCredentialPath(giIntegration *integrations.GitlabIntegration) string {
+func (c *Client) getSAMLCredentialPath(samlIntegration *saml.SAMLIntegration) string {
 	return fmt.Sprintf(
-		"kv/data/secret/%s/%d/gitlab/%d",
+		"kv/data/secret/%s/%d/saml/%d",
 		c.secretPrefix,
-		giIntegration.ProjectID,
-		giIntegration.ID,
+		samlIntegration.ProjectID,
+		samlIntegration.ID,
 	)
 }
 

+ 4 - 0
internal/repository/gorm/saml.go

@@ -37,5 +37,9 @@ func (repo *SAMLIntegrationRepository) ValidateSAMLIntegration(domain string) (*
 }
 
 func (repo *SAMLIntegrationRepository) CreateSAMLIntegration(integ *saml.SAMLIntegration) (*saml.SAMLIntegration, error) {
+	if err := repo.db.Create(integ).Error; err != nil {
+		return nil, err
+	}
+
 	return nil, nil
 }