-
Notifications
You must be signed in to change notification settings - Fork 402
/
system_get_privatelink_config.go
79 lines (67 loc) · 2.38 KB
/
system_get_privatelink_config.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
package snowflake
import (
"encoding/json"
"github.com/jmoiron/sqlx"
)
func SystemGetPrivateLinkConfigQuery() string {
return `SELECT SYSTEM$GET_PRIVATELINK_CONFIG() AS "config"`
}
type RawPrivateLinkConfig struct {
Config string `db:"config"`
}
type privateLinkConfigInternal struct {
AccountName string `json:"privatelink-account-name"`
AwsVpceID string `json:"privatelink-vpce-id,omitempty"`
AzurePrivateLinkServiceID string `json:"privatelink-pls-id,omitempty"`
AccountURL string `json:"privatelink-account-url"`
OCSPURL string `json:"privatelink-ocsp-url,omitempty"`
TypodOCSPURL string `json:"privatelink_ocsp-url,omitempty"` // because snowflake returns this for AWS, but don't have an Azure account to verify against
InternalStage string `json:"privatelink-internal-stage,omitempty"`
SnowsightURL string `json:"snowsight-privatelink-url,omitempty"`
RegionlessSnowsightURL string `json:"regionless-snowsight-privatelink-url,omitempty"`
RegionlessAccountURL string `json:"regionless-privatelink-account-url,omitempty"`
ConnectionURLs string `json:"privatelink-connection-urls,omitempty"`
}
type PrivateLinkConfig struct {
AccountName string
AwsVpceID string
AzurePrivateLinkServiceID string
AccountURL string
OCSPURL string
InternalStage string
SnowsightURL string
RegionlessSnowsightURL string
RegionlessAccountURL string
ConnectionURLs string
}
func ScanPrivateLinkConfig(row *sqlx.Row) (*RawPrivateLinkConfig, error) {
config := &RawPrivateLinkConfig{}
err := row.StructScan(config)
return config, err
}
func (r *RawPrivateLinkConfig) GetStructuredConfig() (*PrivateLinkConfig, error) {
config := &privateLinkConfigInternal{}
err := json.Unmarshal([]byte(r.Config), config)
if err != nil {
return nil, err
}
return config.getPrivateLinkConfig()
}
func (i *privateLinkConfigInternal) getPrivateLinkConfig() (*PrivateLinkConfig, error) {
config := &PrivateLinkConfig{
i.AccountName,
i.AwsVpceID,
i.AzurePrivateLinkServiceID,
i.AccountURL,
i.OCSPURL,
i.InternalStage,
i.SnowsightURL,
i.RegionlessSnowsightURL,
i.RegionlessAccountURL,
i.ConnectionURLs,
}
if i.TypodOCSPURL != "" {
config.OCSPURL = i.TypodOCSPURL
}
return config, nil
}