All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scalar.dl.client.service.ClientModule Maven / Gradle / Ivy

There is a newer version: 3.10.0
Show newest version
/*
 * This file is part of the Scalar DL client SDK.
 * Copyright (c) 2019 Scalar, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 *
 * You can be released from the requirements of the license by purchasing
 * a commercial license. For more information, please contact Scalar, Inc.
 */
package com.scalar.dl.client.service;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.scalar.dl.client.config.ClientConfig;
import com.scalar.dl.client.util.RequestSigner;
import com.scalar.dl.ledger.crypto.SignatureSigner;
import javax.net.ssl.SSLException;

public class ClientModule extends AbstractModule {
  private final ClientConfig config;

  public ClientModule(ClientConfig config) {
    this.config = config;
  }

  @Override
  protected void configure() {
    // TODO: LedgerClient and ProxyClient will be unified in the future.
    if (config.getProxyServer() == null) {
      bind(AbstractLedgerClient.class).to(LedgerClient.class).in(Singleton.class);
    } else {
      bind(AbstractLedgerClient.class).to(ProxyClient.class).in(Singleton.class);
    }
  }

  @Provides
  ClientConfig provideClientConfig() {
    return config;
  }

  @Provides
  com.scalar.dl.ledger.config.ClientConfig provideLedgerClientConfig() {
    return config;
  }

  @Provides
  RequestSigner provideRequestSigner() {
    return config.getPrivateKey() == null
        ? null
        : new RequestSigner(new SignatureSigner(config.getPrivateKey()));
  }

  @Provides
  @Singleton
  AbstractAuditorClient provideAbstractAuditorClient() throws SSLException {
    return config.isAuditorEnabled() ? new AuditorClient(config) : null;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy