-
Notifications
You must be signed in to change notification settings - Fork 13
/
centralconfig.go
887 lines (773 loc) · 34.7 KB
/
centralconfig.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
package config
import (
"errors"
"fmt"
"net/url"
"strings"
"time"
v1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
mv1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1"
"github.com/Axway/agent-sdk/pkg/cmd/properties"
"github.com/Axway/agent-sdk/pkg/util/exception"
)
// AgentType - Defines the type of agent
type AgentType int
const (
// DiscoveryAgent - Type definition for discovery agent
DiscoveryAgent AgentType = iota + 1
// TraceabilityAgent - Type definition for traceability agent
TraceabilityAgent
// GovernanceAgent - Type definition for governance agent
GovernanceAgent
// GenericService - Type for a generic service
GenericService
)
var agentTypeNamesMap = map[AgentType]string{
DiscoveryAgent: "discoveryagent",
TraceabilityAgent: "traceabilityagent",
GovernanceAgent: "governanceagent",
}
var agentTypeShortNamesMap = map[AgentType]string{
DiscoveryAgent: "da",
TraceabilityAgent: "ta",
GovernanceAgent: "ga",
}
func (agentType AgentType) ToString() string {
return agentTypeNamesMap[agentType]
}
func (agentType AgentType) ToShortString() string {
return agentTypeShortNamesMap[agentType]
}
// subscription approval types
const (
ManualApproval string = "manual"
AutoApproval string = "auto"
WebhookApproval string = "webhook"
)
// AgentTypeName - Holds the name Agent type
var AgentTypeName string
// AgentDisplayName - Holds the name Agent name for displaying in version command or elsewhere
var AgentDisplayName string
// AgentVersion - Holds the version of agent
var AgentVersion string
// AgentLatestVersion - Holds the latest version of the agent
var AgentLatestVersion string
// AgentDataPlaneType - Holds the data plane type of agent
var AgentDataPlaneType string
// SDKVersion - Holds the version of SDK
var SDKVersion string
// IConfigValidator - Interface to be implemented for config validation by agent
type IConfigValidator interface {
ValidateCfg() error
}
// IResourceConfigCallback - Interface to be implemented by configs to apply API Server resource for agent
type IResourceConfigCallback interface {
ApplyResources(agentResource *v1.ResourceInstance) error
}
// CentralConfig - Interface to get central Config
type CentralConfig interface {
GetAgentType() AgentType
GetTenantID() string
GetAPICDeployment() string
GetEnvironmentID() string
SetEnvironmentID(environmentID string)
IsAxwayManaged() bool
SetAxwayManaged(isAxwayManaged bool)
GetEnvironmentName() string
GetAgentName() string
GetTeamName() string
GetTeamID() string
SetTeamID(teamID string)
GetURL() string
GetPlatformURL() string
GetCatalogItemsURL() string
GetAPIServerURL() string
GetEnvironmentURL() string
GetEnvironmentACLsURL() string
GetServicesURL() string
GetRevisionsURL() string
GetInstancesURL() string
DeleteServicesURL() string
GetConsumerInstancesURL() string
GetAPIServerSubscriptionDefinitionURL() string
GetAPIServerAccessRequestDefinitionURL() string
GetAPIServerWebhooksURL() string
GetAPIServerSecretsURL() string
GetCategoriesURL() string
GetSubscriptionURL() string
GetSubscriptionConfig() SubscriptionConfig
GetAccessRequestsURL() string
GetAccessRequestURL(string) string
GetAccessRequestStateURL(string) string
GetCatalogItemSubscriptionsURL(string) string
GetCatalogItemSubscriptionStatesURL(string, string) string
GetCatalogItemSubscriptionPropertiesURL(string, string) string
GetCatalogItemSubscriptionRelationshipURL(string, string) string
GetCatalogItemSubscriptionDefinitionPropertiesURL(string) string
GetAuthConfig() AuthConfig
GetTLSConfig() TLSConfig
GetTagsToPublish() string
GetProxyURL() string
GetPollInterval() time.Duration
GetReportActivityFrequency() time.Duration
GetAPIValidationFrequency() time.Duration
GetJobExecutionTimeout() time.Duration
GetClientTimeout() time.Duration
GetAPIServiceRevisionPattern() string
GetCatalogItemByIDURL(catalogItemID string) string
GetAppendEnvironmentToTitle() bool
GetUsageReportingConfig() UsageReportingConfig
IsUsingGRPC() bool
GetGRPCHost() string
GetGRPCPort() int
IsGRPCInsecure() bool
GetCacheStoragePath() string
GetCacheStorageInterval() time.Duration
SetIsMarketplaceSubsEnabled(enabled bool)
IsMarketplaceSubsEnabled() bool
GetSingleURL() string
GetMigrationSettings() MigrationConfig
GetWatchResourceFilters() []ResourceFilter
SetWatchResourceFilters([]ResourceFilter) error
GetCredentialConfig() CredentialConfig
}
// CentralConfiguration - Structure to hold the central config
type CentralConfiguration struct {
CentralConfig
IConfigValidator
AgentType AgentType
TenantID string `config:"organizationID"`
TeamName string `config:"team"`
APICDeployment string `config:"deployment"`
Environment string `config:"environment"`
EnvironmentID string `config:"environmentID"`
AgentName string `config:"agentName"`
URL string `config:"url"`
SingleURL string `config:"platformSingleURL"`
PlatformURL string `config:"platformURL"`
APIServerVersion string `config:"apiServerVersion"`
TagsToPublish string `config:"additionalTags"`
AppendEnvironmentToTitle bool `config:"appendEnvironmentToTitle"`
MigrationSettings MigrationConfig `config:"migration"`
Auth AuthConfig `config:"auth"`
TLS TLSConfig `config:"ssl"`
PollInterval time.Duration `config:"pollInterval"`
ReportActivityFrequency time.Duration `config:"reportActivityFrequency"`
ClientTimeout time.Duration `config:"clientTimeout"`
APIValidationFrequency time.Duration `config:"apiValidationFrequency"`
APIServiceRevisionPattern string `config:"apiServiceRevisionPattern"`
ProxyURL string `config:"proxyUrl"`
SubscriptionConfiguration SubscriptionConfig `config:"subscriptions"`
UsageReporting UsageReportingConfig `config:"usageReporting"`
GRPCCfg GRPCConfig `config:"grpc"`
CacheStoragePath string `config:"cacheStoragePath"`
CacheStorageInterval time.Duration `config:"cacheStorageInterval"`
CredentialConfig CredentialConfig `config:"credential"`
JobExecutionTimeout time.Duration
environmentID string
teamID string
isAxwayManaged bool
isMarketplaceSubs bool
WatchResourceFilters []ResourceFilter
}
// GRPCConfig - Represents the grpc config
type GRPCConfig struct {
Enabled bool `config:"enabled"`
Host string `config:"host"`
Port int `config:"port"`
Insecure bool `config:"insecure"`
}
// NewCentralConfig - Creates the default central config
func NewCentralConfig(agentType AgentType) CentralConfig {
return &CentralConfiguration{
AgentType: agentType,
TeamName: "",
APIServerVersion: "v1alpha1",
Auth: newAuthConfig(),
TLS: NewTLSConfig(),
PollInterval: 60 * time.Second,
ClientTimeout: 60 * time.Second,
PlatformURL: "https://platform.axway.com",
SingleURL: "",
SubscriptionConfiguration: NewSubscriptionConfig(),
AppendEnvironmentToTitle: true,
ReportActivityFrequency: 5 * time.Minute,
APIValidationFrequency: 1 * time.Hour,
UsageReporting: NewUsageReporting(),
JobExecutionTimeout: 5 * time.Minute,
CacheStorageInterval: 10 * time.Second,
GRPCCfg: GRPCConfig{},
MigrationSettings: newMigrationConfig(),
CredentialConfig: newCredentialConfig(),
}
}
// NewTestCentralConfig - Creates the default central config
func NewTestCentralConfig(agentType AgentType) CentralConfig {
config := NewCentralConfig(agentType).(*CentralConfiguration)
config.TenantID = "1234567890"
config.URL = "https://central.com"
config.Environment = "environment"
config.Auth = newTestAuthConfig()
config.MigrationSettings = newTestMigrationConfig()
return config
}
// GetPlatformURL - Returns the central base URL
func (c *CentralConfiguration) GetPlatformURL() string {
return c.PlatformURL
}
// GetAgentType - Returns the agent type
func (c *CentralConfiguration) GetAgentType() AgentType {
return c.AgentType
}
// GetTenantID - Returns the tenant ID
func (c *CentralConfiguration) GetTenantID() string {
return c.TenantID
}
// GetAPICDeployment - Returns the Central deployment type 'prod', 'preprod', team ('beano')
func (c *CentralConfiguration) GetAPICDeployment() string {
return c.APICDeployment
}
// GetEnvironmentID - Returns the environment ID
func (c *CentralConfiguration) GetEnvironmentID() string {
return c.environmentID
}
// SetEnvironmentID - Sets the environment ID
func (c *CentralConfiguration) SetEnvironmentID(environmentID string) {
c.environmentID = environmentID
}
// SetIsMarketplaceSubsEnabled - Sets the isMarketplaceSubs boolean
func (c *CentralConfiguration) SetIsMarketplaceSubsEnabled(enabled bool) {
c.isMarketplaceSubs = enabled
}
// IsMarketplaceSubsEnabled - Returns the isMarketplaceSubs boolean
func (c *CentralConfiguration) IsMarketplaceSubsEnabled() bool {
return c.isMarketplaceSubs
}
// IsAxwayManaged - Returns the environment ID
func (c *CentralConfiguration) IsAxwayManaged() bool {
return c.isAxwayManaged
}
// SetAxwayManaged - Sets the environment ID
func (c *CentralConfiguration) SetAxwayManaged(isManaged bool) {
c.isAxwayManaged = isManaged
}
// GetEnvironmentName - Returns the environment name
func (c *CentralConfiguration) GetEnvironmentName() string {
return c.Environment
}
// GetAgentName - Returns the agent name
func (c *CentralConfiguration) GetAgentName() string {
return c.AgentName
}
// GetTeamName - Returns the team name
func (c *CentralConfiguration) GetTeamName() string {
return c.TeamName
}
// GetTeamID - Returns the team ID
func (c *CentralConfiguration) GetTeamID() string {
return c.teamID
}
// SetTeamID - Sets the team ID
func (c *CentralConfiguration) SetTeamID(teamID string) {
c.teamID = teamID
}
// GetURL - Returns the central base URL
func (c *CentralConfiguration) GetURL() string {
return c.URL
}
// GetProxyURL - Returns the central Proxy URL
func (c *CentralConfiguration) GetProxyURL() string {
return c.ProxyURL
}
// GetCatalogItemsURL - Returns the unifiedcatalog URL for catalog items API
func (c *CentralConfiguration) GetCatalogItemsURL() string {
return c.URL + "/api/unifiedCatalog/v1/catalogItems"
}
// GetAccessRequestsURL - Returns the accessrequest URL for access request API
func (c *CentralConfiguration) GetAccessRequestsURL() string {
return c.GetEnvironmentURL() + "/accessrequests"
}
// GetAPIServerURL - Returns the base path for the API server
func (c *CentralConfiguration) GetAPIServerURL() string {
return c.URL + "/apis/management/" + c.APIServerVersion + "/environments/"
}
// GetAPIServerCatalogURL - Returns the base path for the API server for catalog resources
func (c *CentralConfiguration) GetAPIServerCatalogURL() string {
return c.URL + "/apis/catalog/" + c.APIServerVersion
}
// GetEnvironmentURL - Returns the APIServer URL for services API
func (c *CentralConfiguration) GetEnvironmentURL() string {
return c.GetAPIServerURL() + c.Environment
}
// GetEnvironmentACLsURL - Returns the APIServer URL for ACLs in Environments
func (c *CentralConfiguration) GetEnvironmentACLsURL() string {
return c.GetEnvironmentURL() + "/accesscontrollists"
}
// GetServicesURL - Returns the APIServer URL for services API
func (c *CentralConfiguration) GetServicesURL() string {
return c.GetEnvironmentURL() + "/apiservices"
}
// GetRevisionsURL - Returns the APIServer URL for services API revisions
func (c *CentralConfiguration) GetRevisionsURL() string {
return c.GetEnvironmentURL() + "/apiservicerevisions"
}
// GetInstancesURL - Returns the APIServer URL for services API instances
func (c *CentralConfiguration) GetInstancesURL() string {
return c.GetEnvironmentURL() + "/apiserviceinstances"
}
// DeleteServicesURL - Returns the APIServer URL for services API instances
func (c *CentralConfiguration) DeleteServicesURL() string {
return c.GetEnvironmentURL() + "/apiservices"
}
// GetConsumerInstancesURL - Returns the APIServer URL for services API consumer instances
func (c *CentralConfiguration) GetConsumerInstancesURL() string {
return c.GetEnvironmentURL() + "/consumerinstances"
}
// GetAPIServerSubscriptionDefinitionURL - Returns the APIServer URL for services API instances
func (c *CentralConfiguration) GetAPIServerSubscriptionDefinitionURL() string {
return c.GetEnvironmentURL() + "/consumersubscriptiondefs"
}
// GetAPIServerAccessRequestDefinitionURL - Returns the APIServer URL for access request definitions
func (c *CentralConfiguration) GetAPIServerAccessRequestDefinitionURL() string {
return c.GetEnvironmentURL() + "/accessrequestdefinitions"
}
// GetCategoriesURL - Returns the Categories URL
func (c *CentralConfiguration) GetCategoriesURL() string {
return c.GetAPIServerCatalogURL() + "/categories"
}
// GetAPIServerWebhooksURL - Returns the APIServer URL for webhooks instances
func (c *CentralConfiguration) GetAPIServerWebhooksURL() string {
return c.GetEnvironmentURL() + "/webhooks"
}
// GetAPIServerSecretsURL - Returns the APIServer URL for secrets
func (c *CentralConfiguration) GetAPIServerSecretsURL() string {
return c.GetEnvironmentURL() + "/secrets"
}
// GetSubscriptionURL - Returns the unifiedcatalog URL for subscriptions list
func (c *CentralConfiguration) GetSubscriptionURL() string {
return c.URL + "/api/unifiedCatalog/v1/subscriptions"
}
// GetCatalogItemSubscriptionsURL - Returns the unifiedcatalog URL for catalog item subscriptions
func (c *CentralConfiguration) GetCatalogItemSubscriptionsURL(catalogItemID string) string {
return fmt.Sprintf("%s/%s/subscriptions", c.GetCatalogItemsURL(), catalogItemID)
}
// GetCatalogItemSubscriptionStatesURL - Returns the unifiedcatalog URL for catalog item subscription states
func (c *CentralConfiguration) GetCatalogItemSubscriptionStatesURL(catalogItemID, subscriptionID string) string {
return fmt.Sprintf("%s/%s/states", c.GetCatalogItemSubscriptionsURL(catalogItemID), subscriptionID)
}
// GetAccessRequestURL - Returns the access request URL for catalog item subscription states
func (c *CentralConfiguration) GetAccessRequestURL(accessRequestName string) string {
return fmt.Sprintf("%s/%s", c.GetAccessRequestsURL(), accessRequestName)
}
// GetAccessRequestStateURL - Returns the access request URL to update the state
func (c *CentralConfiguration) GetAccessRequestStateURL(accessRequestName string) string {
return fmt.Sprintf("%s/state", c.GetAccessRequestURL(accessRequestName))
}
// GetCatalogItemSubscriptionPropertiesURL - Returns the unifiedcatalog URL for catalog item subscription properties
func (c *CentralConfiguration) GetCatalogItemSubscriptionPropertiesURL(catalogItemID, subscriptionID string) string {
return fmt.Sprintf("%s/%s/properties", c.GetCatalogItemSubscriptionsURL(catalogItemID), subscriptionID)
}
// GetAccessRequestSubscriptionPropertiesURL - Returns the access request URL for subscription properties
func (c *CentralConfiguration) GetAccessRequestSubscriptionPropertiesURL(accessRequestName string) string {
return fmt.Sprintf("%s/%s", c.GetAccessRequestsURL(), accessRequestName)
}
// GetCatalogItemSubscriptionRelationshipURL - Returns the relationships URL for catalog item subscription
func (c *CentralConfiguration) GetCatalogItemSubscriptionRelationshipURL(catalogItemID, subscriptionID string) string {
return fmt.Sprintf("%s/%s/relationships", c.GetCatalogItemSubscriptionsURL(catalogItemID), subscriptionID)
}
// GetCatalogItemSubscriptionDefinitionPropertiesURL - Returns the unifiedcatalog URL for catalog item subscription definition properties
func (c *CentralConfiguration) GetCatalogItemSubscriptionDefinitionPropertiesURL(catalogItemID string) string {
return fmt.Sprintf("%s/%s/%s/properties", c.GetCatalogItemsURL(), catalogItemID, "subscriptionDefinition")
}
// GetAuthConfig - Returns the Auth Config
func (c *CentralConfiguration) GetAuthConfig() AuthConfig {
return c.Auth
}
// GetMigrationSettings - Returns the Migration Config
func (c *CentralConfiguration) GetMigrationSettings() MigrationConfig {
return c.MigrationSettings
}
// GetTLSConfig - Returns the TLS Config
func (c *CentralConfiguration) GetTLSConfig() TLSConfig {
return c.TLS
}
// GetSubscriptionConfig - Returns the Config for the subscription webhook
func (c *CentralConfiguration) GetSubscriptionConfig() SubscriptionConfig {
return c.SubscriptionConfiguration
}
// GetTagsToPublish - Returns tags to publish
func (c *CentralConfiguration) GetTagsToPublish() string {
return c.TagsToPublish
}
// GetCatalogItemByIDURL - Returns URL to get catalog item by id
func (c *CentralConfiguration) GetCatalogItemByIDURL(catalogItemID string) string {
return c.GetCatalogItemsURL() + "/" + catalogItemID
}
// GetPollInterval - Returns the interval for polling subscriptions
func (c *CentralConfiguration) GetPollInterval() time.Duration {
return c.PollInterval
}
// GetReportActivityFrequency - Returns the interval between running periodic status updater
func (c *CentralConfiguration) GetReportActivityFrequency() time.Duration {
return c.ReportActivityFrequency
}
// GetAPIValidationFrequency - Returns the interval between running the api validator
func (c *CentralConfiguration) GetAPIValidationFrequency() time.Duration {
return c.APIValidationFrequency
}
// GetJobExecutionTimeout - Returns the max time a job execution can run before considered failed
func (c *CentralConfiguration) GetJobExecutionTimeout() time.Duration {
return c.JobExecutionTimeout
}
// GetClientTimeout - Returns the interval for http client timeouts
func (c *CentralConfiguration) GetClientTimeout() time.Duration {
return c.ClientTimeout
}
// GetAPIServiceRevisionPattern - Returns the naming pattern for APIServiceRevition title
func (c *CentralConfiguration) GetAPIServiceRevisionPattern() string {
return c.APIServiceRevisionPattern
}
// GetAppendEnvironmentToTitle - Returns the value of append environment name to title attribute
func (c *CentralConfiguration) GetAppendEnvironmentToTitle() bool {
return c.AppendEnvironmentToTitle
}
// GetUsageReportingConfig -
func (c *CentralConfiguration) GetUsageReportingConfig() UsageReportingConfig {
// Some paths in DA are checking usage reporting . So return an empty usage reporting config if nil
// Find All References to see DA scenarios checking for this config
if c.UsageReporting == nil {
return NewUsageReporting()
}
return c.UsageReporting
}
// GetCredentialConfig -
func (c *CentralConfiguration) GetCredentialConfig() CredentialConfig {
return c.CredentialConfig
}
// IsUsingGRPC -
func (c *CentralConfiguration) IsUsingGRPC() bool {
return c.GRPCCfg.Enabled
}
// GetGRPCHost -
func (c *CentralConfiguration) GetGRPCHost() string {
return c.GRPCCfg.Host
}
// GetGRPCPort -
func (c *CentralConfiguration) GetGRPCPort() int {
return c.GRPCCfg.Port
}
// IsGRPCInsecure -
func (c *CentralConfiguration) IsGRPCInsecure() bool {
return c.GRPCCfg.Insecure
}
// GetCacheStoragePath -
func (c *CentralConfiguration) GetCacheStoragePath() string {
return c.CacheStoragePath
}
// GetCacheStorageInterval -
func (c *CentralConfiguration) GetCacheStorageInterval() time.Duration {
return c.CacheStorageInterval
}
// GetSingleURL - Returns the Alternate base URL
func (c *CentralConfiguration) GetSingleURL() string {
return c.SingleURL
}
// GetWatchResourceFilters - returns the custom watch filter config
func (c *CentralConfiguration) GetWatchResourceFilters() []ResourceFilter {
if c.WatchResourceFilters == nil {
c.WatchResourceFilters = make([]ResourceFilter, 0)
}
return c.WatchResourceFilters
}
// SetWatchResourceFilters - sets the custom watch filter config
func (c *CentralConfiguration) SetWatchResourceFilters(filters []ResourceFilter) error {
c.WatchResourceFilters = make([]ResourceFilter, 0)
for _, filter := range filters {
if filter.Group == "" || filter.Kind == "" {
return errors.New("invalid watch filter configuration, group and kind are required")
}
if filter.Name == "" {
filter.Name = "*"
}
if len(filter.EventTypes) == 0 {
filter.EventTypes = []ResourceEventType{ResourceEventCreated, ResourceEventUpdated, ResourceEventDeleted}
}
if filter.Scope == nil {
filter.Scope = &ResourceScope{
Kind: mv1.EnvironmentGVK().Kind,
Name: c.GetEnvironmentName(),
}
} else {
if filter.Scope.Kind == "" || filter.Scope.Name == "" {
return errors.New("invalid watch filter configuration, scope kind and name are required")
}
}
c.WatchResourceFilters = append(c.WatchResourceFilters, filter)
}
return nil
}
const (
pathTenantID = "central.organizationID"
pathURL = "central.url"
pathPlatformURL = "central.platformURL"
pathAuthPrivateKey = "central.auth.privateKey"
pathAuthPublicKey = "central.auth.publicKey"
pathAuthKeyPassword = "central.auth.keyPassword"
pathAuthURL = "central.auth.url"
pathSingleURL = "central.singleURL"
pathAuthRealm = "central.auth.realm"
pathAuthClientID = "central.auth.clientId"
pathAuthTimeout = "central.auth.timeout"
pathSSLNextProtos = "central.ssl.nextProtos"
pathSSLInsecureSkipVerify = "central.ssl.insecureSkipVerify"
pathSSLCipherSuites = "central.ssl.cipherSuites"
pathSSLMinVersion = "central.ssl.minVersion"
pathSSLMaxVersion = "central.ssl.maxVersion"
pathEnvironment = "central.environment"
pathEnvironmentID = "central.environmentID"
pathAgentName = "central.agentName"
pathDeployment = "central.deployment"
pathMode = "central.mode"
pathTeam = "central.team"
pathPollInterval = "central.pollInterval"
pathReportActivityFrequency = "central.reportActivityFrequency"
pathClientTimeout = "central.clientTimeout"
pathAPIServiceRevisionPattern = "central.apiServiceRevisionPattern"
pathProxyURL = "central.proxyUrl"
pathAPIServerVersion = "central.apiServerVersion"
pathAdditionalTags = "central.additionalTags"
pathAppendEnvironmentToTitle = "central.appendEnvironmentToTitle"
pathAPIValidationFrequency = "central.apiValidationFrequency"
pathJobTimeout = "central.jobTimeout"
pathGRPCEnabled = "central.grpc.enabled"
pathGRPCHost = "central.grpc.host"
pathGRPCPort = "central.grpc.port"
pathGRPCInsecure = "central.grpc.insecure"
pathCacheStoragePath = "central.cacheStoragePath"
pathCacheStorageInterval = "central.cacheStorageInterval"
)
// ValidateCfg - Validates the config, implementing IConfigInterface
func (c *CentralConfiguration) ValidateCfg() (err error) {
exception.Block{
Try: func() {
if supportsTraceability(c.AgentType) && c.GetUsageReportingConfig().IsOfflineMode() {
// only validate certain things when a traceability agent is in offline mode
c.validateOfflineConfig()
c.GetUsageReportingConfig().Validate()
return
}
c.validateConfig()
c.Auth.validate()
// Check that platform service account is used with market place provisioning
if c.IsMarketplaceSubsEnabled() && strings.HasPrefix(c.Auth.GetClientID(), "DOSA_") {
exception.Throw(ErrServiceAccount)
}
if supportsTraceability(c.AgentType) {
c.GetUsageReportingConfig().Validate()
}
},
Catch: func(e error) {
err = e
},
}.Do()
return
}
func (c *CentralConfiguration) validateConfig() {
if c.GetTenantID() == "" {
exception.Throw(ErrBadConfig.FormatError(pathTenantID))
}
c.validateURL(c.GetURL(), pathURL, true)
c.validateURL(c.GetPlatformURL(), pathPlatformURL, true)
if c.GetSingleURL() != "" {
c.validateURL(c.GetSingleURL(), pathSingleURL, true)
}
// proxyURL
c.validateURL(c.GetProxyURL(), pathProxyURL, false)
if supportsTraceability(c.AgentType) {
c.validateTraceabilityAgentConfig()
} else {
c.validateEnvironmentConfig()
c.validateDiscoveryAgentConfig()
}
if c.GetReportActivityFrequency() <= 0 {
exception.Throw(ErrBadConfig.FormatError(pathReportActivityFrequency))
}
if c.GetAPIValidationFrequency() <= 0 {
exception.Throw(ErrBadConfig.FormatError(pathAPIValidationFrequency))
}
if c.GetClientTimeout() <= 0 {
exception.Throw(ErrBadConfig.FormatError(pathClientTimeout))
}
if c.GetJobExecutionTimeout() < 0 {
exception.Throw(ErrBadConfig.FormatError(pathJobTimeout))
}
}
func (c *CentralConfiguration) validateURL(urlString, configPath string, isURLRequired bool) {
if isURLRequired && urlString == "" {
exception.Throw(ErrBadConfig.FormatError(configPath))
}
if urlString != "" {
if _, err := url.ParseRequestURI(urlString); err != nil {
exception.Throw(ErrBadConfig.FormatError(configPath))
}
}
}
func (c *CentralConfiguration) validateDiscoveryAgentConfig() {
if c.GetPollInterval() <= 0 {
exception.Throw(ErrBadConfig.FormatError(pathPollInterval))
}
}
func (c *CentralConfiguration) validateEnvironmentConfig() {
if c.GetEnvironmentName() == "" {
exception.Throw(ErrBadConfig.FormatError(pathEnvironment))
}
if c.APIServerVersion == "" {
exception.Throw(ErrBadConfig.FormatError(pathAPIServerVersion))
}
}
func (c *CentralConfiguration) validateTraceabilityAgentConfig() {
if c.GetAPICDeployment() == "" {
exception.Throw(ErrBadConfig.FormatError(pathDeployment))
}
if c.GetEnvironmentName() == "" {
exception.Throw(ErrBadConfig.FormatError(pathEnvironment))
}
}
func (c *CentralConfiguration) validateOfflineConfig() {
// validate environment ID
c.SetEnvironmentID(c.EnvironmentID)
if c.GetEnvironmentID() == "" {
exception.Throw(ErrBadConfig.FormatError(pathEnvironmentID))
}
}
// AddCentralConfigProperties - Adds the command properties needed for Central Config
func AddCentralConfigProperties(props properties.Properties, agentType AgentType) {
props.AddStringProperty(pathTenantID, "", "Tenant ID for the owner of the environment")
props.AddStringProperty(pathURL, "https://apicentral.axway.com", "URL of Amplify Central")
props.AddStringProperty(pathTeam, "", "Team name for creating catalog")
props.AddStringProperty(pathPlatformURL, "https://platform.axway.com", "URL of the platform")
props.AddStringProperty(pathSingleURL, "", "Alternate Connection for Agent if using static IP")
props.AddStringProperty(pathAuthPrivateKey, "/etc/private_key.pem", "Path to the private key for Amplify Central Authentication")
props.AddStringProperty(pathAuthPublicKey, "/etc/public_key", "Path to the public key for Amplify Central Authentication")
props.AddStringProperty(pathAuthKeyPassword, "", "Path to the password file required by the private key for Amplify Central Authentication")
props.AddStringProperty(pathAuthURL, "https://login.axway.com/auth", "Amplify Central authentication URL")
props.AddStringProperty(pathAuthRealm, "Broker", "Amplify Central authentication Realm")
props.AddStringProperty(pathAuthClientID, "", "Client ID for the service account")
props.AddDurationProperty(pathAuthTimeout, 10*time.Second, "Timeout waiting for AxwayID response", properties.WithLowerLimit(10*time.Second))
// ssl properties and command flags
props.AddStringSliceProperty(pathSSLNextProtos, []string{}, "List of supported application level protocols, comma separated")
props.AddBoolProperty(pathSSLInsecureSkipVerify, false, "Controls whether a client verifies the server's certificate chain and host name")
props.AddStringSliceProperty(pathSSLCipherSuites, TLSDefaultCipherSuitesStringSlice(), "List of supported cipher suites, comma separated")
props.AddStringProperty(pathSSLMinVersion, TLSDefaultMinVersionString(), "Minimum acceptable SSL/TLS protocol version")
props.AddStringProperty(pathSSLMaxVersion, "0", "Maximum acceptable SSL/TLS protocol version")
props.AddStringProperty(pathEnvironment, "", "The Environment that the APIs will be associated with in Amplify Central")
props.AddStringProperty(pathAgentName, "", "The name of the asociated agent resource in Amplify Central")
props.AddStringProperty(pathProxyURL, "", "The Proxy URL to use for communication to Amplify Central")
props.AddDurationProperty(pathPollInterval, 60*time.Second, "The time interval at which the central will be polled for subscription processing")
props.AddDurationProperty(pathReportActivityFrequency, 5*time.Minute, "The time interval at which the agent polls for event changes for the periodic agent status updater")
props.AddDurationProperty(pathAPIValidationFrequency, 1*time.Hour, "The time interval at which the agent validates API Services with the dataplane", properties.WithLowerLimit(5*time.Minute))
props.AddDurationProperty(pathClientTimeout, 60*time.Second, "The time interval at which the http client times out making HTTP requests and processing the response")
props.AddStringProperty(pathAPIServiceRevisionPattern, "", "The naming pattern for APIServiceRevision Title")
props.AddStringProperty(pathAPIServerVersion, "v1alpha1", "Version of the API Server")
props.AddDurationProperty(pathJobTimeout, 5*time.Minute, "The max time a job execution can run before being considered as failed")
// Watch stream config
props.AddBoolProperty(pathGRPCEnabled, false, "Controls whether an agent uses a gRPC connection")
props.AddStringProperty(pathGRPCHost, "", "Host name for Amplify Central gRPC connection")
props.AddIntProperty(pathGRPCPort, 0, "Port for Amplify Central gRPC connection")
props.AddBoolProperty(pathGRPCInsecure, false, "Controls whether an agent uses a gRPC connection with TLS")
props.AddStringProperty(pathCacheStoragePath, "", "The directory path where agent cache will be persisted to file")
props.AddDurationProperty(pathCacheStorageInterval, 10*time.Second, "The interval to persist agent caches to file", properties.WithLowerLimit(10*time.Second))
if supportsTraceability(agentType) {
props.AddStringProperty(pathEnvironmentID, "", "Offline Usage Reporting Only. The Environment ID the usage is associated with on Amplify Central")
props.AddStringProperty(pathDeployment, "prod", "Amplify Central")
AddUsageReportingProperties(props)
} else {
props.AddStringProperty(pathAdditionalTags, "", "Additional Tags to Add to discovered APIs when publishing to Amplify Central")
props.AddBoolProperty(pathAppendEnvironmentToTitle, true, "When true API titles and descriptions will be appended with environment name")
AddSubscriptionConfigProperties(props)
AddMigrationConfigProperties(props)
AddCredentialConfigProperties(props)
}
}
// ParseCentralConfig - Parses the Central Config values from the command line
func ParseCentralConfig(props properties.Properties, agentType AgentType) (CentralConfig, error) {
var usageReporting UsageReportingConfig
if supportsTraceability(agentType) {
usageReporting = ParseUsageReportingConfig(props)
if usageReporting.IsOfflineMode() {
// Check if this is offline usage reporting only
cfg := &CentralConfiguration{
AgentName: props.StringPropertyValue(pathAgentName),
AgentType: agentType,
UsageReporting: usageReporting,
}
// only need the environment ID in offline mode
cfg.EnvironmentID = props.StringPropertyValue(pathEnvironmentID)
return cfg, nil
}
}
proxyURL := props.StringPropertyValue(pathProxyURL)
cfg := &CentralConfiguration{
AgentType: agentType,
TenantID: props.StringPropertyValue(pathTenantID),
PollInterval: props.DurationPropertyValue(pathPollInterval),
ReportActivityFrequency: props.DurationPropertyValue(pathReportActivityFrequency),
APIValidationFrequency: props.DurationPropertyValue(pathAPIValidationFrequency),
JobExecutionTimeout: props.DurationPropertyValue(pathJobTimeout),
ClientTimeout: props.DurationPropertyValue(pathClientTimeout),
APIServiceRevisionPattern: props.StringPropertyValue(pathAPIServiceRevisionPattern),
Environment: props.StringPropertyValue(pathEnvironment),
TeamName: props.StringPropertyValue(pathTeam),
AgentName: props.StringPropertyValue(pathAgentName),
Auth: &AuthConfiguration{
URL: props.StringPropertyValue(pathAuthURL),
Realm: props.StringPropertyValue(pathAuthRealm),
ClientID: props.StringPropertyValue(pathAuthClientID),
PrivateKey: props.StringPropertyValue(pathAuthPrivateKey),
PublicKey: props.StringPropertyValue(pathAuthPublicKey),
KeyPwd: props.StringPropertyValue(pathAuthKeyPassword),
Timeout: props.DurationPropertyValue(pathAuthTimeout),
},
TLS: &TLSConfiguration{
NextProtos: props.StringSlicePropertyValue(pathSSLNextProtos),
InsecureSkipVerify: props.BoolPropertyValue(pathSSLInsecureSkipVerify),
CipherSuites: NewCipherArray(props.StringSlicePropertyValue(pathSSLCipherSuites)),
MinVersion: TLSVersionAsValue(props.StringPropertyValue(pathSSLMinVersion)),
MaxVersion: TLSVersionAsValue(props.StringPropertyValue(pathSSLMaxVersion)),
},
ProxyURL: proxyURL,
GRPCCfg: GRPCConfig{
Enabled: props.BoolPropertyValue(pathGRPCEnabled),
Host: props.StringPropertyValue(pathGRPCHost),
Port: props.IntPropertyValue(pathGRPCPort),
Insecure: props.BoolPropertyValue(pathGRPCInsecure),
},
CacheStoragePath: props.StringPropertyValue(pathCacheStoragePath),
CacheStorageInterval: props.DurationPropertyValue(pathCacheStorageInterval),
}
cfg.URL = props.StringPropertyValue(pathURL)
cfg.SingleURL = props.StringPropertyValue(pathSingleURL)
cfg.PlatformURL = props.StringPropertyValue(pathPlatformURL)
cfg.APIServerVersion = props.StringPropertyValue(pathAPIServerVersion)
cfg.APIServiceRevisionPattern = props.StringPropertyValue(pathAPIServiceRevisionPattern)
if supportsTraceability(agentType) {
cfg.APICDeployment = props.StringPropertyValue(pathDeployment)
cfg.UsageReporting = usageReporting
} else {
cfg.TeamName = props.StringPropertyValue(pathTeam)
cfg.TagsToPublish = props.StringPropertyValue(pathAdditionalTags)
cfg.AppendEnvironmentToTitle = props.BoolPropertyValue(pathAppendEnvironmentToTitle)
// set the notifications
subscriptionConfig := ParseSubscriptionConfig(props)
cfg.SubscriptionConfiguration = subscriptionConfig
cfg.MigrationSettings = ParseMigrationConfig(props)
cfg.CredentialConfig = ParseCredentialConfig(props)
}
if cfg.AgentName == "" && cfg.Environment != "" && agentType.ToShortString() != "" {
cfg.AgentName = cfg.Environment + "-" + agentType.ToShortString()
}
return cfg, nil
}
func supportsTraceability(agentType AgentType) bool {
return agentType == TraceabilityAgent
}