This repository has been archived by the owner on Mar 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
/
storeIDP.go
99 lines (75 loc) · 4.27 KB
/
storeIDP.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package uidp
import (
"github.com/seknox/trasa/server/models"
logger "github.com/sirupsen/logrus"
)
// GetAllIdps retrieves all idps configured for organization
func (s idpStore) GetAllIdps(orgID string) ([]models.IdentityProvider, error) {
var idps []models.IdentityProvider = make([]models.IdentityProvider, 0)
var idp models.IdentityProvider
rows, err := s.DB.Query("SELECT id, org_id, name,type, meta, is_enabled, redirect_url, audience_uri, client_id, endpoint, created_by , last_updated, scim_endpoint FROM idp WHERE org_id = $1", orgID)
if err != nil {
return idps, err
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&idp.IdpID, &idp.OrgID, &idp.IdpName, &idp.IdpType, &idp.IdpMeta, &idp.IsEnabled, &idp.RedirectURL, &idp.AudienceURI, &idp.ClientID, &idp.Endpoint, &idp.CreatedBy, &idp.LastUpdated, &idp.SCIMEndpoint)
if err != nil {
logger.Errorf("scan error in idpStore.GetAllIdps: %v", err)
}
idps = append(idps, idp)
}
return idps, err
}
// GetAllIdpsWoa retrieves all idps configured for organization. Only returne SAML idp that is required for login.
func (s idpStore) GetAllIdpsWoa() ([]models.IdentityProvider, error) {
var idps []models.IdentityProvider = make([]models.IdentityProvider, 0)
var idp models.IdentityProvider
rows, err := s.DB.Query("SELECT name,type, endpoint FROM idp WHERE type = $1", "saml")
if err != nil {
return idps, err
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&idp.IdpName, &idp.IdpType, &idp.Endpoint)
if err != nil {
logger.Errorf("scan error in idpStore.GetAllIdps: %v", err)
}
idps = append(idps, idp)
}
return idps, err
}
// GetByID retrieves IDP detail based on ID
func (s idpStore) GetByID(orgID, idpID string) (models.IdentityProvider, error) {
var idp models.IdentityProvider
err := s.DB.QueryRow("SELECT id, org_id, name,type, meta, is_enabled, redirect_url, audience_uri, client_id, endpoint, created_by , last_updated FROM idp WHERE org_id = $1 AND id=$2",
orgID, idpID).
Scan(&idp.IdpID, &idp.OrgID, &idp.IdpName, &idp.IdpType, &idp.IdpMeta, &idp.IsEnabled, &idp.RedirectURL, &idp.AudienceURI, &idp.ClientID, &idp.Endpoint, &idp.CreatedBy, &idp.LastUpdated)
return idp, err
}
// GetByName retrieves IDP detail based on Name
func (s idpStore) GetByName(orgID, idpName string) (models.IdentityProvider, error) {
var idp models.IdentityProvider
err := s.DB.QueryRow("SELECT id, org_id, name,type, meta, is_enabled, redirect_url, audience_uri, client_id, endpoint, created_by , last_updated FROM idp WHERE org_id = $1 AND name=$2",
orgID, idpName).
Scan(&idp.IdpID, &idp.OrgID, &idp.IdpName, &idp.IdpType, &idp.IdpMeta, &idp.IsEnabled, &idp.RedirectURL, &idp.AudienceURI, &idp.ClientID, &idp.Endpoint, &idp.CreatedBy, &idp.LastUpdated)
return idp, err
}
// CreateIDP creates new Identity Provider
func (s idpStore) CreateIDP(idp *models.IdentityProvider) error {
_, err := s.DB.Exec(`INSERT into idp (id, org_id, name,type, meta, is_enabled, redirect_url, audience_uri,client_id, endpoint, created_by , integration_type,scim_endpoint, last_updated )
values($1, $2, $3, $4, $5,$6,$7,$8, $9, $10, $11, $12, $13, $14);`, idp.IdpID, idp.OrgID, idp.IdpName, idp.IdpType, idp.IdpMeta, idp.IsEnabled, idp.RedirectURL, idp.AudienceURI, idp.ClientID, idp.Endpoint, idp.CreatedBy, idp.IntegrationType, idp.SCIMEndpoint, idp.LastUpdated)
return err
}
func (s idpStore) UpdateIDP(idp *models.IdentityProvider) error {
_, err := s.DB.Exec(`UPDATE idp SET meta = $1, is_enabled = $2, endpoint = $3, created_by = $4 , last_updated = $5 WHERE org_id=$6 AND id=$7`, idp.IdpMeta, idp.IsEnabled, idp.Endpoint, idp.CreatedBy, idp.LastUpdated, idp.OrgID, idp.IdpID)
return err
}
func (s idpStore) UpdateLDAPIDP(idp *models.IdentityProvider) error {
_, err := s.DB.Exec(`UPDATE idp SET meta = $1, is_enabled = $2, endpoint = $3, created_by = $4 , last_updated = $5, audience_uri=$6, client_id=$7 WHERE org_id=$8 AND id=$9`, idp.IdpMeta, idp.IsEnabled, idp.Endpoint, idp.CreatedBy, idp.LastUpdated, idp.AudienceURI, idp.ClientID, idp.OrgID, idp.IdpID)
return err
}
func (s idpStore) activateOrDisableIdp(orgID, idpID string, updateTime int64, updateVal bool) error {
_, err := s.DB.Exec(`UPDATE idp SET is_enabled = $1, last_updated = $2 WHERE org_id=$3 AND id=$4`, updateVal, updateTime, orgID, idpID)
return err
}