Giter Club home page Giter Club logo

logzio_terraform_client's Introduction

Logz.io Terraform client library

Client library for Logz.io API, see below for supported endpoints.

The primary purpose of this library is to act as the API interface for the logz.io Terraform provider. To use it, you'll need to create an API token and provide it to the client library along with your logz.io regional API server address.

The library currently supports the following API endpoints:

Contributing

  1. Clone this repo locally.
  2. As this package uses Go modules, make sure you are outside of $GOPATH or you have the GO111MODULE=on environment variable set. Then run go get to pull down the dependencies.
  3. Use logzio_client.CallLogzioApi when you need to make a Logz.io API call.
  4. Use structs to represent the requests/responses body, rather than maps.
  5. Sample responses for tests should be under testdata/fixtures.
Run tests

go test -v -race ./...

Changelog

Exapnd to check old versions
  • v1.16.0
  • v1.15.0
  • v1.14.0
    • alerts_v2 - support new field schedule
  • v1.13.1
    • Add retry mechanism for requests.
  • v1.13.0
    • Bug fix - sub_accounts: field ReservedDailyGB in requests can be 0.
  • v1.12.0
    • Upgrade to Go 1.18.
    • Refactor users, adjust to the recent API fields.
    • Add field UserName to restore initiate request, to match recent API fields.
  • v1.11.0
  • v1.10.3
    • Bug fix - sub_accounts: omit maxDailyGb if needed.
  • v1.10.2
    • Bug fix - alerts_v2: allow sending with columns without sort.
  • v1.10.1
    • Bug fix - custom endpoint: allow empty string for Headers field.
  • v1.10.0
  • v1.9.1
    • Bug fix - adjust "not found" message to all resources.
  • v1.9.0
  • v1.8.0
    • sub_accounts:
      • Add flexible & reservedDailyGB.
      • Breaking changes: refactor resource.
    • endpoints:
      • Breaking changes: refactor resource.
      • Add new endpoint types (OpsGenie, ServiceNow, Microsoft Teams).
  • v1.7.0
  • v1.6.0
  • v1.5.3
    • Fix for sub account: return token & account id on Create.
  • v1.5.2
    • Fix custom endpoint -empty headers bug.
    • Allow empty array for sharing accounts in sub account.
  • v1.5.1
    • Fix alerts_v2 sort bug.
  • v1.5
    • Add alerts v2 compatibility.
  • v1.3.2
    • fix client custom endpoint headers bug
    • improve tests
  • v1.3
    • unnecessary resource updates bug fix.
    • support tags in alerts
  • v1.2
    • Add subaccount support

Trademark Disclaimer

Terraform is a trademark of HashiCorp, Inc.

logzio_terraform_client's People

Contributors

8naama avatar barakm avatar jonboydell avatar jonboydell-massive avatar mirii1994 avatar pengux avatar talhibner avatar yyyogev avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

logzio_terraform_client's Issues

Use go modules

Go modules has become the canonical way to handle dependencies in a Go project. I would be happy to add support for Go modules in this project.

GetSubAccount panics (since nil values are not validated before conversion)

Test code:

func Test(apiToken string, baseUrl string, subAccountNumber int64) error {
    var c *sub_accounts.SubAccountClient
	if len(apiToken) == 0 {
		fmt.Errorf("API token not defined")
	}
	if len(baseUrl) == 0 {
		fmt.Errorf("Base URL not defined")
	}
    c, _ =  sub_accounts.New(apiToken, baseUrl)

    subAccount, err := c.GetSubAccount(subAccountNumber)
	if err != nil {
		return err
	}
    fmt.Println("%s", subAccount.AccountName)
    return nil
}

Result:

panic: interface conversion: interface {} is nil, not float64

Root cause:
Not checking nil value when accessing json['key'] in function jsonToSubAccount (specifically in the field MaxDailyGB)
See the code below:

func jsonToSubAccount(json map[string]interface{}) SubAccount {
 
	subAccount := SubAccount{
		Id:                    int64(json[fldAccountId].(float64)),
		AccountName:           json[fldAccountName].(string),
		MaxDailyGB:            float32(json[fldMaxDailyGB].(float64)),  <---------- BUG ------------
		RetentionDays:         int32(json[fldRetentionDays].(float64)),
		Searchable:            json[fldSearchable].(bool),
		Accessible:            json[fldAccessible].(bool),
		DocSizeSetting:        json[fldDocSizeSetting].(bool),
		SharingObjectAccounts: json[fldSharingAccountObjects].([]interface{}),
		UtilizationSettings:   json[fldUtilizationSettings].(map[string]interface{}),
	}
....
}

Debug log:

{
	"accessible": true,
	"accountId": 12345,
	"accountName": "xxxxx",
	"docSizeSetting": true,
	"email": null,
	"isFlexible": true,
	"maxDailyGB": null,  <------------- The returned value ------------ 
	"reservedDailyGB": 0,
	"retentionDays": 14,
	"searchable": true,
	"sharingObjectsAccounts": [],
	"utilizationSettings": {
		"frequencyMinutes": 60,
		"utilizationEnabled": true
	}
}

The fix:
I was not able to push code even to side branch !
For all field need to validate values are NOT nil (in case of nil set some default):

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:            maxDailyGB,
		RetentionDays:         int32(json[fldRetentionDays].(float64)),
		Searchable:            json[fldSearchable].(bool),
		Accessible:            json[fldAccessible].(bool),
		DocSizeSetting:        json[fldDocSizeSetting].(bool),
		SharingObjectAccounts: json[fldSharingAccountObjects].([]interface{}),
		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)
				}
			}
		}
	return subAccount
}

create_alerts_list test failing

problem

  • create_alerts_list test failing

infos

github.com/jonboydell/logzio_client.(*Client).ListAlerts(0xc000041740, 0xc000018011, 0x24, 0x105e1e0, 0xc000041720, 0x851aebb9)
	/Users/jon.boydell/go/src/github.com/jonboydell/logzio_client/client_alerts_list.go:61 +0x12bd

done when

  • line 61 GroupByAggregationFields: jsonAlert["groupByAggregationFields"].([]interface{}), can be nil and needs to be dealt with outside the struct initialisation

subaccounts: add subaccounts support

create_alerts_list and create_alerts_get duplicate code

problem:

  • create_alerts_list and create_alerts_get duplicate code for unmarshalling an alert

proposed solution:

  • should either use some custom unmarshaller or be refactored into its own function

complete when:

  • duplicate code is removed

global: refactor packages

each "type" of API to be managed in it's own package, to prevent name space clashes, to compartmentalise the different APIs and to make testing simpler

endpoints : expose endpoint types

expose endpoint types consts publicly, so the client (of the client) can provide it's own mapping between type names (if it needs to)

  • slack C
  • slack U
  • custom C
  • custom U
  • pagerduty C
  • pagerduty U
  • bigpanda C
  • bigpanda U
  • datadog C
  • datadog U
  • victorops C
  • victorops U
  • R endpoint by id
  • R endpoint by name
  • list endpoints

Use a mock for tests

Currently, the tests seem to require a valid API token and is actually making requests against the Logz.io API. This makes it non-trivial to contribute to the project as it requires to have an Enterprise account just for running the tests. I suggest to use a mock for the tests and complement with integration tests which can do real requests against the API if desired.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.