Skip to content

Commit

Permalink
make fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
kevholditch committed Feb 15, 2018
1 parent 09cd321 commit 1e9d517
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 48 deletions.
29 changes: 11 additions & 18 deletions auth0/auth0_client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package auth0

import (
"github.com/parnurzeal/gorequest"
"fmt"
"encoding/json"
"fmt"
"github.com/parnurzeal/gorequest"
)

type AuthClient struct {
Expand All @@ -26,21 +26,20 @@ type UserRequest struct {
}

type User struct {
UserId string `json:"user_id,omitempty"`
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
UserMetaData map[string]interface{} `json:"user_metadata,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
UserId string `json:"user_id,omitempty"`
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
UserMetaData map[string]interface{} `json:"user_metadata,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
}


func (config *Config) getAuthenticationHeader() string {
return "Bearer " + config.accessToken
}

func (authClient *AuthClient) GetUserById(id string) (*User, error) {

_, body, errs := gorequest.New().Get(authClient.config.apiUri + "users/" + id).Set("Authorization", authClient.config.getAuthenticationHeader()).End()
_, body, errs := gorequest.New().Get(authClient.config.apiUri+"users/"+id).Set("Authorization", authClient.config.getAuthenticationHeader()).End()

if errs != nil {
return nil, fmt.Errorf("could parse user resposne from auth0, error: %v", errs)
Expand All @@ -61,8 +60,7 @@ func (authClient *AuthClient) GetUserById(id string) (*User, error) {

func (authClient *AuthClient) CreateUser(userRequest *UserRequest) (*User, error) {

_, body, errs := gorequest.New().Post(authClient.config.apiUri + "users").Send(userRequest).Set("Authorization", authClient.config.getAuthenticationHeader()).End()

_, body, errs := gorequest.New().Post(authClient.config.apiUri+"users").Send(userRequest).Set("Authorization", authClient.config.getAuthenticationHeader()).End()

if errs != nil {
return nil, fmt.Errorf("could create user in auth0, error: %v", errs)
Expand All @@ -83,7 +81,7 @@ func (authClient *AuthClient) CreateUser(userRequest *UserRequest) (*User, error

func (authClient *AuthClient) UpdateUserById(id string, userRequest *UserRequest) (*User, error) {

_, body, errs := gorequest.New().Patch(authClient.config.apiUri + "users/" + id).Set("Authorization", authClient.config.getAuthenticationHeader()).End()
_, body, errs := gorequest.New().Patch(authClient.config.apiUri+"users/"+id).Set("Authorization", authClient.config.getAuthenticationHeader()).End()
if errs != nil {
return nil, fmt.Errorf("could not update auth0 user, error: %v", errs)
}
Expand All @@ -103,15 +101,10 @@ func (authClient *AuthClient) UpdateUserById(id string, userRequest *UserRequest

func (authClient *AuthClient) DeleteById(id string) error {

res, _, errs := gorequest.New().Delete(authClient.config.apiUri + "users/" + id).Set("Authorization", authClient.config.getAuthenticationHeader()).End()
res, _, errs := gorequest.New().Delete(authClient.config.apiUri+"users/"+id).Set("Authorization", authClient.config.getAuthenticationHeader()).End()
if errs != nil {
return fmt.Errorf("could not delete auth0 user, result: %v error: %v", res, errs)
}

return nil
}





30 changes: 14 additions & 16 deletions auth0/provider.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package auth0

import (
"github.com/hashicorp/terraform/helper/schema"
"log"
"github.com/parnurzeal/gorequest"
"fmt"
"encoding/json"
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/parnurzeal/gorequest"
"log"
)

func Provider() terraform.ResourceProvider {
Expand All @@ -27,29 +27,27 @@ func Provider() terraform.ResourceProvider {
Required: true,
DefaultFunc: schema.EnvDefaultFunc("AUTH0_CLIENT_SECRET", nil),
},

},

ResourcesMap: map[string]*schema.Resource{
"auth0_user": resourceAuth0User(),
"auth0_user": resourceAuth0User(),
},

ConfigureFunc: providerConfigure,
}
}


type Config struct {
domain string
accessToken string
apiUri string
}

type LoginRequest struct {
ClientId string `json:"client_id"`
ClientId string `json:"client_id"`
ClientSecret string `json:"client_secret"`
Audience string `json:"audience"`
GrantType string `json:"grant_type"`
Audience string `json:"audience"`
GrantType string `json:"grant_type"`
}

type LoginResponse struct {
Expand All @@ -63,10 +61,10 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
apiUri := "https://" + domain + "/api/v2/"

auth0LoginRequest := &LoginRequest{
ClientId: d.Get("auth0_client_id").(string),
ClientSecret: d.Get("auth0_client_secret").(string),
Audience: apiUri,
GrantType: "client_credentials",
ClientId: d.Get("auth0_client_id").(string),
ClientSecret: d.Get("auth0_client_secret").(string),
Audience: apiUri,
GrantType: "client_credentials",
}

_, body, errs := gorequest.New().Post("https://" + domain + "/oauth/token").Send(auth0LoginRequest).End()
Expand All @@ -82,9 +80,9 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
}

config := &Config{
domain: domain,
domain: domain,
accessToken: loginResponse.AccessToken,
apiUri:apiUri,
apiUri: apiUri,
}

return NewClient(config), nil
Expand Down
5 changes: 2 additions & 3 deletions auth0/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package auth0
import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"testing"
"os"
"testing"
)


var testAccProviders map[string]terraform.ResourceProvider
var testAccProvider *schema.Provider

Expand Down Expand Up @@ -40,4 +39,4 @@ func testAccPreCheck(t *testing.T) {
if v := os.Getenv("AUTH0_CLIENT_SECRET"); v == "" {
t.Fatal("AUTH0_CLIENT_SECRET must be set for acceptance tests")
}
}
}
12 changes: 5 additions & 7 deletions auth0/resource_auth0_user.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package auth0

import (
"github.com/hashicorp/terraform/helper/schema"
"fmt"
"github.com/hashicorp/terraform/helper/schema"
)

func resourceAuth0User() *schema.Resource {
Expand Down Expand Up @@ -40,15 +40,14 @@ func resourceAuth0User() *schema.Resource {
ForceNew: true,
},
"email_verified": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
},
},
}
}


func resourceAuth0UserCreate(d *schema.ResourceData, meta interface{}) error {

auth0Client := meta.(*AuthClient)
Expand Down Expand Up @@ -112,6 +111,5 @@ func createUserRequestFromResourceData(d *schema.ResourceData) *UserRequest {
userRequest.UserMetaData = readMapFromResource(d, "user_metadata")
userRequest.EmailVerified = readBoolFromResource(d, "email_verified")


return userRequest
}
}
4 changes: 1 addition & 3 deletions auth0/resource_auth0_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestAccAuth0User(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAuth0UserDestroy,
Steps: []resource.TestStep{
Expand Down Expand Up @@ -43,7 +43,6 @@ func TestAccAuth0User(t *testing.T) {
})
}


func testAccCheckAuth0UserDestroy(state *terraform.State) error {

client := testAccProvider.Meta().(*AuthClient)
Expand Down Expand Up @@ -123,4 +122,3 @@ resource "auth0_user" "test_user" {
email_verified = true
}
`

1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/kevholditch/terraform-provider-auth0/auth0"
)


func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: auth0.Provider})
Expand Down

0 comments on commit 1e9d517

Please sign in to comment.