-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
APIGOV-28984 [SDK] Custom unit configuration and client code
- Loading branch information
Deepak Kasu
committed
Oct 16, 2024
1 parent
5d14643
commit 42f7c46
Showing
7 changed files
with
312 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package config | ||
|
||
import ( | ||
"net/url" | ||
|
||
"github.com/Axway/agent-sdk/pkg/util/exception" | ||
) | ||
|
||
const ( | ||
pathMetricServiceEnable = "agentFeatures.metricServices.enable" | ||
pathMetricServiceURL = "agentFeatures.metricServices.url" | ||
pathRejectOnFail = "agentFeatures.metricServices.rejectOnFail" | ||
) | ||
|
||
type MetricServiceConfig interface { | ||
MetricServiceEnabled() bool | ||
GetMetricServiceURL() string | ||
RejectOnFailEnabled() bool | ||
validate() | ||
} | ||
|
||
type MetricServiceConfiguration struct { | ||
MetricServiceConfig | ||
Enable bool `config:"enable"` // set to true to have the sdk initiate the connection to the custom metric service | ||
URL string `config:"url"` // set the url that the agent will connect to the metric service on | ||
RejectOnFail bool `config:"rejectOnFail"` // set to true to reject the access request if the quota enforcement call fails | ||
} | ||
|
||
func (a *MetricServiceConfiguration) validate() { | ||
if a.GetMetricServiceURL() == "" { | ||
exception.Throw(ErrBadConfig.FormatError(pathMetricServiceEnable)) | ||
} else if _, err := url.ParseRequestURI(a.GetMetricServiceURL()); err != nil { | ||
exception.Throw(ErrBadConfig.FormatError(pathMetricServiceEnable)) | ||
} | ||
} | ||
|
||
func (c *MetricServiceConfiguration) MetricServiceEnabled() bool { | ||
return c.Enable | ||
} | ||
|
||
// ProcessSystemSignalsEnabled - True if the agent SDK listens for system signals and manages shutdown | ||
func (c *MetricServiceConfiguration) GetMetricServiceURL() string { | ||
return c.URL | ||
} | ||
|
||
// VersionCheckerEnabled - True if the agent SDK should check for newer versions of the agent. | ||
func (c *MetricServiceConfiguration) RejectOnFailEnabled() bool { | ||
return c.RejectOnFail | ||
} |
Oops, something went wrong.