Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/main/java/com/openshift/client/IOpenShiftConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
public interface IOpenShiftConnection {

public static final String DEFAULT_CLIENT_ID = "com.openshift.client";

/**
* Returns the server this connection is bound to.
*
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/openshift/client/IUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public interface IUser extends IOpenShiftResource {

public static final String ID = "com.openshift.client";
public String getId();

public String getRhlogin();

Expand Down Expand Up @@ -83,4 +83,4 @@ public interface IUser extends IOpenShiftResource {

public int getConsumedGears();

}
}
7 changes: 7 additions & 0 deletions src/main/java/com/openshift/internal/client/UserResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
public class UserResource extends AbstractOpenShiftResource implements IUser {

private final APIResource api;
private final String id;
private final String rhLogin;
private final String password;
private final int maxGears;
Expand All @@ -46,6 +47,7 @@ public class UserResource extends AbstractOpenShiftResource implements IUser {
public UserResource(final APIResource api, final UserResourceDTO dto, final String password) {
super(api.getService(), dto.getLinks(), dto.getMessages());
this.api = api;
this.id = dto.getId();
this.rhLogin = dto.getRhLogin();
this.maxGears = dto.getMaxGears();
this.consumedGears = dto.getConsumedGears();
Expand All @@ -57,6 +59,11 @@ public IOpenShiftConnection getConnection() {
return api;
}

@Override
public String getId() {
return id;
}

@Override
public String getRhlogin() {
return rhLogin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ private UserResourceDTO createUser(ModelNode userNode) throws OpenShiftException
if (!userNode.isDefined()) {
return null;
}
final String id = getAsString(userNode, PROPERTY_ID);
final String rhlogin = getAsString(userNode, PROPERTY_LOGIN);
final int maxGears = getAsInteger(userNode, PROPERTY_MAX_GEARS);
final int consumedGears = getAsInteger(userNode, PROPERTY_CONSUMED_GEARS);
final Map<String, Link> links = createLinks(userNode.get(PROPERTY_LINKS));
return new UserResourceDTO(rhlogin, maxGears, consumedGears, links);
return new UserResourceDTO(id, rhlogin, maxGears, consumedGears, links);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,28 @@

public class UserResourceDTO extends BaseResourceDTO {

private final String id;
/** the user's login on rhcloud. */
private final String rhLogin;

private final int maxGears;
private final int consumedGears;

UserResourceDTO(final String rhLogin, final int maxGears, final int consumedGears, final Map<String, Link> links) {
UserResourceDTO(final String id, final String rhLogin, final int maxGears, final int consumedGears, final Map<String, Link> links) {
super(links, null);
this.id = id;
this.rhLogin = rhLogin;
this.maxGears = maxGears;
this.consumedGears = consumedGears;
}

/**
* @return the id
*/
public String getId() {
return id;
}

/**
* @return the rhLogin
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.jcraft.jsch.KeyPair;
import com.openshift.client.IOpenShiftSSHKey;
import com.openshift.client.IUser;
import com.openshift.client.IOpenShiftConnection;
import com.openshift.client.OpenShiftException;
import com.openshift.client.SSHPublicKey;

Expand Down Expand Up @@ -74,7 +75,7 @@ public static IOpenShiftSSHKey getKey(String name, List<IOpenShiftSSHKey> keys)
public static KeyPair createDsaKeyPair(String publicKeyPath, String privateKeyPath) throws IOException, JSchException {
KeyPair keyPair = KeyPair.genKeyPair(new JSch(), KeyPair.DSA, 1024);
keyPair.setPassphrase(DEFAULT_PASSPHRASE);
keyPair.writePublicKey(publicKeyPath, "created by " + IUser.ID);
keyPair.writePublicKey(publicKeyPath, "created by " + IOpenShiftConnection.DEFAULT_CLIENT_ID);
keyPair.writePrivateKey(privateKeyPath);
return keyPair;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ public void setUp() throws OpenShiftException, DatatypeConfigurationException, I
this.user = new TestConnectionFactory().getConnection().getUser();
}

@Test
public void shouldReturnId() throws OpenShiftException {
// precondition
DomainTestUtils.ensureHasDomain(user);
// operation
String id = user.getId();
// verification
assertThat(id).isNotEmpty();
}

@Test(expected = InvalidCredentialsOpenShiftException.class)
public void shouldThrowIfInvalidCredentials() throws Exception {
// dont test on dev server
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/com/openshift/internal/client/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,11 @@ public void shouldHaveMaxGears() throws Throwable {
// verifications
assertThat(user.getMaxGears()).isEqualTo(10);
}

@Test
public void shouldHaveId() throws Throwable {
// pre-conditions
// verifications
assertThat(user.getId()).isEqualTo("511a780cf2cb83f4d0001b23");
}
}