Skip to content

Commit

Permalink
Merge pull request #12 from iLert/feature/improve-data-source-search
Browse files Browse the repository at this point in the history
Feature/improve-data-source-search
  • Loading branch information
STLVRTX authored Sep 6, 2022
2 parents fd6c2df + d27b383 commit 7554192
Show file tree
Hide file tree
Showing 14 changed files with 424 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
examples/test

# Test binary, built with `go test -c`
*.test
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 04.09.2022, Version 2.2.0

- add search by name for all entities

## 30.08.2022, Version 2.1.1

- add various validation lists to schedule
Expand Down
38 changes: 38 additions & 0 deletions alertaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,44 @@ func (c *Client) GetAlertActions(input *GetAlertActionsInput) (*GetAlertActionsO
return &GetAlertActionsOutput{AlertActions: alertActions}, nil
}

// SearchAlertActionInput represents the input of a SearchAlertAction operation.
type SearchAlertActionInput struct {
_ struct{}
AlertActionName *string
}

// SearchAlertActionOutput represents the output of a SearchAlertAction operation.
type SearchAlertActionOutput struct {
_ struct{}
AlertAction *AlertAction
}

// SearchAlertAction gets the alertAction with specified name.
func (c *Client) SearchAlertAction(input *SearchAlertActionInput) (*SearchAlertActionOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.AlertActionName == nil {
return nil, errors.New("alert action name is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.alertActions, *input.AlertActionName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}

alertAction := &AlertAction{}
err = json.Unmarshal(resp.Body(), alertAction)
if err != nil {
return nil, err
}

return &SearchAlertActionOutput{AlertAction: alertAction}, nil
}

// UpdateAlertActionInput represents the input of a UpdateAlertAction operation.
type UpdateAlertActionInput struct {
_ struct{}
Expand Down
38 changes: 38 additions & 0 deletions alertsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,44 @@ func (c *Client) GetAlertSources(input *GetAlertSourcesInput) (*GetAlertSourcesO
return &GetAlertSourcesOutput{AlertSources: alertSources}, nil
}

// SearchAlertSourceInput represents the input of a SearchAlertSource operation.
type SearchAlertSourceInput struct {
_ struct{}
AlertSourceName *string
}

// SearchAlertSourceOutput represents the output of a SearchAlertSource operation.
type SearchAlertSourceOutput struct {
_ struct{}
AlertSource *AlertSource
}

// SearchAlertSource gets the alertSource with specified name.
func (c *Client) SearchAlertSource(input *SearchAlertSourceInput) (*SearchAlertSourceOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.AlertSourceName == nil {
return nil, errors.New("alert source name is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.alertSources, *input.AlertSourceName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}

alertSource := &AlertSource{}
err = json.Unmarshal(resp.Body(), alertSource)
if err != nil {
return nil, err
}

return &SearchAlertSourceOutput{AlertSource: alertSource}, nil
}

// UpdateAlertSourceInput represents the input of a UpdateAlertSource operation.
type UpdateAlertSourceInput struct {
_ struct{}
Expand Down
38 changes: 38 additions & 0 deletions connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,44 @@ func (c *Client) GetConnectors(input *GetConnectorsInput) (*GetConnectorsOutput,
return &GetConnectorsOutput{Connectors: connectors}, nil
}

// SearchConnectorInput represents the input of a SearchConnector operation.
type SearchConnectorInput struct {
_ struct{}
ConnectorName *string
}

// SearchConnectorOutput represents the output of a SearchConnector operation.
type SearchConnectorOutput struct {
_ struct{}
Connector *Connector
}

// SearchConnector gets the connector with specified name.
func (c *Client) SearchConnector(input *SearchConnectorInput) (*SearchConnectorOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.ConnectorName == nil {
return nil, errors.New("Connector name is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.connectors, *input.ConnectorName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}

connector := &Connector{}
err = json.Unmarshal(resp.Body(), connector)
if err != nil {
return nil, err
}

return &SearchConnectorOutput{Connector: connector}, nil
}

// UpdateConnectorInput represents the input of a UpdateConnector operation.
type UpdateConnectorInput struct {
_ struct{}
Expand Down
38 changes: 38 additions & 0 deletions escalationpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,44 @@ func (c *Client) GetEscalationPolicies(input *GetEscalationPoliciesInput) (*GetE
return &GetEscalationPoliciesOutput{EscalationPolicies: escalationPolicies}, nil
}

// SearchEscalationPolicyInput represents the input of a SearchEscalationPolicy operation.
type SearchEscalationPolicyInput struct {
_ struct{}
EscalationPolicyName *string
}

// SearchEscalationPolicyOutput represents the output of a SearchEscalationPolicy operation.
type SearchEscalationPolicyOutput struct {
_ struct{}
EscalationPolicy *EscalationPolicy
}

// SearchEscalationPolicy gets the escalationPolicy with specified name.
func (c *Client) SearchEscalationPolicy(input *SearchEscalationPolicyInput) (*SearchEscalationPolicyOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.EscalationPolicyName == nil {
return nil, errors.New("escalation policy name is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.escalationPolicies, *input.EscalationPolicyName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}

escalationPolicy := &EscalationPolicy{}
err = json.Unmarshal(resp.Body(), escalationPolicy)
if err != nil {
return nil, err
}

return &SearchEscalationPolicyOutput{EscalationPolicy: escalationPolicy}, nil
}

// UpdateEscalationPolicyInput represents the input of a UpdateEscalationPolicy operation.
type UpdateEscalationPolicyInput struct {
_ struct{}
Expand Down
38 changes: 38 additions & 0 deletions incidenttemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,44 @@ func (c *Client) GetIncidentTemplate(input *GetIncidentTemplateInput) (*GetIncid
return &GetIncidentTemplateOutput{IncidentTemplate: incidentTemplate}, nil
}

// SearchIncidentTemplateInput represents the input of a SearchIncidentTemplate operation.
type SearchIncidentTemplateInput struct {
_ struct{}
IncidentTemplateName *string
}

// SearchIncidentTemplateOutput represents the output of a SearchIncidentTemplate operation.
type SearchIncidentTemplateOutput struct {
_ struct{}
IncidentTemplate *IncidentTemplate
}

// SearchIncidentTemplate gets the incidentTemplate with specified name.
func (c *Client) SearchIncidentTemplate(input *SearchIncidentTemplateInput) (*SearchIncidentTemplateOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.IncidentTemplateName == nil {
return nil, errors.New("incident template name is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.incidentTemplates, *input.IncidentTemplateName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}

incidentTemplate := &IncidentTemplate{}
err = json.Unmarshal(resp.Body(), incidentTemplate)
if err != nil {
return nil, err
}

return &SearchIncidentTemplateOutput{IncidentTemplate: incidentTemplate}, nil
}

// UpdateIncidentTemplateInput represents the input of a UpdateIncidentTemplate operation.
type UpdateIncidentTemplateInput struct {
_ struct{}
Expand Down
38 changes: 38 additions & 0 deletions schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,44 @@ func (c *Client) GetScheduleUserOnCall(input *GetScheduleUserOnCallInput) (*GetS
return &GetScheduleUserOnCallOutput{Shift: shift}, nil
}

// SearchScheduleInput represents the input of a SearchSchedule operation.
type SearchScheduleInput struct {
_ struct{}
ScheduleName *string
}

// SearchScheduleOutput represents the output of a SearchSchedule operation.
type SearchScheduleOutput struct {
_ struct{}
Schedule *Schedule
}

// SearchSchedule gets the schedule with specified name.
func (c *Client) SearchSchedule(input *SearchScheduleInput) (*SearchScheduleOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.ScheduleName == nil {
return nil, errors.New("schedule name is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.schedules, *input.ScheduleName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}

schedule := &Schedule{}
err = json.Unmarshal(resp.Body(), schedule)
if err != nil {
return nil, err
}

return &SearchScheduleOutput{Schedule: schedule}, nil
}

// UpdateScheduleInput represents the input of a UpdateSchedule operation.
type UpdateScheduleInput struct {
_ struct{}
Expand Down
38 changes: 38 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,44 @@ func (c *Client) GetServiceSubscribers(input *GetServiceSubscribersInput) (*GetS
return &GetServiceSubscribersOutput{Subscribers: subscribers}, nil
}

// SearchServiceInput represents the input of a SearchService operation.
type SearchServiceInput struct {
_ struct{}
ServiceName *string
}

// SearchServiceOutput represents the output of a SearchService operation.
type SearchServiceOutput struct {
_ struct{}
Service *Service
}

// SearchService gets the service with specified name.
func (c *Client) SearchService(input *SearchServiceInput) (*SearchServiceOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.ServiceName == nil {
return nil, errors.New("service name is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.services, *input.ServiceName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}

service := &Service{}
err = json.Unmarshal(resp.Body(), service)
if err != nil {
return nil, err
}

return &SearchServiceOutput{Service: service}, nil
}

// UpdateServiceInput represents the input of a UpdateService operation.
type UpdateServiceInput struct {
_ struct{}
Expand Down
38 changes: 38 additions & 0 deletions statuspage.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,44 @@ func (c *Client) GetStatusPageSubscribers(input *GetStatusPageSubscribersInput)
return &GetStatusPageSubscribersOutput{Subscribers: subscribers}, nil
}

// SearchStatusPageInput represents the input of a SearchStatusPage operation.
type SearchStatusPageInput struct {
_ struct{}
StatusPageName *string
}

// SearchStatusPageOutput represents the output of a SearchStatusPage operation.
type SearchStatusPageOutput struct {
_ struct{}
StatusPage *StatusPage
}

// SearchStatusPage gets the statusPage with specified name.
func (c *Client) SearchStatusPage(input *SearchStatusPageInput) (*SearchStatusPageOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.StatusPageName == nil {
return nil, errors.New("status page name is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.statusPages, *input.StatusPageName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}

statusPage := &StatusPage{}
err = json.Unmarshal(resp.Body(), statusPage)
if err != nil {
return nil, err
}

return &SearchStatusPageOutput{StatusPage: statusPage}, nil
}

// UpdateStatusPageInput represents the input of a UpdateStatusPage operation.
type UpdateStatusPageInput struct {
_ struct{}
Expand Down
Loading

0 comments on commit 7554192

Please sign in to comment.