Skip to content

Commit

Permalink
Merge pull request #1081 from jianghaolu/graph
Browse files Browse the repository at this point in the history
A bit of clean up in graph
  • Loading branch information
Martin Sawicki authored Sep 16, 2016
2 parents 6fee7b8 + aed1b0b commit 90fbf90
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.microsoft.azure.RequestIdHeaderInterceptor;
import com.microsoft.azure.RestClient;
import com.microsoft.azure.credentials.AzureTokenCredentials;
import com.microsoft.azure.management.graphrbac.ServicePrincipals;
import com.microsoft.azure.management.graphrbac.Users;
import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable;
Expand All @@ -18,6 +19,7 @@
* Entry point to Azure resource management.
*/
public final class GraphRbacManager {
private String tenantId;
// The sdk clients
private final GraphRbacManagementClientImpl graphRbacManagementClient;
// The collections
Expand All @@ -39,6 +41,20 @@ public static GraphRbacManager authenticate(ServiceClientCredentials credentials
.build(), tenantId);
}

/**
* Creates an instance of GraphRbacManager that exposes resource management API entry points.
*
* @param credentials the credentials to use
* @return the GraphRbacManager instance
*/
public static GraphRbacManager authenticate(AzureTokenCredentials credentials) {
return new GraphRbacManager(new RestClient.Builder()
.withBaseUrl("https://graph.windows.net")
.withInterceptor(new RequestIdHeaderInterceptor())
.withCredentials(credentials)
.build(), credentials.getDomain());
}

/**
* Creates an instance of GraphRbacManager that exposes resource management API entry points.
*
Expand Down Expand Up @@ -71,6 +87,14 @@ public interface Configurable extends AzureConfigurable<Configurable> {
* @return the interface exposing resource management API entry points that work across subscriptions
*/
GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId);

/**
* Creates an instance of GraphRbacManager that exposes resource management API entry points.
*
* @param credentials the credentials to use
* @return the interface exposing resource management API entry points that work across subscriptions
*/
GraphRbacManager authenticate(AzureTokenCredentials credentials);
}

/**
Expand All @@ -86,10 +110,22 @@ protected ConfigurableImpl() {
public GraphRbacManager authenticate(ServiceClientCredentials credentials, String tenantId) {
return GraphRbacManager.authenticate(buildRestClient(credentials), tenantId);
}

public GraphRbacManager authenticate(AzureTokenCredentials credentials) {
return GraphRbacManager.authenticate(buildRestClient(credentials), credentials.getDomain());
}
}

private GraphRbacManager(RestClient restClient, String tenantId) {
this.graphRbacManagementClient = new GraphRbacManagementClientImpl(restClient).withTenantID(tenantId);
this.tenantId = tenantId;
}

/**
* @return the tenant ID the graph client is associated with
*/
public String tenantId() {
return tenantId;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,17 @@ public ServicePrincipalImpl withAccountEnabled(boolean enabled) {

@Override
public ServicePrincipal refresh() {
return null;
setInner(client.list(String.format("servicePrincipalNames/any(c:c eq '%s')", name())).get(0));
return this;
}

@Override
public Observable<ServicePrincipal> createResourceAsync() {
return null;
throw new UnsupportedOperationException("not implemented yet");
}

@Override
public Observable<ServicePrincipal> applyAsync() {
return null;
throw new UnsupportedOperationException("not implemented yet");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,17 @@ public UserImpl withPassword(String password, boolean forceChangePasswordNextLog

@Override
public User refresh() {
return null;
setInner(client.get(name()));
return this;
}

@Override
public Observable<User> createResourceAsync() {
return null;
throw new UnsupportedOperationException("not implemented yet");
}

@Override
public Observable<User> applyAsync() {
return null;
throw new UnsupportedOperationException("not implemented yet");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,17 @@ public abstract class GraphRbacManagementTestBase {
protected static GraphRbacManager graphRbacManager;

protected static void createClients() {
// ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
// System.getenv("client-id"),
// System.getenv("domain"),
// System.getenv("secret"),
// "https://graph.windows.net",
// null);
UserTokenCredentials credentials = new UserTokenCredentials(
"1950a258-227b-4e31-a9cf-717495945fc2",
System.getenv("client-id"),
System.getenv("domain"),
System.getenv("username"),
System.getenv("password"),
"https://graph.windows.net",
"https://graph.windows.net",
AzureEnvironment.AZURE
);

graphRbacManager = GraphRbacManager
.configure()
.withLogLevel(HttpLoggingInterceptor.Level.BODY)
.authenticate(credentials, "myorganization");
.authenticate(credentials);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ public void canCRUDUser() throws Exception {
//LIST
List<User> userList = graphRbacManager.users().list();
Assert.assertNotNull(userList);
User user = graphRbacManager.users().define("[email protected]")
User user = graphRbacManager.users().define("newuser")
.withDisplayName("Test User 309")
.withPassword("Pa$$w0rd")
.withMailNickname("")
.withMailNickname(null)
.create();
Assert.assertNotNull(user);
Assert.assertEquals("Test User 309", user.displayName());
}

}

0 comments on commit 90fbf90

Please sign in to comment.