diff --git a/alerts/alerts_test.go b/alerts/alerts_test.go index cfc9e4a..6bce393 100644 --- a/alerts/alerts_test.go +++ b/alerts/alerts_test.go @@ -9,8 +9,6 @@ import ( "testing" ) - - var ( mux *http.ServeMux server *httptest.Server @@ -53,7 +51,7 @@ func createValidAlert() alerts.CreateAlertType { Filter: "", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, @@ -77,7 +75,7 @@ func createUpdateAlert() alerts.CreateAlertType { Filter: "", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, diff --git a/alerts/client_alerts.go b/alerts/client_alerts.go index fb8dd14..6a323d5 100644 --- a/alerts/client_alerts.go +++ b/alerts/client_alerts.go @@ -53,7 +53,7 @@ const ( fldTitle string = "title" fldValueAggregationField string = "valueAggregationField" fldValueAggregationType string = "valueAggregationType" - fldTags string = "tags" + fldTags string = "tags" ) type CreateAlertType struct { @@ -71,7 +71,7 @@ type CreateAlertType struct { Title string ValueAggregationField interface{} ValueAggregationType string - Tags []string + Tags []string } type AlertType struct { @@ -96,7 +96,7 @@ type AlertType struct { Title string ValueAggregationField interface{} ValueAggregationType string - Tags []string + Tags []string } type SeverityThresholdType struct { @@ -121,7 +121,7 @@ func jsonAlertToAlert(jsonAlert map[string]interface{}) AlertType { Threshold: int(jsonAlert[fldThreshold].(float64)), Title: jsonAlert[fldTitle].(string), ValueAggregationType: jsonAlert[fldValueAggregationType].(string), - Tags: []string{}, + Tags: []string{}, } if jsonAlert[fldGroupByAggregationFields] != nil { diff --git a/alerts/client_alerts_create.go b/alerts/client_alerts_create.go index 2280e3c..a608568 100644 --- a/alerts/client_alerts_create.go +++ b/alerts/client_alerts_create.go @@ -118,6 +118,5 @@ func (c *AlertsClient) CreateAlert(alert CreateAlertType) (*AlertType, error) { retVal := jsonAlertToAlert(jsonResponse) - return &retVal, nil } diff --git a/alerts/create_alerts_integration_test.go b/alerts/create_alerts_integration_test.go index e48b260..5501c2c 100644 --- a/alerts/create_alerts_integration_test.go +++ b/alerts/create_alerts_integration_test.go @@ -20,7 +20,7 @@ func TestIntegrationAlerts_CreateAlert(t *testing.T) { Filter: "", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, @@ -33,7 +33,7 @@ func TestIntegrationAlerts_CreateAlert(t *testing.T) { ValueAggregationField: nil, GroupByAggregationFields: []interface{}{"my_field"}, AlertNotificationEndpoints: []interface{}{}, - Tags: []string{"some", "words"}, + Tags: []string{"some", "words"}, }) time.Sleep(3 * time.Second) @@ -54,7 +54,7 @@ func TestIntegrationAlerts_CreateAlertWithFilter(t *testing.T) { Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, @@ -87,7 +87,7 @@ func TestIntegrationAlerts_CreateAlertInvalidFilter(t *testing.T) { Filter: "Invalid Filter", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, @@ -118,7 +118,7 @@ func TestIntegrationAlerts_CreateAlertInvalidAggregationType(t *testing.T) { Filter: "", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, @@ -149,7 +149,7 @@ func TestIntegrationAlerts_CreateAlertInvaldValueAggregationField(t *testing.T) Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, @@ -180,7 +180,7 @@ func TestIntegrationAlerts_CreateAlertInvalidValueAggregationTypeNone(t *testing Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, @@ -211,7 +211,7 @@ func TestIntegrationAlerts_CreateAlertInvalidValueAggregationTypeCount(t *testin Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, @@ -242,7 +242,7 @@ func TestIntegrationAlerts_CreateAlertNoNotifications(t *testing.T) { Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, @@ -273,7 +273,7 @@ func TestIntegrationAlerts_CreateAlertNoQueryString(t *testing.T) { Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, @@ -304,7 +304,7 @@ func TestIntegrationAlerts_CreateAlertInvalidSeverity(t *testing.T) { Filter: "{\"bool\":{\"must\":[{\"match\":{\"type\":\"mytype\"}}],\"must_not\":[]}}", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { "TEST", 10, }, diff --git a/alerts/create_alerts_test.go b/alerts/create_alerts_test.go index 3e11c4b..42f49dd 100644 --- a/alerts/create_alerts_test.go +++ b/alerts/create_alerts_test.go @@ -58,7 +58,7 @@ func TestAlerts_CreateAlert(t *testing.T) { ValueAggregationField: nil, GroupByAggregationFields: []interface{}{"my_field"}, AlertNotificationEndpoints: []interface{}{}, - Tags: []string{"some", "words"}, + Tags: []string{"some", "words"}, } alert, err := underTest.CreateAlert(testAlert) diff --git a/alerts/delete_alerts_integration_test.go b/alerts/delete_alerts_integration_test.go index 590e6d2..e146042 100644 --- a/alerts/delete_alerts_integration_test.go +++ b/alerts/delete_alerts_integration_test.go @@ -22,7 +22,7 @@ func TestIntegrationAlerts_DeleteAlert(t *testing.T) { Filter: "", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, diff --git a/alerts/get_alerts_integration_test.go b/alerts/get_alerts_integration_test.go index 9aa6c83..5391f93 100644 --- a/alerts/get_alerts_integration_test.go +++ b/alerts/get_alerts_integration_test.go @@ -18,7 +18,7 @@ func TestIntegrationAlerts_GetAlert(t *testing.T) { Filter: "", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, diff --git a/alerts/update_alerts_integration_test.go b/alerts/update_alerts_integration_test.go index d6aeb79..0fd0771 100644 --- a/alerts/update_alerts_integration_test.go +++ b/alerts/update_alerts_integration_test.go @@ -20,7 +20,7 @@ func TestIntegrationAlerts_UpdateAlert(t *testing.T) { Filter: "", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, @@ -43,7 +43,7 @@ func TestIntegrationAlerts_UpdateAlert(t *testing.T) { Filter: "", Operation: alerts.OperatorGreaterThan, SeverityThresholdTiers: []alerts.SeverityThresholdType{ - alerts.SeverityThresholdType{ + { alerts.SeverityHigh, 10, }, diff --git a/client/client.go b/client/client.go index 052ceb4..8c02f45 100644 --- a/client/client.go +++ b/client/client.go @@ -6,7 +6,6 @@ import ( "net/http" ) - const ( ERROR_CODE = "errorCode" ERROR_MESSAGE = "errorMessage" diff --git a/endpoints/client_endpoints.go b/endpoints/client_endpoints.go index a8d688c..4ff1525 100644 --- a/endpoints/client_endpoints.go +++ b/endpoints/client_endpoints.go @@ -33,12 +33,12 @@ const ( ) const ( - EndpointTypeSlack endpointType = "Slack" - EndpointTypeCustom endpointType = "Custom" - EndpointTypePagerDuty endpointType = "PagerDuty" - EndpointTypeBigPanda endpointType = "BigPanda" - EndpointTypeDataDog endpointType = "Datadog" - EndpointTypeVictorOps endpointType = "VictorOps" + EndpointTypeSlack endpointType = "slack" + EndpointTypeCustom endpointType = "custom" + EndpointTypePagerDuty endpointType = "pagerduty" + EndpointTypeBigPanda endpointType = "bigpanda" + EndpointTypeDataDog endpointType = "datadog" + EndpointTypeVictorOps endpointType = "victorops" ) type ( @@ -65,7 +65,7 @@ type Endpoint struct { } func jsonEndpointToEndpoint(jsonEndpoint map[string]interface{}) Endpoint { - t := jsonEndpoint[fldEndpointType].(string) + t := strings.ToLower(jsonEndpoint[fldEndpointType].(string)) endpoint := Endpoint{ Id: int64(jsonEndpoint[fldEndpointId].(float64)), diff --git a/sub_accounts/client_sub_account.go b/sub_accounts/client_sub_account.go index e0b3e01..83f5961 100644 --- a/sub_accounts/client_sub_account.go +++ b/sub_accounts/client_sub_account.go @@ -9,11 +9,11 @@ import ( const ( subAccountServiceEndpoint = "%s/v1/account-management/time-based-accounts" - loggerName = "logzio-client" + loggerName = "logzio-client" ) const ( - fldAccountId string = "accountId" //required + fldAccountId string = "accountId" //required fldEmail string = "email" //required fldAccountName string = "accountName" //required fldMaxDailyGB string = "maxDailyGB" @@ -42,33 +42,34 @@ type SubAccount struct { } type SubAccountRelation struct { - OwnerAccountId int64 `json:"ownerAccountId"` - SubAccountId int64 `json:"subAccountId"` - Searchable bool `json:"searchable"` - Accessible bool `json:"accessible"` - CreatedDate int64 `json:"createdDate"` - LastUpdatedDate int64 `json:"lastUpdatedDate"` - LastUpdaterUserId int64 `json:"lastUpdaterUserId"` - Type string `json:"type"` + OwnerAccountId int64 `json:"ownerAccountId"` + SubAccountId int64 `json:"subAccountId"` + Searchable bool `json:"searchable"` + Accessible bool `json:"accessible"` + CreatedDate int64 `json:"createdDate"` + LastUpdatedDate int64 `json:"lastUpdatedDate"` + LastUpdaterUserId int64 `json:"lastUpdaterUserId"` + Type string `json:"type"` } type Account struct { - AccountId int64 `json:"accountId"` - AccountToken string `json:"accountToken"` - AccountName string `json:"accountName"` - Active bool `json:"active"` - EsIndexPrefix string `json:"esIndexPrefix"` - MaxDailyGB int64 `json:"maxDailyGB"` - RetentionDays int64 `json:"retentionDays"` + AccountId int64 `json:"accountId"` + AccountToken string `json:"accountToken"` + AccountName string `json:"accountName"` + Active bool `json:"active"` + EsIndexPrefix string `json:"esIndexPrefix"` + MaxDailyGB int64 `json:"maxDailyGB"` + RetentionDays int64 `json:"retentionDays"` } type SubAccountDetailed struct { - SubAccountRelation SubAccountRelation `json:"subAccountRelation"` - Account Account `json:"account"` - SharingObjectAccounts []interface{} `json:"sharingObjectsAccounts"` - UtilizationSettings map[string]interface{} `json:"utilizationSettings"` - DailyUsagesList map[string]interface{} `json:"dailyUsagesList"` - DocSizeSetting bool `json:"docSizeSetting"`} + SubAccountRelation SubAccountRelation `json:"subAccountRelation"` + Account Account `json:"account"` + SharingObjectAccounts []interface{} `json:"sharingObjectsAccounts"` + UtilizationSettings map[string]interface{} `json:"utilizationSettings"` + DailyUsagesList map[string]interface{} `json:"dailyUsagesList"` + DocSizeSetting bool `json:"docSizeSetting"` +} type SubAccountCreate struct { Email string @@ -86,7 +87,7 @@ type SubAccountCreate struct { type SubAccountClient struct { *client.Client - logger hclog.Logger + logger hclog.Logger } // Creates a new entry point into the sub-account functions, accepts the user's logz.io API token and account Id @@ -110,10 +111,14 @@ func New(apiToken string, baseUrl string) (*SubAccountClient, error) { } func jsonToSubAccount(json map[string]interface{}) SubAccount { + var maxDailyGB float32 = 0 + if json[fldMaxDailyGB] != nil { + maxDailyGB = float32(json[fldMaxDailyGB].(float64)) + } subAccount := SubAccount{ Id: int64(json[fldAccountId].(float64)), AccountName: json[fldAccountName].(string), - MaxDailyGB: float32(json[fldMaxDailyGB].(float64)), + MaxDailyGB: maxDailyGB, RetentionDays: int32(json[fldRetentionDays].(float64)), Searchable: json[fldSearchable].(bool), Accessible: json[fldAccessible].(bool), @@ -122,18 +127,17 @@ func jsonToSubAccount(json map[string]interface{}) SubAccount { UtilizationSettings: json[fldUtilizationSettings].(map[string]interface{}), } - if json[fldUtilizationSettings] != nil { - subAccount.UtilizationSettings = json[fldUtilizationSettings].(map[string]interface{}) - for key, value := range subAccount.UtilizationSettings { - if value == nil { - delete(subAccount.UtilizationSettings, key) - } + if json[fldUtilizationSettings] != nil { + subAccount.UtilizationSettings = json[fldUtilizationSettings].(map[string]interface{}) + for key, value := range subAccount.UtilizationSettings { + if value == nil { + delete(subAccount.UtilizationSettings, key) } } + } return subAccount } - func jsonToDetailedSubAccount(jsonMap map[string]interface{}) (*SubAccountDetailed, error) { jsonBytes, err := json.Marshal(jsonMap) if err != nil { @@ -145,4 +149,4 @@ func jsonToDetailedSubAccount(jsonMap map[string]interface{}) (*SubAccountDetail return nil, err } return &subAccount, nil -} \ No newline at end of file +} diff --git a/sub_accounts/client_sub_account_create.go b/sub_accounts/client_sub_account_create.go index 5dc90d0..66ad618 100644 --- a/sub_accounts/client_sub_account_create.go +++ b/sub_accounts/client_sub_account_create.go @@ -55,16 +55,15 @@ func (c *SubAccountClient) CreateSubAccount(subAccount SubAccountCreate) (*SubAc } createdSubAccount := SubAccount{ - Id: int64(target["accountId"].(float64)), - MaxDailyGB: subAccount.MaxDailyGB, - AccountName: subAccount.AccountName, - UtilizationSettings: subAccount.UtilizationSettings, - DocSizeSetting: subAccount.DocSizeSetting, - Accessible: subAccount.Accessible, - Searchable: subAccount.Searchable, - RetentionDays: subAccount.RetentionDays, - SharingObjectAccounts: sharingAccounts, - + Id: int64(target["accountId"].(float64)), + MaxDailyGB: subAccount.MaxDailyGB, + AccountName: subAccount.AccountName, + UtilizationSettings: subAccount.UtilizationSettings, + DocSizeSetting: subAccount.DocSizeSetting, + Accessible: subAccount.Accessible, + Searchable: subAccount.Searchable, + RetentionDays: subAccount.RetentionDays, + SharingObjectAccounts: sharingAccounts, } return &createdSubAccount, nil } diff --git a/sub_accounts/client_sub_account_get.go b/sub_accounts/client_sub_account_get.go index 88b429d..05a3dc3 100644 --- a/sub_accounts/client_sub_account_get.go +++ b/sub_accounts/client_sub_account_get.go @@ -66,8 +66,7 @@ func (c *SubAccountClient) GetSubAccount(id int64) (*SubAccount, error) { return nil, err } - - pretty, err := json.MarshalIndent(target,""," ") + pretty, err := json.MarshalIndent(target, "", " ") if err != nil { c.logger.Error("Error parsing subaccount: ", err) } else { diff --git a/sub_accounts/client_sub_account_list_detailed.go b/sub_accounts/client_sub_account_list_detailed.go index 85b45c5..6c16a4b 100644 --- a/sub_accounts/client_sub_account_list_detailed.go +++ b/sub_accounts/client_sub_account_list_detailed.go @@ -67,7 +67,7 @@ func (c *SubAccountClient) DetailedSubAccounts() ([]SubAccountDetailed, error) { for _, jsonObject := range target { subAccount, err := jsonToDetailedSubAccount(jsonObject) if err != nil { - return nil, err + return nil, err } subAccountsDetailed = append(subAccountsDetailed, *subAccount) } diff --git a/sub_accounts/sub_account_get_detailed_test.go b/sub_accounts/sub_account_get_detailed_test.go index e381215..c4d788b 100644 --- a/sub_accounts/sub_account_get_detailed_test.go +++ b/sub_accounts/sub_account_get_detailed_test.go @@ -1,11 +1,11 @@ package sub_accounts_test import ( -"fmt" -"github.com/stretchr/testify/assert" -"net/http" -"strconv" -"testing" + "fmt" + "github.com/stretchr/testify/assert" + "net/http" + "strconv" + "testing" ) func TestSubAccount_GetDetailedValidSubAccount(t *testing.T) { diff --git a/sub_accounts/sub_account_get_test.go b/sub_accounts/sub_account_get_test.go index c4a7a30..c2618eb 100644 --- a/sub_accounts/sub_account_get_test.go +++ b/sub_accounts/sub_account_get_test.go @@ -1,11 +1,11 @@ package sub_accounts_test import ( -"fmt" -"github.com/stretchr/testify/assert" -"net/http" -"strconv" -"testing" + "fmt" + "github.com/stretchr/testify/assert" + "net/http" + "strconv" + "testing" ) func TestSubAccount_GetValidSubAccount(t *testing.T) { diff --git a/users/client_user_delete.go b/users/client_user_delete.go index 5f3a59d..9d43847 100644 --- a/users/client_user_delete.go +++ b/users/client_user_delete.go @@ -11,11 +11,11 @@ import ( ) const ( - deleteUserServiceUrl = userServiceEndpoint + "/%d" - deleteUserServiceMethod = "DELETE" - + deleteUserServiceUrl = userServiceEndpoint + "/%d" + deleteUserServiceMethod = "DELETE" ) -var deleteUserServiceSuccess = []int {http.StatusOK, http.StatusNoContent} + +var deleteUserServiceSuccess = []int{http.StatusOK, http.StatusNoContent} func validateDeleteUserRequest(u User) (error, bool) { return nil, true diff --git a/users/user_test.go b/users/user_test.go index f7d3107..5d11553 100644 --- a/users/user_test.go +++ b/users/user_test.go @@ -65,4 +65,4 @@ func TestNewWithEmptyApiToken(t *testing.T) { t.Fatalf("The expected error message to be '%s' but was '%s'", "API token not defined", err.Error()) } -} \ No newline at end of file +} diff --git a/utils.go b/utils.go index 049b4f7..fd3f0d7 100644 --- a/utils.go +++ b/utils.go @@ -9,7 +9,8 @@ import ( ) const ( - serviceSuccess int = http.StatusOK + serviceSuccess int = http.StatusOK + serviceNoContest int = http.StatusNoContent // This is like StatusOK with no body in response ) func AddHttpHeaders(apiToken string, req *http.Request) { @@ -43,7 +44,7 @@ func CreateHttpRequest(req *http.Request) (map[string]interface{}, error) { } defer resp.Body.Close() jsonBytes, err := ioutil.ReadAll(resp.Body) - if !CheckValidStatus(resp, []int{serviceSuccess}) { + if !CheckValidStatus(resp, []int{serviceSuccess, serviceNoContest}) { return nil, fmt.Errorf("%d %s", resp.StatusCode, jsonBytes) } var target map[string]interface{}