@@ -4,43 +4,77 @@ import (
44 "github.com/cloudquery/plugin-sdk/v4/schema"
55)
66
7- func OrganizationMultiplex (meta schema.ClientMeta ) []schema.ClientMeta {
8- client := meta .(* Client )
9- hierarchyItems := client .hierarchy .OrganizationRows ()
7+ // available reports whether a service can be reached in the installation this
8+ // client is connected to, logging the tables we skip because it cannot.
9+ func (c * Client ) available (service Service ) bool {
10+ if c .serviceAvailable (service ) {
11+ return true
12+ }
13+ c .Logger .Info ().
14+ Str ("service" , string (service )).
15+ Str ("region" , string (c .Region )).
16+ Msg ("skipping tables: this installation does not offer the service" )
17+ return false
18+ }
1019
11- var l = make ([]schema.ClientMeta , len (hierarchyItems ))
12- for i , item := range hierarchyItems {
13- l [i ] = client .WithOrganization (item .Organization ).WithMultiplexedResourceId (item .Organization )
20+ // GlobalMultiplex is for tables whose RPC takes no folder, cloud or
21+ // organization: it keeps the single unscoped client the scheduler would use
22+ // anyway, but drops it in regions that do not have the service.
23+ func GlobalMultiplex (service Service ) schema.Multiplexer {
24+ return func (meta schema.ClientMeta ) []schema.ClientMeta {
25+ client := meta .(* Client )
26+ if ! client .available (service ) {
27+ return nil
28+ }
29+ return []schema.ClientMeta {client }
1430 }
15- return l
1631}
1732
18- func CloudMultiplex (meta schema.ClientMeta ) []schema.ClientMeta {
19- client := meta .(* Client )
20- hierarchyItems := client .hierarchy .CloudRows ()
33+ func OrganizationMultiplex (service Service ) schema.Multiplexer {
34+ return func (meta schema.ClientMeta ) []schema.ClientMeta {
35+ client := meta .(* Client )
36+ if ! client .available (service ) {
37+ return nil
38+ }
39+ hierarchyItems := client .hierarchy .OrganizationRows ()
2140
22- var l = make ([]schema.ClientMeta , len (hierarchyItems ))
23- for i , item := range hierarchyItems {
24- l [i ] = client .WithOrganization (item .Organization ).WithCloud (item .Cloud ).WithMultiplexedResourceId (item .Cloud )
41+ var l = make ([]schema.ClientMeta , len (hierarchyItems ))
42+ for i , item := range hierarchyItems {
43+ l [i ] = client .WithOrganization (item .Organization ).WithMultiplexedResourceId (item .Organization )
44+ }
45+ return l
2546 }
26- return l
2747}
2848
29- func FolderMultiplex (meta schema.ClientMeta ) []schema.ClientMeta {
30- client := meta .(* Client )
31- hierarchyItems := client .hierarchy .FolderRows ()
49+ func CloudMultiplex (service Service ) schema.Multiplexer {
50+ return func (meta schema.ClientMeta ) []schema.ClientMeta {
51+ client := meta .(* Client )
52+ if ! client .available (service ) {
53+ return nil
54+ }
55+ hierarchyItems := client .hierarchy .CloudRows ()
3256
33- var l = make ([]schema.ClientMeta , len (hierarchyItems ))
34- for i , item := range hierarchyItems {
35- l [i ] = client .WithOrganization (item .Organization ).WithCloud (item .Cloud ).WithFolder (item .Folder ).WithMultiplexedResourceId (item .Folder )
57+ var l = make ([]schema.ClientMeta , len (hierarchyItems ))
58+ for i , item := range hierarchyItems {
59+ l [i ] = client .WithOrganization (item .Organization ).WithCloud (item .Cloud ).WithMultiplexedResourceId (item .Cloud )
60+ }
61+ return l
3662 }
37- return l
3863}
3964
40- func PrependEmptyMultiplex ( multiplexer schema. Multiplexer ) schema.Multiplexer {
65+ func FolderMultiplex ( service Service ) schema.Multiplexer {
4166 return func (meta schema.ClientMeta ) []schema.ClientMeta {
4267 client := meta .(* Client )
43- return append ([]schema.ClientMeta {client }, multiplexer (meta )... )
68+ if ! client .available (service ) {
69+ return nil
70+ }
71+ hierarchyItems := client .hierarchy .FolderRows ()
72+
73+ var l = make ([]schema.ClientMeta , len (hierarchyItems ))
74+ for i , item := range hierarchyItems {
75+ l [i ] = client .WithOrganization (item .Organization ).WithCloud (item .Cloud ).WithFolder (item .Folder ).WithMultiplexedResourceId (item .Folder )
76+ }
77+ return l
4478 }
4579}
4680
0 commit comments