Skip to content

Customization

Jae Hyeon Bae edited this page Nov 22, 2013 · 3 revisions

###How to set up AWS credential

To use S3FileSink or SQSNotify, we should specify AWS credential to Suro server. For the security reason, if we do not want to write AWS secret key and access key on configuration file, we can set up custom AWS credential implementing com.amazonaws.auth.AWSCredentialProvider by extending Guice module. For example, currently, SuroModule initializing PropertyAWSCredentialProvider is used with the following code

public class SuroModule extends AbstractModule {
    private final Properties properties;
    
    public SuroModule(Properties properties) {
        this.properties = properties;
    }
    
    @Override
    protected void configure() {
        bind(AWSCredentialsProvider.class)
            .annotatedWith(Names.named("credentials")).to(PropertyAWSCredentialsProvider.class);

        bind(ObjectMapper.class).to(DefaultObjectMapper.class).asEagerSingleton();
        bind(AWSCredentialsProvider.class).to(PropertyAWSCredentialsProvider.class);
        bind(SinkManager.class);
        bind(RoutingMap.class);
        bind(SuroService.class);
        bind(StatusServer.class);
    }
}

public class PropertyAWSCredentialsProvider implements AWSCredentialsProvider {
    @Configuration("SuroServer.AWSAccessKey")
    private String accessKey;
    
    @Configuration("SuroServer.AWSSecretKey")
    private String secretKey;
    
    @Override
    public AWSCredentials getCredentials() {
        if (accessKey != null && secretKey != null) {
            return new AWSCredentials() {
                @Override
                public String getAWSAccessKeyId() {
                    return accessKey;
                }

                @Override
                public String getAWSSecretKey() {
                    return secretKey;
                }
            };
        } 
        else {
            return null;
        }
    }
    
    @Override
    public void refresh() {
    }
}

If you want to customize AWSCredentialProvider, try as the following sample:

bind(AWSCredentialsProvider.class)
                .annotatedWith(Names.named("credentials")).to(NFAWSCredentialProvider.class);
...

public class NFAWSCredentialProvider implements AWSCredentialsProvider {
    private final AWSManager awsManager;

    @Inject
    public NFAWSCredentialProvider(AWSManager awsManager) {
        this.awsManager = awsManager;
    }

    @Override
    public AWSCredentials getCredentials() {
        // return whatever you want
    }

    @Override
    public void refresh() {
        // do refresh
    }
}
Clone this wiki locally