-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git module clone #287
Git module clone #287
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.suse.salt.netapi.examples; | ||
|
||
import com.suse.salt.netapi.AuthModule; | ||
import com.suse.salt.netapi.calls.LocalCall; | ||
import com.suse.salt.netapi.calls.modules.Git; | ||
import com.suse.salt.netapi.client.SaltClient; | ||
import com.suse.salt.netapi.client.impl.HttpAsyncClientImpl; | ||
import com.suse.salt.netapi.datatypes.AuthMethod; | ||
import com.suse.salt.netapi.datatypes.Token; | ||
import com.suse.salt.netapi.datatypes.target.MinionList; | ||
import com.suse.salt.netapi.results.Result; | ||
import com.suse.salt.netapi.utils.HttpClientUtils; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class GitModule { | ||
|
||
// salt netapi parameters | ||
private static final String SALT_API_URL = "http://192.168.1.12:8000"; | ||
private static final String USER = "gitUser"; | ||
private static final String PASSWORD = "gitUser"; | ||
// git.clone parameters | ||
private static final String MINION_ID = "my_minion_id"; | ||
private static final String GIT_URL = "https://github.com/SUSE/salt-netapi-client.git"; | ||
private static final String CWD = "/home/saltuser/dev/"; | ||
private static final String NAME = "java_netapi"; | ||
private static final String HTTPS_USER = "saltgit"; | ||
private static final String HTTPS_PASS = "saltgit"; | ||
|
||
public static void main(String[] args) { | ||
// Init the client | ||
SaltClient client = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that there is some There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done: 4bf414e |
||
new SaltClient(URI.create(SALT_API_URL), | ||
new HttpAsyncClientImpl(HttpClientUtils.defaultClient())); | ||
Token token = client.login(USER, PASSWORD, AuthModule.PAM).toCompletableFuture().join(); | ||
AuthMethod tokenAuth = new AuthMethod(token); | ||
|
||
// Cloning a repository via https with user name and password | ||
LocalCall<Boolean> call = Git.clone( | ||
CWD, | ||
GIT_URL, | ||
Optional.of(NAME), | ||
"", | ||
"", | ||
Optional.empty(), Optional.of(HTTPS_USER), Optional.of(HTTPS_PASS)); | ||
// substitute above line for the below line of no user and password | ||
// Optional.empty(), Optional.empty(), Optional.empty()); | ||
|
||
Map<String, Result<Boolean>> results = | ||
call.callSync(client, new MinionList(MINION_ID), tokenAuth).toCompletableFuture().join(); | ||
|
||
System.out.println("Response from minions:"); | ||
results.forEach((minion, result) -> { | ||
System.out.println(minion + " -> " + result.result().orElse(Boolean.FALSE)); | ||
result.error().ifPresent(err -> System.out.println(result.error())); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"return":[{"myminion": "ERROR: Command 'git clone -- https://github.com/SUSE/salt-netapi-client.error netapi' failed: Cloning into 'netapi'...\nfatal: could not read Username for 'https://github.com': No such device or address"}]} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"return":[{"myminion": true}]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why this would be needed (here and above), wouldn't
Arrays.asList()
already create and return a list of strings asList<String>
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. It returns a list of strings as
List<String>
. However the size of the list is fixed, this will not allow us to add other arguments to the list. Below the documentation of the method:If you add an element to that list, the application will throw an Exception. The current code actually send an exception, maybe it was not well tested. This is not the only line of code where this happens, so I made that change on in different places of the git module. See: 2f9c98a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, it makes sense!