-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#17): adds transaction_detection_rule resource
- Loading branch information
1 parent
2050d9e
commit 6331fa5
Showing
13 changed files
with
1,082 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
package client | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/imroc/req" | ||
) | ||
|
||
func (c *AppDClient) GetTransactionRules(applicationId int) (*TransactionRules, error) { | ||
|
||
resp, err := req.Get(c.createGetTransactionRuleUrl(applicationId), c.createAuthHeader()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if resp.Response().StatusCode != 200 { | ||
respString, _ := resp.ToString() | ||
return nil, errors.New(fmt.Sprintf("Error getting Transaction configs: %d, %s", resp.Response().StatusCode, respString)) | ||
} | ||
|
||
var updated TransactionRules | ||
err = resp.ToJSON(&updated) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &updated, nil | ||
} | ||
|
||
func (c *AppDClient) GetTransactionRule(applicationId int, transactionRuleId string) (*RuleScope, bool, error) { | ||
|
||
rules, err := c.GetTransactionRules(applicationId) | ||
|
||
if err != nil { | ||
return nil, false, err | ||
} | ||
|
||
for _, n := range rules.RuleScopeSummaryMappings { | ||
if transactionRuleId == n.Rule.Summary.Id { | ||
return n, true, nil | ||
} | ||
} | ||
|
||
return nil, false, nil | ||
} | ||
|
||
func (c *AppDClient) CreateTransactionRule(applicationId int, rule *TransactionRule) (*UpdateResult, error) { | ||
|
||
resp, err := req.Post(c.createCreateTransactionRuleUrl(), c.createAuthHeader(), req.QueryParam{"scopeId": "", "applicationId": applicationId}, req.BodyJSON(rule)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if resp.Response().StatusCode != 200 { | ||
respString, _ := resp.ToString() | ||
return nil, errors.New(fmt.Sprintf("Error creating Transaction rule: %d, %s", resp.Response().StatusCode, respString)) | ||
} | ||
|
||
var updated UpdateResult | ||
err = resp.ToJSON(&updated) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &updated, nil | ||
} | ||
|
||
func (c *AppDClient) DeleteTransactionRules(transactionRuleIds []string) (*UpdateResult, error) { | ||
|
||
resp, err := req.Post(c.createDeleteTransactionRuleUrl(), c.createAuthHeader(), req.BodyJSON(transactionRuleIds)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if resp.Response().StatusCode != 200 { | ||
respString, _ := resp.ToString() | ||
return nil, errors.New(fmt.Sprintf("Error deleting Transaction rule: %d, %s", resp.Response().StatusCode, respString)) | ||
} | ||
|
||
var updated UpdateResult | ||
err = resp.ToJSON(&updated) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &updated, nil | ||
} | ||
|
||
func (c *AppDClient) UpdateTransactionRule(applicationId int, transactionConfig *TransactionRule) (*UpdateResult, error) { | ||
|
||
resp, err := req.Post(c.createUpdateTransactionRuleUrl(), c.createAuthHeader(), req.QueryParam{"scopeId": "", "applicationId": applicationId}, req.BodyJSON(transactionConfig)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if resp.Response().StatusCode != 200 { | ||
respString, _ := resp.ToString() | ||
return nil, errors.New(fmt.Sprintf("Error deleting Transaction rule: %d, %s", resp.Response().StatusCode, respString)) | ||
} | ||
|
||
var updated UpdateResult | ||
err = resp.ToJSON(&updated) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &updated, nil | ||
} | ||
|
||
func (c *AppDClient) createGetTransactionRuleUrl(applicationId int) string { | ||
return fmt.Sprintf("%s/controller/restui/transactionConfigProto/getRules/%d", c.BaseUrl, applicationId) | ||
} | ||
|
||
func (c *AppDClient) createCreateTransactionRuleUrl() string { | ||
return fmt.Sprintf("%s/controller/restui/transactionConfigProto/createRule", c.BaseUrl) | ||
} | ||
|
||
func (c *AppDClient) createDeleteTransactionRuleUrl() string { | ||
return fmt.Sprintf("%s/controller/restui/transactionConfigProto/deleteRules", c.BaseUrl) | ||
} | ||
|
||
func (c *AppDClient) createUpdateTransactionRuleUrl() string { | ||
return fmt.Sprintf("%s/controller/restui/transactionConfigProto/updateRule", c.BaseUrl) | ||
} | ||
|
||
type UpdateResult struct { | ||
ResultType string `json:"resultType"` | ||
Successes []*Success `json:"successes"` | ||
} | ||
|
||
type Success struct { | ||
Summary *Summary `json:"summary"` | ||
} | ||
|
||
type TransactionRules struct { | ||
RuleScopeSummaryMappings []*RuleScope `json:"ruleScopeSummaryMappings"` | ||
} | ||
|
||
type RuleScope struct { | ||
Rule *TransactionRule `json:"rule"` | ||
} | ||
|
||
type TransactionRule struct { | ||
Type string `json:"type"` | ||
Summary *Summary `json:"summary"` | ||
Enabled bool `json:"enabled"` | ||
Priority int `json:"priority"` | ||
Version *int `json:"version,omitempty"` | ||
AgentType string `json:"agentType"` | ||
TxMatchRule *TxMatchRule `json:"txMatchRule"` | ||
} | ||
|
||
type Summary struct { | ||
Id string `json:"id"` | ||
Type string `json:"type"` | ||
AccountId string `json:"accountId"` | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
CreatedOn *int `json:"createdOn,omitempty"` | ||
UpdatedOn *int `json:"updatedOn,omitempty"` | ||
} | ||
|
||
type TxMatchRule struct { | ||
AgentType string `json:"agentType"` | ||
Type string `json:"type"` | ||
TxCustomRule *TxCustomRule `json:"txCustomRule"` | ||
} | ||
|
||
type TxCustomRule struct { | ||
Type string `json:"type"` | ||
TxEntryPointType string `json:"txEntryPointType"` | ||
MatchConditions []*MatchCondition `json:"matchConditions"` | ||
} | ||
|
||
type MatchCondition struct { | ||
Type string `json:"type"` | ||
HttpMatch *HttpMatch `json:"httpMatch"` | ||
} | ||
|
||
type HttpMatch struct { | ||
Uri *Uri `json:"uri"` | ||
HttpMethod string `json:"httpMethod"` | ||
} | ||
|
||
type Uri struct { | ||
Type string `json:"type"` | ||
MatchStrings []interface{} `json:"matchStrings"` | ||
} |
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,35 @@ | ||
{ | ||
"type": "TX_MATCH_RULE", | ||
"enabled": true, | ||
"priority": 1, | ||
"agentType": "NODE_JS_SERVER", | ||
"summary": { | ||
"type": "com.appdynamics.platform.services.configuration.impl.persistenceapi.model.ConfigRuleEntity", | ||
"accountId": "ad14e72e-da84-11ea-87d0-0242ac130003", | ||
"id": "", | ||
"name": "test", | ||
"description": "test description" | ||
}, | ||
"txMatchRule": { | ||
"agentType": "NODE_JS_SERVER", | ||
"type": "CUSTOM", | ||
"txCustomRule": { | ||
"type": "INCLUDE", | ||
"txEntryPointType": "NODEJS_WEB", | ||
"matchConditions": [ | ||
{ | ||
"type": "HTTP", | ||
"httpMatch": { | ||
"uri": { | ||
"type": "EQUALS", | ||
"matchStrings": [ | ||
"/bob" | ||
] | ||
}, | ||
"httpMethod": "POST" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
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,12 @@ | ||
{ | ||
"resultType": "SUCCESS", | ||
"successes": [ | ||
{ | ||
"summary": { | ||
"id": "878bdfc0-da7b-11ea-87d0-0242ac130003", | ||
"type": "com.appdynamics.platform.services.configuration.impl.persistenceapi.model.ConfigRuleEntity", | ||
"accountId": "8c469528-da7b-11ea-87d0-0242ac130003" | ||
} | ||
} | ||
] | ||
} |
Oops, something went wrong.