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

io.fabric8.repo.git.GitRepoTokenClient Maven / Gradle / Ivy

/**
 *  Copyright 2005-2016 Red Hat, Inc.
 *
 *  Red Hat licenses this file to you under the Apache License, version
 *  2.0 (the "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 *  implied.  See the License for the specific language governing
 *  permissions and limitations under the License.
 */
package io.fabric8.repo.git;

import io.fabric8.utils.cxf.WebClients;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.WebClient;

import java.util.List;

import static io.fabric8.utils.cxf.WebClients.configureAuthorization;
import static io.fabric8.utils.cxf.WebClients.configureUserAndPassword;
import static io.fabric8.utils.cxf.WebClients.disableSslChecks;

/**
 * A client API for working with git hosted repositories using back ends like
 * gogs or github
 */
public class GitRepoTokenClient extends GitRepoClientSupport {

    private String authorizationType;
    private String authorization;

    public GitRepoTokenClient(String address, String username, String authorizationType, String authorization) {
        super(address, username);
        this.authorizationType = authorizationType;
        this.authorization = authorization;
    }


    /**
     * Creates a JAXRS web client for the given JAXRS client
     */
    @Override
    protected  T createWebClient(Class clientType) {
        List providers = WebClients.createProviders();
        WebClient webClient = WebClient.create(address, providers);
        disableSslChecks(webClient);
        configureAuthorization(webClient, username, authorizationType, authorization);
        return JAXRSClientFactory.fromClient(webClient, clientType);
    }

}