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

es.nitaur.bitbucket.rest.client.http.SshClientRest Maven / Gradle / Ivy

/*
 *
 *  *
 *  * Licensed 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 es.nitaur.bitbucket.rest.client.http;

import es.nitaur.bitbucket.rest.client.Range;
import es.nitaur.bitbucket.rest.client.SshClient;
import es.nitaur.bitbucket.rest.client.model.Page;
import es.nitaur.bitbucket.rest.client.model.RepositorySshKey;
import es.nitaur.bitbucket.rest.client.http.responseparsers.Parsers;
import es.nitaur.bitbucket.rest.client.model.UserSshKey;
import com.google.gson.JsonElement;

class SshClientRest extends BitBucketClient implements SshClient {

    public SshClientRest(BitBucketExecutor bitBucketHttpExecutor) {
        super(bitBucketHttpExecutor);
    }

    @Override
    public Page getRepositoryKeys(String projectKey, String repositorySlug, Range range) {
        String requestUrl = String.format("/rest/keys/1.0/projects/%s/repos/%s/ssh", projectKey, repositorySlug) + addLimits(range);
        JsonElement jsonElement = execute(requestUrl, HttpMethod.GET, null).get();
        return Parsers.pageParser(Parsers.repositorySshKeyParser()).apply(jsonElement);
    }

    @Override
    public Page getCurrentUserKeys(Range range) {
        String requestUrl = "/rest/ssh/1.0/keys" + addLimits(range);
        JsonElement jsonElement = execute(requestUrl, HttpMethod.GET, null).get();
        return Parsers.pageParser(Parsers.userSshKeyParser()).apply(jsonElement);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy