-
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
Merged
Merged
Git module clone #287
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/test/java/com/suse/salt/netapi/examples/GitModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
// the client | ||
SaltClient client = | ||
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())); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"return":[{"myminion": true}]} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!