Skip to content
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

A bit of clean up in graph #1081

Merged
merged 2 commits into from
Sep 16, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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("Will be implemented in a next release");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of promising when it will be implemented, which we probably shouldn't do, we could just say "Not yet implemented".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be done in a few days. So I'm lying anyways.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, ok. Well, but if a bus runs you over in the meantime (which I hope it doesn't!) there is a chance we'll ship it as is, so...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix it, not sure why the new Github doesn't hide this

}

@Override
public Observable<ServicePrincipal> applyAsync() {
return null;
throw new UnsupportedOperationException("Will be implemented in a next release");
}
}
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("Will be implemented in a next release");
}

@Override
public Observable<User> applyAsync() {
return null;
throw new UnsupportedOperationException("Will be implemented in a next release");
}
}
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,14 @@ public void canCRUDUser() throws Exception {
//LIST
List<User> userList = graphRbacManager.users().list();
Assert.assertNotNull(userList);
User user = graphRbacManager.users().define("jeffrolfnlu@hotmail.com")
User user = graphRbacManager.users().define("azuresdk@outlook.com")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we delete this user after test is done? not sure if we can do so. But this test is not doing much once it run for first time as this user will always be there for ever.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not functional. For now it's just a placeholder.

.withDisplayName("Test User 309")
.withPassword("Pa$$w0rd")
.withMailNickname("")
.withMailNickname(null)
.create();
Assert.assertNotNull(user);
Assert.assertEquals("Test User 309", user.displayName());
Assert.assertEquals("azuresdk@outlook.com", user.mail());
}

}