Skip to content

Commit

Permalink
Add support for Gitea credentials (#325)
Browse files Browse the repository at this point in the history
* Gitea credentials add cmd

* gitea credentials missing reflection file

* gitea credentials unit test
  • Loading branch information
JaimeSeqLabs authored Aug 28, 2023
1 parent 86cdf4d commit 315e648
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
12 changes: 12 additions & 0 deletions conf/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,12 @@
"allDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.credentials.providers.GiteaProvider",
"allDeclaredFields":true,
"allDeclaredMethods":true,
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"io.seqera.tower.cli.commands.credentials.providers.GitlabProvider",
"allDeclaredFields":true,
Expand Down Expand Up @@ -2648,6 +2654,12 @@
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"io.seqera.tower.model.GiteaSecurityKeys",
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name":"io.seqera.tower.model.GithubActionConfig",
"allDeclaredFields":true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.seqera.tower.cli.commands.credentials.add.AddAzureCmd;
import io.seqera.tower.cli.commands.credentials.add.AddBitbucketCmd;
import io.seqera.tower.cli.commands.credentials.add.AddContainerRegistryCmd;
import io.seqera.tower.cli.commands.credentials.add.AddGiteaCmd;
import io.seqera.tower.cli.commands.credentials.add.AddGithubCmd;
import io.seqera.tower.cli.commands.credentials.add.AddGitlabCmd;
import io.seqera.tower.cli.commands.credentials.add.AddGoogleCmd;
Expand All @@ -36,6 +37,7 @@
AddGoogleCmd.class,
AddGithubCmd.class,
AddGitlabCmd.class,
AddGiteaCmd.class,
AddBitbucketCmd.class,
AddSshCmd.class,
AddK8sCmd.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.cli.commands.credentials.add;

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

@Command(
name = "gitea",
description = "Add new Gitea workspace credentials."
)
public class AddGiteaCmd extends AbstractAddCmd {

@Mixin
GiteaProvider provider;

@Override
protected CredentialsProvider getProvider() {
return provider;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

package io.seqera.tower.cli.commands.credentials.providers;

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

import java.io.IOException;

public class GiteaProvider extends AbstractGitProvider<GiteaSecurityKeys> {

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

// NOTE: setting 'arity' + 'interactive' allows both passing value as param and prompting user for input
@Option(names = {"-p", "--password"}, description = "Gitea account password.", arity = "0..1", interactive = true, required = true)
public String password;

public GiteaProvider() {
super(ProviderEnum.GITEA);
}

@Override
public GiteaSecurityKeys securityKeys() throws IOException {
return new GiteaSecurityKeys()
.username(userName)
.password(password);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2021, Seqera Labs.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0.
*/

/*
* This Java source file was generated by the Gradle 'init' task.
*/
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 GiteaProviderTest 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]\",\"password\":\"mysecret\"},\"name\":\"TestGitea\",\"provider\":\"gitea\"}}")),
exactly(1)
).respond(
response().withStatusCode(200).withBody("{\"credentialsId\":\"1cz5A8cuBkB5iJliCwJCFU\"}").withContentType(MediaType.APPLICATION_JSON)
);

ExecOut out = exec(format, mock, "credentials", "add", "gitea", "-n", "TestGitea", "-u", "[email protected]", "-p", "mysecret");
assertOutput(format, out, new CredentialsAdded("GITEA", "1cz5A8cuBkB5iJliCwJCFU", "TestGitea", USER_WORKSPACE_NAME));
}

}

0 comments on commit 315e648

Please sign in to comment.