Skip to content

Commit

Permalink
Merge new-flow into master
Browse files Browse the repository at this point in the history
  • Loading branch information
fperot74 authored Dec 9, 2020
2 parents f77cf5f + e1dff02 commit e259774
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 31 deletions.
28 changes: 14 additions & 14 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

[[constraint]]
name = "github.com/cloudtrust/common-service"
version = "2.2.4"
version = "2.3.0"

[[constraint]]
name = "github.com/pkg/errors"
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pipeline {
if (!env.CHANGE_ID) {
isBranch = " || true"
}
withCredentials([usernamePassword(credentialsId: 'sonarqube', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
withCredentials([usernamePassword(credentialsId: 'cloudtrust-cicd-sonarqube', usernameVariable: 'USER', passwordVariable: 'PASS')]) {
sh """
set -eo pipefail
Expand Down
11 changes: 10 additions & 1 deletion api/recovery_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
)

const (
recoveryCodePath = "/auth/realms/:realm/recovery-code"
recoveryCodePath = "/auth/realms/:realm/recovery-code"
activationCodePath = "/auth/realms/:realm/activation-code"
)

// CreateRecoveryCode creates a new recovery code authenticator and returns the code.
Expand All @@ -17,3 +18,11 @@ func (c *Client) CreateRecoveryCode(accessToken string, realmName string, userID
_, err := c.post(accessToken, &resp, query.Add("userId", userID), url.Path(recoveryCodePath), url.Param("realm", realmName))
return resp, err
}

// CreateActivationCode creates a new activation code authenticator and returns the code.
func (c *Client) CreateActivationCode(accessToken string, realmName string, userID string) (keycloak.ActivationCodeRepresentation, error) {
var resp = keycloak.ActivationCodeRepresentation{}

_, err := c.post(accessToken, &resp, query.Add("userId", userID), url.Path(activationCodePath), url.Param("realm", realmName))
return resp, err
}
43 changes: 29 additions & 14 deletions api/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ import (
)

const (
userPath = "/auth/admin/realms/:realm/users"
usersAdminExtensionAPIPath = "/auth/realms/:realmReq/api/admin/realms/:realm/users"
userCountPath = userPath + "/count"
userIDPath = userPath + "/:id"
userGroupsPath = userIDPath + "/groups"
userGroupIDPath = userGroupsPath + "/:groupId"
executeActionsEmailPath = userIDPath + "/execute-actions-email"
sendReminderEmailPath = "/auth/realms/:realm/onboarding/sendReminderEmail"
smsAPI = "/auth/realms/:realm/smsApi"
sendNewEnrolmentCode = smsAPI + "/sendNewCode"
shadowUser = userIDPath + "/federated-identity/:provider"
userPath = "/auth/admin/realms/:realm/users"
adminExtensionAPIPath = "/auth/realms/:realmReq/api/admin/realms/:realm"
usersAdminExtensionAPIPath = adminExtensionAPIPath + "/users"
sendEmailAdminExtensionAPIPath = adminExtensionAPIPath + "/send-email"
userCountPath = userPath + "/count"
userIDPath = userPath + "/:id"
userGroupsPath = userIDPath + "/groups"
userGroupIDPath = userGroupsPath + "/:groupId"
executeActionsEmailPath = userIDPath + "/execute-actions-email"
sendReminderEmailPath = "/auth/realms/:realm/onboarding/sendReminderEmail"
smsAPI = "/auth/realms/:realm/smsApi"
sendSmsCode = smsAPI + "/sendNewCode"
sendSMSPath = smsAPI + "/sendSms"
shadowUser = userIDPath + "/federated-identity/:provider"
)

// GetUsers returns a list of users, filtered according to the query parameters.
Expand Down Expand Up @@ -94,11 +97,11 @@ func (c *Client) ExecuteActionsEmail(accessToken string, realmName string, userI
return c.put(accessToken, plugins...)
}

// SendNewEnrolmentCode sends a new enrolment code and return it
func (c *Client) SendNewEnrolmentCode(accessToken string, realmName string, userID string) (keycloak.SmsCodeRepresentation, error) {
// SendSmsCode sends a SMS code and return it
func (c *Client) SendSmsCode(accessToken string, realmName string, userID string) (keycloak.SmsCodeRepresentation, error) {
var paramKV []string
paramKV = append(paramKV, "userid", userID)
var plugins = append(createQueryPlugins(paramKV...), url.Path(sendNewEnrolmentCode), url.Param("realm", realmName))
var plugins = append(createQueryPlugins(paramKV...), url.Path(sendSmsCode), url.Param("realm", realmName))
var resp = keycloak.SmsCodeRepresentation{}

_, err := c.post(accessToken, &resp, plugins...)
Expand All @@ -124,3 +127,15 @@ func (c *Client) LinkShadowUser(accessToken string, reqRealmName string, userID
_, err := c.post(accessToken, nil, url.Path(shadowUser), url.Param("realm", reqRealmName), url.Param("id", userID), url.Param("provider", provider), body.JSON(fedIDKC))
return err
}

// SendEmail sends an email to a user
func (c *Client) SendEmail(accessToken string, reqRealmName string, realmName string, emailRep keycloak.EmailRepresentation) error {
_, err := c.post(accessToken, nil, url.Path(sendEmailAdminExtensionAPIPath), url.Param("realmReq", reqRealmName), url.Param("realm", realmName), body.JSON(emailRep))
return err
}

// SendSMS sends an SMS to a user
func (c *Client) SendSMS(accessToken string, realmName string, smsRep keycloak.SMSRepresentation) error {
_, err := c.post(accessToken, nil, url.Path(sendSMSPath), url.Param("realm", realmName), body.JSON(smsRep))
return err
}
41 changes: 41 additions & 0 deletions definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,3 +752,44 @@ type StatisticsUsersRepresentation struct {
type RecoveryCodeRepresentation struct {
Code *string `json:"code,omitempty"`
}

// ActivationCodeRepresentation struct
type ActivationCodeRepresentation struct {
Code *string `json:"code,omitempty"`
}

// EmailRepresentation struct
type EmailRepresentation struct {
Recipient *string `json:"recipient,omitempty"`
Theming *EmailThemingRepresentation `json:"theming,omitempty"`
Attachments *[]AttachementRepresentation `json:"attachments,omitempty"`
}

// EmailThemingRepresentation struct
type EmailThemingRepresentation struct {
SubjectKey *string `json:"subjectKey,omitempty"`
SubjectParameters *[]string `json:"subjectParameters,omitempty"`
Template *string `json:"template,omitempty"`
TemplateParameters *map[string]string `json:"templateParameters,omitempty"`
Locale *string `json:"locale,omitempty"`
}

// AttachementRepresentation struct
type AttachementRepresentation struct {
Filename *string `json:"filename,omitempty"`
ContentType *string `json:"contentType,omitempty"`
Content *string `json:"content,omitempty"`
}

// SMSRepresentation struct
type SMSRepresentation struct {
MSISDN *string `json:"msisdn,omitempty"`
Theming *SMSThemingRepresentation `json:"theming,omitempty"`
}

// SMSThemingRepresentation struct
type SMSThemingRepresentation struct {
MessageKey *string `json:"messageKey,omitempty"`
MessageParameters *[]string `json:"messageParameters,omitempty"`
Locale *string `json:"locale,omitempty"`
}

0 comments on commit e259774

Please sign in to comment.