Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with github actions, modernize tooling #60

Merged
merged 4 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/golang-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Golang Build

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
go-version: ["1.18", "1.19", "1.20"]

steps:
- uses: actions/checkout@v3
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Building
run: go build -v ./...
- name: Running golangci-lint
uses: golangci/golangci-lint-action@v3
- name: Testing
run: go test -v ./...
43 changes: 0 additions & 43 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go-ovh
Lightweight Go wrapper around OVH's APIs. Handles all the hard work including credential creation and requests signing.

[![GoDoc](https://godoc.org/github.com/ovh/go-ovh/go-ovh?status.svg)](http://godoc.org/github.com/ovh/go-ovh/ovh)
[![Build Status](https://travis-ci.org/ovh/go-ovh.svg?branch=master)](https://travis-ci.org/ovh/go-ovh)
[![Build Status](https://github.com/ovh/go-ovh/actions/workflows/golang-build.yaml/badge.svg?branch=master)](https://github.com/ovh/go-ovh/actions?query=workflow:golang-build)
[![Coverage Status](https://coveralls.io/repos/github/ovh/go-ovh/badge.svg?branch=master)](https://coveralls.io/github/ovh/go-ovh?branch=master)
[![Go Report Card](https://goreportcard.com/badge/ovh/go-ovh)](http://goreportcard.com/report/ovh/go-ovh)

Expand Down Expand Up @@ -40,7 +40,7 @@ func main() {

## Installation

The Golang wrapper has been tested with Golang 1.5+. It may worker with older versions although it has not been tested.
The Golang wrapper has been tested with Golang 1.18+. It may worker with older versions although it has not been tested.

To use it, just include it to your ``import`` and run ``go get``:

Expand Down
10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
module github.com/ovh/go-ovh

go 1.12
go 1.18

require (
// required by gopkg.in/ini.v1 unit tests...
github.com/smartystreets/goconvey v1.6.4 // indirect
gopkg.in/ini.v1 v1.57.0
)
require gopkg.in/ini.v1 v1.67.0

require github.com/stretchr/testify v1.8.2 // indirect
33 changes: 18 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/ini.v1 v1.57.0 h1:9unxIsFcTt4I55uWluz+UmL95q4kdJ0buvQ1ZIqVQww=
gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
19 changes: 8 additions & 11 deletions ovh/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@ var (

// currentUserHome attempts to get current user's home directory
func currentUserHome() (string, error) {
userHome := ""
usr, err := user.Current()
if err != nil {
// Fallback by trying to read $HOME
userHome = os.Getenv("HOME")
if userHome != "" {
err = nil
if userHome := os.Getenv("HOME"); userHome != "" {
return userHome, nil
}
} else {
userHome = usr.HomeDir
return "", err
}
return userHome, nil

return usr.HomeDir, nil
}

// appendConfigurationFile only if it exists. We need to do this because
// ini package will fail to load configuration at all if a configuration
// file is missing. This is racy, but better than always failing.
func appendConfigurationFile(cfg *ini.File, path string) {
if file, err := os.Open(path); err == nil {
file.Close()
cfg.Append(path)
defer file.Close()
_ = cfg.Append(path)
}
}

Expand All @@ -57,7 +55,6 @@ func appendConfigurationFile(cfg *ini.File, path string) {
// - ./ovh.conf
// - $HOME/.ovh.conf
// - /etc/ovh.conf
//
func (c *Client) loadConfig(endpointName string) error {
// Load configuration files by order of increasing priority. All configuration
// files are optional. Only load file from user home if home could be resolve
Expand Down Expand Up @@ -107,7 +104,7 @@ func (c *Client) loadConfig(endpointName string) error {
return nil
}

// getConfigValue returns the value of OVH_<NAME> or ``name`` value from ``section``. If
// getConfigValue returns the value of OVH_<NAME> or "name" value from "section". If
// the value could not be read from either env or any configuration files, return 'def'
func getConfigValue(cfg *ini.File, section, name, def string) string {
// Attempt to load from environment
Expand Down
45 changes: 24 additions & 21 deletions ovh/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,30 @@ func TestConfigFromFiles(t *testing.T) {
// This is a simple way to test precedence

// Prepare
ioutil.WriteFile(systemConfigPath, []byte(`
_ = ioutil.WriteFile(systemConfigPath, []byte(`
[ovh-eu]
application_key=system
application_secret=system
consumer_key=system
`), 0660)

ioutil.WriteFile(home+userConfigPath, []byte(`
_ = ioutil.WriteFile(home+userConfigPath, []byte(`
[ovh-eu]
application_secret=user
consumer_key=user
`), 0660)

ioutil.WriteFile(localConfigPath, []byte(`
_ = ioutil.WriteFile(localConfigPath, []byte(`
[ovh-eu]
consumer_key=local
`), 0660)

// Clear
defer ioutil.WriteFile(systemConfigPath, []byte(``), 0660)
defer ioutil.WriteFile(home+userConfigPath, []byte(``), 0660)
defer ioutil.WriteFile(localConfigPath, []byte(``), 0660)
t.Cleanup(func() {
_ = ioutil.WriteFile(systemConfigPath, []byte(``), 0660)
_ = ioutil.WriteFile(home+userConfigPath, []byte(``), 0660)
_ = ioutil.WriteFile(localConfigPath, []byte(``), 0660)
})

// Test
client := Client{}
Expand All @@ -82,15 +84,17 @@ func TestConfigFromOnlyOneFile(t *testing.T) {

// Prepare
os.Remove(systemConfigPath)
ioutil.WriteFile(home+userConfigPath, []byte(`
_ = ioutil.WriteFile(home+userConfigPath, []byte(`
[ovh-eu]
application_key=user
application_secret=user
consumer_key=user
`), 0660)

// Clear
defer ioutil.WriteFile(home+userConfigPath, []byte(``), 0660)
t.Cleanup(func() {
_ = ioutil.WriteFile(home+userConfigPath, []byte(``), 0660)
})

// Test
client := Client{}
Expand All @@ -113,24 +117,21 @@ consumer_key=user

func TestConfigFromEnv(t *testing.T) {
// Prepare
ioutil.WriteFile(systemConfigPath, []byte(`
_ = ioutil.WriteFile(systemConfigPath, []byte(`
[ovh-eu]
application_key=fail
application_secret=fail
consumer_key=fail
`), 0660)

defer ioutil.WriteFile(systemConfigPath, []byte(``), 0660)
os.Setenv("OVH_ENDPOINT", "ovh-eu")
os.Setenv("OVH_APPLICATION_KEY", "env")
os.Setenv("OVH_APPLICATION_SECRET", "env")
os.Setenv("OVH_CONSUMER_KEY", "env")
t.Cleanup(func() {
_ = ioutil.WriteFile(systemConfigPath, []byte(``), 0660)
})

// Clear
defer os.Unsetenv("OVH_ENDPOINT")
defer os.Unsetenv("OVH_APPLICATION_KEY")
defer os.Unsetenv("OVH_APPLICATION_SECRET")
defer os.Unsetenv("OVH_CONSUMER_KEY")
t.Setenv("OVH_ENDPOINT", "ovh-eu")
t.Setenv("OVH_APPLICATION_KEY", "env")
t.Setenv("OVH_APPLICATION_SECRET", "env")
t.Setenv("OVH_CONSUMER_KEY", "env")

// Test
client := Client{}
Expand Down Expand Up @@ -183,7 +184,7 @@ func TestConfigFromArgs(t *testing.T) {

func TestEndpoint(t *testing.T) {
// Prepare
ioutil.WriteFile(systemConfigPath, []byte(`
_ = ioutil.WriteFile(systemConfigPath, []byte(`
[ovh-eu]
application_key=ovh
application_secret=ovh
Expand All @@ -196,7 +197,9 @@ consumer_key=example.com
`), 0660)

// Clear
defer ioutil.WriteFile(systemConfigPath, []byte(``), 0660)
t.Cleanup(func() {
_ = ioutil.WriteFile(systemConfigPath, []byte(``), 0660)
})

// Test: by name
client := Client{}
Expand Down
4 changes: 2 additions & 2 deletions ovh/ovh.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewClient(endpoint, appKey, appSecret, consumerKey string) (*Client, error)
AppSecret: appSecret,
ConsumerKey: consumerKey,
Client: &http.Client{},
Timeout: time.Duration(DefaultTimeout),
Timeout: DefaultTimeout,
}

// Get and check the configuration
Expand Down Expand Up @@ -369,7 +369,7 @@ func (c *Client) CallAPI(method, path string, reqBody, resType interface{}, need
// - full serialized request body
// - server current time (takes time delta into account)
//
// Context is used by http.Client to handle context cancelation
// Context is used by http.Client to handle context cancelation.
//
// Call will automatically assemble the target url from the endpoint
// configured in the client instance and the path argument. If the reqBody
Expand Down
4 changes: 2 additions & 2 deletions ovh/ovh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func APIMethodTester(t *testing.T, HTTPmethod string, body interface{}, expected
sleep := time.Duration(0)
var failureExpected bool
if cancel || contextTimeout {
sleep = time.Duration(2) * time.Second
sleep = 300 * time.Millisecond
failureExpected = true
}
ts, client := initMockServer(&InputRequest, 200, `"success"`, &InputRequestBody, sleep)
Expand Down Expand Up @@ -341,7 +341,7 @@ func TestGetResponse(t *testing.T) {
Body: ioutil.NopCloser(strings.NewReader(``)),
}, nil)
if err != nil {
t.Fatalf("UnmarshalResponse should not return an error when reponse is empty or target type is nil. Got %v", err)
t.Fatalf("UnmarshalResponse should not return an error when response is empty or target type is nil. Got %v", err)
}

// Error
Expand Down