Skip to content

Commit

Permalink
Use IdGenerators directly in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdeleon committed Jan 20, 2017
1 parent eae4e98 commit be61f94
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
19 changes: 16 additions & 3 deletions iam/src/main/groovy/io/corbel/iam/cli/dsl/IamShell.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.google.gson.Gson
import com.google.gson.GsonBuilder
import io.corbel.lib.cli.console.Description
import io.corbel.lib.cli.console.Shell
import io.corbel.lib.mongo.IdGenerator
import net.oauth.jsontoken.JsonToken
import net.oauth.jsontoken.crypto.HmacSHA256Signer
import org.bouncycastle.util.encoders.Base64
Expand All @@ -29,16 +30,24 @@ class IamShell {
IdentityRepository identityRepository
String iamUri
GroupRepository groupRepository
IdGenerator<Client> clientIdGenerator
IdGenerator<Identity> identityIdGenerator
IdGenerator<Group> groupIdGenerator


public IamShell(ClientRepository clientRepository, ScopeRepository scopeRepository, UserRepository userRepository,
DomainRepository domainRepository, String iamUri, IdentityRepository identityRepository, GroupRepository groupRepository) {
DomainRepository domainRepository, String iamUri, IdentityRepository identityRepository, GroupRepository groupRepository,
IdGenerator<Client> clientIdGenerator, IdGenerator<Identity> identityIdGenerator, IdGenerator<Group> groupIdGenerator) {
this.clientRepository = clientRepository
this.scopeRepository = scopeRepository
this.userRepository = userRepository
this.domainRepository = domainRepository
this.iamUri = iamUri
this.identityRepository = identityRepository
this.groupRepository = groupRepository
this.clientIdGenerator = clientIdGenerator
this.identityIdGenerator = identityIdGenerator
this.groupIdGenerator = groupIdGenerator
}

@Description("Creates a new domain on the DB. The input parameter is a map containing the domain data.")
Expand Down Expand Up @@ -75,6 +84,8 @@ class IamShell {
client.clientSideAuthentication = clientFields.clientSideAuthentication
client.resetNotificationId = clientFields.resetNotificationId

client.id = clientFields.id ? clientFields.id : clientIdGenerator.generateId(client)

if (clientFields.resetUrl) {
client.resetUrl = clientFields.resetUrl
}
Expand Down Expand Up @@ -244,15 +255,17 @@ class IamShell {
identity.setUserId(identityFields.userId)
identity.setOauthService(identityFields.oauthService)
identity.setOauthId(identityFields.oauthId)
identity.id = identityFields.id? identityFields.id : identityIdGenerator.generateId(identity)
identityRepository.save(identity)
}

@Description('Create a new users group')
def createGroup(groupFields) {
assert groupFields.name: 'name is required'
assert groupFields.domain: 'domain is required'

groupRepository.save(new Group(null, groupFields.name, groupFields.domain, groupFields.scopes))
Group group = new Group(null, groupFields.name, groupFields.domain, groupFields.scopes)
group.id = groupFields.id? groupFields.id : groupIdGenerator.generateId(group)
groupRepository.save(group)
}

@Description('Remove a users group')
Expand Down
2 changes: 1 addition & 1 deletion iam/src/main/java/io/corbel/iam/ioc/IamIoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public JsonTokenParser getTokenUpgradeJsonTokenParser() {
@Bean
public IamShell getIamShell(GroupService groupService) {
return new IamShell(clientRepository, scopeRepository, getUserRepository(), domainRepository, env.getProperty("iam.uri"),
identityRepository, groupRepository);
identityRepository, groupRepository, getClientIdGenerator(), getIdentityIdGenerator(), getGroupIdGenerator());
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package io.corbel.notifications.cli.dsl

import io.corbel.lib.cli.console.Description
import io.corbel.lib.cli.console.Shell
import io.corbel.lib.mongo.IdGenerator
import io.corbel.notifications.model.Domain
import io.corbel.notifications.model.Notification
import io.corbel.notifications.model.NotificationTemplate
import io.corbel.notifications.repository.DomainRepository
import io.corbel.notifications.repository.NotificationRepository
Expand All @@ -16,11 +18,14 @@ class NotificationsShell {

NotificationRepository notificationRepository
DomainRepository domainRepository
IdGenerator<NotificationTemplate> notificationIdGenerator

public NotificationsShell(NotificationRepository notificationRepository,
DomainRepository domainRepository) {
DomainRepository domainRepository,
IdGenerator<NotificationTemplate> notificationIdGenerator) {
this.notificationRepository = notificationRepository
this.domainRepository = domainRepository;
this.domainRepository = domainRepository
this.notificationIdGenerator = notificationIdGenerator
}

@Description("Creates a new notification on the DB. The input parameter is a map containing the notification data.")
Expand All @@ -38,6 +43,7 @@ class NotificationsShell {
notification.text = notificationFields.text
notification.title = notificationFields.title
notification.replyTo = notificationFields.replyTo
notification.id = notificationFields.id? notificationFields.id : notificationIdGenerator.generateId(notification)
notificationRepository.save(notification)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
@Bean
public NotificationsShell getNotificationsShell(NotificationRepository notificationRepository,
DomainRepository domainRepository) {
return new NotificationsShell(notificationRepository, domainRepository);
return new NotificationsShell(notificationRepository, domainRepository, getNotificationTemplateIdGenerator());
}

@Bean
Expand Down

0 comments on commit be61f94

Please sign in to comment.