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

Review and preparation of migration to github.com/ovh #2

Merged
merged 6 commits into from
Mar 22, 2016
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ before_install:
script:
- go vet ./...
- $HOME/gopath/bin/golint ./...
- $HOME/gopath/bin/goveralls -service=travis-ci
- $HOME/gopath/bin/goveralls -service=travis-ci ./...
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to govh
# Contributing to go-ovh

## Submitting Modifications:

Expand Down Expand Up @@ -49,8 +49,8 @@ git rebase upstream/master

## Licensing for new files:

govh is licensed under a (modified) BSD license. Anything contributed to
govh must be released under this license.
go-ovh is licensed under a (modified) BSD license. Anything contributed to
go-ovh must be released under this license.

When introducing a new file into the project, please make sure it has a
copyright header making clear under which license it''s being released.
Expand Down
88 changes: 58 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
govh
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/gregdel/govh?status.svg)](http://godoc.org/github.com/gregdel/govh)
[![Build Status](https://travis-ci.org/gregdel/govh.svg?branch=master)](https://travis-ci.org/gregdel/govh)
[![Coverage Status](https://coveralls.io/repos/gregdel/govh/badge.svg?branch=master&service=github)](https://coveralls.io/github/gregdel/govh?branch=master)
[![Go Report Card](http://goreportcard.com/badge/gregdel/govh)](http://goreportcard.com/report/gregdel/govh)
[![GoDoc](https://godoc.org/github.com/ovh/go-ovh/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/gregdel/ovh)
[![Coverage Status](https://coveralls.io/repos/ovh/go-ovh/badge.svg?branch=master&service=github)](https://coveralls.io/github/gregdel/ovh?branch=master)
[![Go Report Card](http://goreportcard.com/badge/ovh/go-ovh)](http://goreportcard.com/report/gregdel/ovh)

```go
package main

import (
"fmt"
"github.com/gregdel/govh"
"github.com/ovh/go-ovh/ovh"
)

// PartialMe holds the first name of the currently logged-in user.
Expand All @@ -27,7 +27,7 @@ type PartialMe struct {
func main() {
var me PartialMe

client, _ := govh.NewClient(
client, _ := ovh.NewClient(
"ovh-eu",
YOUR_APPLICATION_KEY,
YOUR_APPLICATION_SECRET,
Expand All @@ -47,7 +47,7 @@ To use it, just include it to your ``import`` and run ``go get``:
```go
import (
...
"github.com/gregdel/govh"
"github.com/ovh/go-ovh/ovh"
)
```

Expand Down Expand Up @@ -78,6 +78,17 @@ application_secret=my_application_secret
consumer_key=my_consumer_key
```

Depending on the API you want to use, you may set the ``endpoint`` to:

* ``ovh-eu`` for OVH Europe API
* ``ovh-ca`` for OVH North-America API
* ``soyoustart-eu`` for So you Start Europe API
* ``soyoustart-ca`` for So you Start North America API
* ``kimsufi-eu`` for Kimsufi Europe API
* ``kimsufi-ca`` for Kimsufi North America API
* ``runabove-ca`` for RunAbove API
* Or any arbitrary URL to use in a test for example

The client will successively attempt to locate this configuration file in

1. Current working directory: ``./ovh.conf``
Expand Down Expand Up @@ -108,28 +119,41 @@ credentials at once. See below.
### Use the API on behalf of a user

Visit [https://eu.api.ovh.com/createApp](https://eu.api.ovh.com/createApp) and create your app
You'll get an application key and an application secret. To use the API you'll need a consumer key.
You'll get an application key and an application secret. To use the API you'll need a consumer key.

The consumer key has two types of restriction:

* path: eg. only the ```GET``` method on ```/me```
* time: eg. expire in 1 day


Then, get a consumer key. Here's an example on how to generate one:
Then, get a consumer key. Here's an example on how to generate one.

First, create a 'ovh.conf' file in the current directory with the application key and
application secret. You can add the consumer key once generated. For alternate
configuration method, please see the [configuration section](#configuration).

```ini
[ovh-eu]
application_key=my_app_key
application_secret=my_application_secret
; consumer_key=my_consumer_key
```

Then, you may use a program like this example to create a consumer key for the application:

```go
package main

import (
"fmt"

"github.com/gregdel/govh"
"github.com/ovh/go-ovh/ovh"
)

func main() {
// Create a client using credentials from config files or environment variables
client, err := govh.NewEndpointClient("ovh-eu")
client, err := ovh.NewEndpointClient("ovh-eu")
if err != nil {
fmt.Printf("Error: %q\n", err)
return
Expand Down Expand Up @@ -162,9 +186,21 @@ typically want to do this when writing automation scripts for a single projects.

If this case, you may want to directly go to https://eu.api.ovh.com/createToken/ to generate
the 3 tokens at once. Make sure to save them in one of the 'ovh.conf' configuration file.
Please see the [configuration section](#configuration).

``ovh.conf`` should look like:

```ini
[ovh-eu]
application_key=my_app_key
application_secret=my_application_secret
consumer_key=my_consumer_key
```

## Use the lib

These examples assume valid credentials are available in the [configuration](#configuration).

### GET

```go
Expand All @@ -173,15 +209,11 @@ package main
import (
"fmt"

"github.com/gregdel/govh"
"github.com/ovh/go-ovh/ovh"
)

func main() {
ak := "your_app_key"
as := "your_app_secret"
ck := "your_consumer_key"

client, err := govh.NewClient("ovh-eu", ak, as, ck)
client, err := ovh.NewEndpointClient("ovh-eu")
if err != nil {
fmt.Printf("Error: %q\n", err)
return
Expand Down Expand Up @@ -224,15 +256,11 @@ package main
import (
"fmt"

"github.com/gregdel/govh"
"github.com/ovh/go-ovh/ovh"
)

func main() {
ak := "your_app_key"
as := "your_app_secret"
ck := "your_consumer_key"

client, err := govh.NewClient("ovh-eu", ak, as, ck)
client, err := ovh.NewEndpointClient("ovh-eu")
if err != nil {
fmt.Printf("Error: %q\n", err)
return
Expand All @@ -258,9 +286,9 @@ func main() {

### Create a client

- Use ``govh.NewClient()`` to have full controll over ther authentication
- Use ``govh.NewEndpointClient()`` to create a client for a specific API and use credentials from config files or environment
- Use ``govh.NewDefaultClient()`` to create a client unsing endpoint and credentials from config files or environment
- Use ``ovh.NewClient()`` to have full controll over ther authentication
- Use ``ovh.NewEndpointClient()`` to create a client for a specific API and use credentials from config files or environment
- Use ``ovh.NewDefaultClient()`` to create a client unsing endpoint and credentials from config files or environment

### Query

Expand Down Expand Up @@ -340,13 +368,13 @@ Here is a quick outline of what it may look like.
### Get the sources

```
go get github.com/gregdel/govh
cd $GOPATH/src/github.com/gregdel/govh
go get github.com/ovh/go-ovh/ovh
cd $GOPATH/src/github.com/ovh/go-ovh/ovh
go get
```

You've developed a new cool feature ? Fixed an annoying bug ? We'd be happy
to hear from you ! See [CONTRIBUTING.md](https://github.com/gregdel/govh/blob/master/CONTRIBUTING.md)
to hear from you ! See [CONTRIBUTING.md](https://github.com/ovh/go-ovh/ovh/blob/master/CONTRIBUTING.md)
for more informations

### Run the tests
Expand Down
24 changes: 12 additions & 12 deletions configuration.go → ovh/configuration.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package govh
package ovh

import (
"fmt"
Expand Down Expand Up @@ -67,33 +67,33 @@ func (c *Client) loadConfig(endpointName string) error {
endpointName = getConfigValue(cfg, "default", "endpoint", "ovh-eu")
}

if c.appKey == "" {
c.appKey = getConfigValue(cfg, endpointName, "application_key", "")
if c.AppKey == "" {
c.AppKey = getConfigValue(cfg, endpointName, "application_key", "")
}

if c.appSecret == "" {
c.appSecret = getConfigValue(cfg, endpointName, "application_secret", "")
if c.AppSecret == "" {
c.AppSecret = getConfigValue(cfg, endpointName, "application_secret", "")
}

if c.consumerKey == "" {
c.consumerKey = getConfigValue(cfg, endpointName, "consumer_key", "")
if c.ConsumerKey == "" {
c.ConsumerKey = getConfigValue(cfg, endpointName, "consumer_key", "")
}

// Load real endpoint URL by name. If endpoint contains a '/', consider it as a URL
if strings.Contains(endpointName, "/") {
c.endpoint = Endpoint(endpointName)
c.endpoint = endpointName
} else {
c.endpoint = Endpoints[endpointName]
}

// If we still have no valid endpoint, appKey or appSecret, return an error
if c.endpoint == Endpoint("") {
// If we still have no valid endpoint, AppKey or AppSecret, return an error
if c.endpoint == "" {
return fmt.Errorf("Unknown endpoint '%s'. Consider checking 'Endpoints' list of using an URL.", endpointName)
}
if c.appKey == "" {
if c.AppKey == "" {
return fmt.Errorf("Missing application key. Please check your configuration or consult the documentation to create one.")
}
if c.appSecret == "" {
if c.AppSecret == "" {
return fmt.Errorf("Missing application secret. Please check your configuration or consult the documentation to create one.")
}

Expand Down
Loading