Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions src/main/java/io/seqera/tower/cli/commands/credentials/AddCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.seqera.tower.cli.commands.credentials.add.AddAgentCmd;
import io.seqera.tower.cli.commands.credentials.add.AddAwsCmd;
import io.seqera.tower.cli.commands.credentials.add.AddAzureCmd;
import io.seqera.tower.cli.commands.credentials.add.AddAzureReposCmd;
import io.seqera.tower.cli.commands.credentials.add.AddBitbucketCmd;
import io.seqera.tower.cli.commands.credentials.add.AddCodeCommitCmd;
import io.seqera.tower.cli.commands.credentials.add.AddContainerRegistryCmd;
Expand All @@ -36,24 +37,21 @@

import java.io.IOException;

@Command(
name = "add",
description = "Add new workspace credentials.",
subcommands = {
AddAwsCmd.class,
AddCodeCommitCmd.class,
AddGoogleCmd.class,
AddGithubCmd.class,
AddGitlabCmd.class,
AddGiteaCmd.class,
AddBitbucketCmd.class,
AddSshCmd.class,
AddK8sCmd.class,
AddAzureCmd.class,
AddAgentCmd.class,
AddContainerRegistryCmd.class
}
)
@Command(name = "add", description = "Add new workspace credentials.", subcommands = {
AddAwsCmd.class,
AddCodeCommitCmd.class,
AddGoogleCmd.class,
AddGithubCmd.class,
AddGitlabCmd.class,
AddGiteaCmd.class,
AddBitbucketCmd.class,
AddAzureReposCmd.class,
AddSshCmd.class,
AddK8sCmd.class,
AddAzureCmd.class,
AddAgentCmd.class,
AddContainerRegistryCmd.class
})
public class AddCmd extends AbstractCredentialsCmd {
@Override
protected Response exec() throws ApiException, IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021-2023, Seqera.
*
* 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 io.seqera.tower.cli.commands.credentials.add;

import io.seqera.tower.cli.commands.credentials.providers.AzureReposProvider;
import io.seqera.tower.cli.commands.credentials.providers.CredentialsProvider;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;

@Command(name = "azurerepos", description = "Add new Azure Repos workspace credentials.")
public class AddAzureReposCmd extends AbstractAddCmd {

@Mixin
AzureReposProvider provider;

@Override
protected CredentialsProvider getProvider() {
return provider;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2021-2023, Seqera.
*
* 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 io.seqera.tower.cli.commands.credentials.providers;

import io.seqera.tower.model.Credentials.ProviderEnum;
import io.seqera.tower.model.AzureReposSecurityKeys;
import picocli.CommandLine.Option;

import java.io.IOException;

public class AzureReposProvider extends AbstractGitProvider<AzureReposSecurityKeys> {

@Option(names = { "-u", "--username" }, description = "Azure Repos username.", required = true)
public String userName;

@Option(names = { "-p",
"--password" }, description = "Azure Repos account password or access token (recommended).", arity = "0..1", interactive = true, required = true)
public String password;

@Option(names = { "-t",
"--token" }, description = "Azure Repos account access token.", arity = "0..1", required = true, interactive = true)
public String accessToken;

public AzureReposProvider() {
super(ProviderEnum.AZUREREPOS);
}

@Override
public AzureReposSecurityKeys securityKeys() throws IOException {
return new AzureReposSecurityKeys()
.username(userName)
.token(accessToken);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2021-2023, Seqera.
*
* 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 io.seqera.tower.cli.credentials.providers;

import io.seqera.tower.cli.BaseCmdTest;
import io.seqera.tower.cli.commands.enums.OutputType;
import io.seqera.tower.cli.responses.CredentialsAdded;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
import org.mockserver.client.MockServerClient;
import org.mockserver.model.MediaType;

import static io.seqera.tower.cli.commands.AbstractApiCmd.USER_WORKSPACE_NAME;
import static org.mockserver.matchers.Times.exactly;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;
import static org.mockserver.model.JsonBody.json;

class AzureReposProviderTest extends BaseCmdTest {

@ParameterizedTest
@EnumSource(OutputType.class)
void testAdd(OutputType format, MockServerClient mock) {

mock.when(
request()
.withMethod("POST")
.withPath("/credentials")
.withBody(json(
"{\"credentials\":{\"keys\":{\"username\":\"[email protected]\",\"token\":\"azure_repos_token\"},\"name\":\"azurerepos\",\"provider\":\"azurerepos\"}}")),
exactly(1)).respond(
response().withStatusCode(200).withBody("{\"credentialsId\":\"1cz5A8cuBkB5iJliCwJCFU\"}")
.withContentType(MediaType.APPLICATION_JSON));

ExecOut out = exec(format, mock, "credentials", "add", "azurerepos", "-n", "azurerepos", "-u",
"[email protected]", "-t", "azure_repos_token");
assertOutput(format, out,
new CredentialsAdded("AZUREREPOS", "1cz5A8cuBkB5iJliCwJCFU", "azurerepos", USER_WORKSPACE_NAME));
}

}
Loading