From d7268268888dc72e5770bb287bddd0b1b132d0ee Mon Sep 17 00:00:00 2001 From: harture Date: Tue, 12 Mar 2019 10:48:48 +0100 Subject: [PATCH] Fix issue with pointers --- authentication_management.go | 12 ++++++------ integration/integration.go | 10 ++++++---- keycloak_client.go | 10 +++++----- realm.go | 4 ++-- users.go | 4 ++-- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/authentication_management.go b/authentication_management.go index 25ffadd..6706cb1 100644 --- a/authentication_management.go +++ b/authentication_management.go @@ -49,8 +49,8 @@ func (c *Client) DeleteAuthenticatorConfig(accessToken string, realmName, config // CreateAuthenticationExecution add new authentication execution func (c *Client) CreateAuthenticationExecution(accessToken string, realmName string, authExec AuthenticationExecutionRepresentation) (string, error) { - var location *string - return *location, c.post(accessToken, nil, location, url.Path(authenticationManagementPath+"/executions"), url.Param("realm", realmName), body.JSON(authExec)) + var location string + return location, c.post(accessToken, nil, &location, url.Path(authenticationManagementPath+"/executions"), url.Param("realm", realmName), body.JSON(authExec)) } // DeleteAuthenticationExecution deletes the execution. @@ -109,16 +109,16 @@ func (c *Client) UpdateAuthenticationExecutionForFlow(accessToken string, realmN // 'flowAlias' is the alias of the parent flow. func (c *Client) CreateAuthenticationExecutionForFlow(accessToken string, realmName, flowAlias, provider string) (string, error) { var m = map[string]string{"provider": provider} - var location *string - return *location, c.post(accessToken, nil, location, url.Path(authenticationManagementPath+"/flows/:flowAlias/executions/execution"), url.Param("realm", realmName), url.Param("flowAlias", flowAlias), body.JSON(m)) + var location string + return location, c.post(accessToken, nil, &location, url.Path(authenticationManagementPath+"/flows/:flowAlias/executions/execution"), url.Param("realm", realmName), url.Param("flowAlias", flowAlias), body.JSON(m)) } // CreateFlowWithExecutionForExistingFlow add a new flow with a new execution to an existing flow. // 'flowAlias' is the alias of the parent authentication flow. func (c *Client) CreateFlowWithExecutionForExistingFlow(accessToken string, realmName, flowAlias, alias, flowType, provider, description string) (string, error) { var m = map[string]string{"alias": alias, "type": flowType, "provider": provider, "description": description} - var location *string - return *location, c.post(accessToken, nil, location, url.Path(authenticationManagementPath+"/flows/:flowAlias/executions/flow"), url.Param("realm", realmName), url.Param("flowAlias", flowAlias), body.JSON(m)) + var location string + return location, c.post(accessToken, nil, &location, url.Path(authenticationManagementPath+"/flows/:flowAlias/executions/flow"), url.Param("realm", realmName), url.Param("flowAlias", flowAlias), body.JSON(m)) } // GetAuthenticationFlow gets the authentication flow for id. diff --git a/integration/integration.go b/integration/integration.go index 81c4cb5..e09a4ba 100644 --- a/integration/integration.go +++ b/integration/integration.go @@ -49,7 +49,8 @@ func main() { // Create test realm. { var realm = tstRealm - var err = client.CreateRealm(accessToken, keycloak.RealmRepresentation{ + var err error + _, err = client.CreateRealm(accessToken, keycloak.RealmRepresentation{ Realm: &realm, }) if err != nil { @@ -111,7 +112,8 @@ func main() { for _, u := range tstUsers { var username = strings.ToLower(u.firstname + "." + u.lastname) var email = username + "@cloudtrust.ch" - var err = client.CreateUser(accessToken, tstRealm, keycloak.UserRepresentation{ + var err error + _, err = client.CreateUser(accessToken, tstRealm, keycloak.UserRepresentation{ Username: &username, FirstName: &u.firstname, LastName: &u.lastname, @@ -341,8 +343,8 @@ func getKeycloakConfig() *keycloak.Config { pflag.Parse() return &keycloak.Config{ - Addr: *adr, - Timeout: 10 * time.Second, + Addr: *adr, + Timeout: 10 * time.Second, } } diff --git a/keycloak_client.go b/keycloak_client.go index eb0ca82..fac3fb5 100644 --- a/keycloak_client.go +++ b/keycloak_client.go @@ -131,9 +131,9 @@ func (c *Client) get(accessToken string, data interface{}, plugins ...plugin.Plu switch { case resp.StatusCode == http.StatusUnauthorized: - return fmt.Errorf("unauthorized request: '%v': %v", resp.RawResponse.Status, resp.String()) + return fmt.Errorf("unauthorized request: '%v': %v", resp.RawResponse.Status, string(resp.Bytes())) case resp.StatusCode >= 400: - return fmt.Errorf("invalid status code: '%v': %v", resp.RawResponse.Status, resp.String()) + return fmt.Errorf("invalid status code: '%v': %v", resp.RawResponse.Status, string(resp.Bytes())) case resp.StatusCode >= 200: switch resp.Header.Get("Content-Type") { case "application/json": @@ -163,7 +163,7 @@ func (c *Client) post(accessToken string, data interface{}, location *string, pl switch { case resp.StatusCode == http.StatusUnauthorized: - return fmt.Errorf("unauthorized request: '%v': %v", resp.RawResponse.Status, resp.String()) + return fmt.Errorf("unauthorized request: '%v': %v", resp.RawResponse.Status, string(resp.Bytes())) case resp.StatusCode >= 400: return fmt.Errorf("invalid status code: '%v': %v", resp.RawResponse.Status, string(resp.Bytes())) case resp.StatusCode >= 200: @@ -199,7 +199,7 @@ func (c *Client) delete(accessToken string, plugins ...plugin.Plugin) error { switch { case resp.StatusCode == http.StatusUnauthorized: - return fmt.Errorf("unauthorized request: '%v': %v", resp.RawResponse.Status, resp.String()) + return fmt.Errorf("unauthorized request: '%v': %v", resp.RawResponse.Status, string(resp.Bytes())) case resp.StatusCode >= 400: return fmt.Errorf("invalid status code: '%v': %v", resp.RawResponse.Status, string(resp.Bytes())) case resp.StatusCode >= 200: @@ -224,7 +224,7 @@ func (c *Client) put(accessToken string, plugins ...plugin.Plugin) error { switch { case resp.StatusCode == http.StatusUnauthorized: - return fmt.Errorf("unauthorized request: '%v': %v", resp.RawResponse.Status, resp.String()) + return fmt.Errorf("unauthorized request: '%v': %v", resp.RawResponse.Status, string(resp.Bytes())) case resp.StatusCode >= 400: return fmt.Errorf("invalid status code: '%v': %v", resp.RawResponse.Status, string(resp.Bytes())) case resp.StatusCode >= 200: diff --git a/realm.go b/realm.go index 802282b..225aad2 100644 --- a/realm.go +++ b/realm.go @@ -21,8 +21,8 @@ func (c *Client) GetRealms(accessToken string) ([]RealmRepresentation, error){ // CreateRealm creates the realm from its RealmRepresentation. func (c *Client) CreateRealm(accessToken string, realm RealmRepresentation) (string, error) { - var location *string - return *location, c.post(accessToken, nil, location, url.Path(realmRootPath), body.JSON(realm)) + var location string + return location, c.post(accessToken, nil, &location, url.Path(realmRootPath), body.JSON(realm)) } // GetRealm get the top level represention of the realm. Nested information like users are diff --git a/users.go b/users.go index 4f6349c..2218a3b 100644 --- a/users.go +++ b/users.go @@ -30,8 +30,8 @@ func (c *Client) GetUsers(accessToken string, realmName string, paramKV ...strin // CreateUser creates the user from its UserRepresentation. The username must be unique. func (c *Client) CreateUser(accessToken string, realmName string, user UserRepresentation) (string, error) { - var location *string - return *location, c.post(accessToken, nil, location, url.Path(userPath), url.Param("realm", realmName), body.JSON(user)) + var location string + return location, c.post(accessToken, nil, &location, url.Path(userPath), url.Param("realm", realmName), body.JSON(user)) } // CountUsers returns the number of users in the realm.