Browse Source

Fix issue with pointers

master
harture 7 years ago
parent
commit
d726826888
  1. 12
      authentication_management.go
  2. 10
      integration/integration.go
  3. 10
      keycloak_client.go
  4. 4
      realm.go
  5. 4
      users.go

12
authentication_management.go

@ -49,8 +49,8 @@ func (c *Client) DeleteAuthenticatorConfig(accessToken string, realmName, config
// CreateAuthenticationExecution add new authentication execution // CreateAuthenticationExecution add new authentication execution
func (c *Client) CreateAuthenticationExecution(accessToken string, realmName string, authExec AuthenticationExecutionRepresentation) (string, error) { func (c *Client) CreateAuthenticationExecution(accessToken string, realmName string, authExec AuthenticationExecutionRepresentation) (string, error) {
var location *string var location string
return *location, c.post(accessToken, nil, location, url.Path(authenticationManagementPath+"/executions"), url.Param("realm", realmName), body.JSON(authExec)) return location, c.post(accessToken, nil, &location, url.Path(authenticationManagementPath+"/executions"), url.Param("realm", realmName), body.JSON(authExec))
} }
// DeleteAuthenticationExecution deletes the execution. // DeleteAuthenticationExecution deletes the execution.
@ -109,16 +109,16 @@ func (c *Client) UpdateAuthenticationExecutionForFlow(accessToken string, realmN
// 'flowAlias' is the alias of the parent flow. // 'flowAlias' is the alias of the parent flow.
func (c *Client) CreateAuthenticationExecutionForFlow(accessToken string, realmName, flowAlias, provider string) (string, error) { func (c *Client) CreateAuthenticationExecutionForFlow(accessToken string, realmName, flowAlias, provider string) (string, error) {
var m = map[string]string{"provider": provider} var m = map[string]string{"provider": provider}
var location *string 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)) 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. // CreateFlowWithExecutionForExistingFlow add a new flow with a new execution to an existing flow.
// 'flowAlias' is the alias of the parent authentication 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) { 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 m = map[string]string{"alias": alias, "type": flowType, "provider": provider, "description": description}
var location *string 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)) 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. // GetAuthenticationFlow gets the authentication flow for id.

10
integration/integration.go

@ -49,7 +49,8 @@ func main() {
// Create test realm. // Create test realm.
{ {
var realm = tstRealm var realm = tstRealm
var err = client.CreateRealm(accessToken, keycloak.RealmRepresentation{ var err error
_, err = client.CreateRealm(accessToken, keycloak.RealmRepresentation{
Realm: &realm, Realm: &realm,
}) })
if err != nil { if err != nil {
@ -111,7 +112,8 @@ func main() {
for _, u := range tstUsers { for _, u := range tstUsers {
var username = strings.ToLower(u.firstname + "." + u.lastname) var username = strings.ToLower(u.firstname + "." + u.lastname)
var email = username + "@cloudtrust.ch" 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, Username: &username,
FirstName: &u.firstname, FirstName: &u.firstname,
LastName: &u.lastname, LastName: &u.lastname,
@ -341,8 +343,8 @@ func getKeycloakConfig() *keycloak.Config {
pflag.Parse() pflag.Parse()
return &keycloak.Config{ return &keycloak.Config{
Addr: *adr, Addr: *adr,
Timeout: 10 * time.Second, Timeout: 10 * time.Second,
} }
} }

10
keycloak_client.go

@ -131,9 +131,9 @@ func (c *Client) get(accessToken string, data interface{}, plugins ...plugin.Plu
switch { switch {
case resp.StatusCode == http.StatusUnauthorized: 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: 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: case resp.StatusCode >= 200:
switch resp.Header.Get("Content-Type") { switch resp.Header.Get("Content-Type") {
case "application/json": case "application/json":
@ -163,7 +163,7 @@ func (c *Client) post(accessToken string, data interface{}, location *string, pl
switch { switch {
case resp.StatusCode == http.StatusUnauthorized: 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: case resp.StatusCode >= 400:
return fmt.Errorf("invalid status code: '%v': %v", resp.RawResponse.Status, string(resp.Bytes())) return fmt.Errorf("invalid status code: '%v': %v", resp.RawResponse.Status, string(resp.Bytes()))
case resp.StatusCode >= 200: case resp.StatusCode >= 200:
@ -199,7 +199,7 @@ func (c *Client) delete(accessToken string, plugins ...plugin.Plugin) error {
switch { switch {
case resp.StatusCode == http.StatusUnauthorized: 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: case resp.StatusCode >= 400:
return fmt.Errorf("invalid status code: '%v': %v", resp.RawResponse.Status, string(resp.Bytes())) return fmt.Errorf("invalid status code: '%v': %v", resp.RawResponse.Status, string(resp.Bytes()))
case resp.StatusCode >= 200: case resp.StatusCode >= 200:
@ -224,7 +224,7 @@ func (c *Client) put(accessToken string, plugins ...plugin.Plugin) error {
switch { switch {
case resp.StatusCode == http.StatusUnauthorized: 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: case resp.StatusCode >= 400:
return fmt.Errorf("invalid status code: '%v': %v", resp.RawResponse.Status, string(resp.Bytes())) return fmt.Errorf("invalid status code: '%v': %v", resp.RawResponse.Status, string(resp.Bytes()))
case resp.StatusCode >= 200: case resp.StatusCode >= 200:

4
realm.go

@ -21,8 +21,8 @@ func (c *Client) GetRealms(accessToken string) ([]RealmRepresentation, error){
// CreateRealm creates the realm from its RealmRepresentation. // CreateRealm creates the realm from its RealmRepresentation.
func (c *Client) CreateRealm(accessToken string, realm RealmRepresentation) (string, error) { func (c *Client) CreateRealm(accessToken string, realm RealmRepresentation) (string, error) {
var location *string var location string
return *location, c.post(accessToken, nil, location, url.Path(realmRootPath), body.JSON(realm)) 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 // GetRealm get the top level represention of the realm. Nested information like users are

4
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. // CreateUser creates the user from its UserRepresentation. The username must be unique.
func (c *Client) CreateUser(accessToken string, realmName string, user UserRepresentation) (string, error) { func (c *Client) CreateUser(accessToken string, realmName string, user UserRepresentation) (string, error) {
var location *string var location string
return *location, c.post(accessToken, nil, location, url.Path(userPath), url.Param("realm", realmName), body.JSON(user)) 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. // CountUsers returns the number of users in the realm.

Loading…
Cancel
Save