-
Notifications
You must be signed in to change notification settings - Fork 289
Create TenantManager class and wire through listTenants operation. #369
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3fef342
Create TenantManager and wire through listTenants operation.
micahstairs 2f62957
Fix formatting of javadoc comment.
micahstairs 9af1011
Implement suggested changes.
micahstairs d3936d3
Handle ListTenantsResponse defaults in the getters.
micahstairs 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
118 changes: 118 additions & 0 deletions
118
src/main/java/com/google/firebase/auth/TenantManager.java
This file contains hidden or 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,118 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.firebase.auth; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import com.google.api.client.json.JsonFactory; | ||
import com.google.api.core.ApiFuture; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.auth.ListTenantsPage.DefaultTenantSource; | ||
import com.google.firebase.auth.ListTenantsPage.PageFactory; | ||
import com.google.firebase.auth.ListTenantsPage.TenantSource; | ||
import com.google.firebase.auth.Tenant.CreateRequest; | ||
import com.google.firebase.auth.Tenant.UpdateRequest; | ||
import com.google.firebase.internal.CallableOperation; | ||
import com.google.firebase.internal.NonNull; | ||
import com.google.firebase.internal.Nullable; | ||
|
||
/** | ||
* This class can be used to perform a variety of tenant-related operations, including creating, | ||
* updating, and listing tenants. | ||
* | ||
* <p>TODO(micahstairs): Implement the following methods: getAuthForTenant(), getTenant(), | ||
* deleteTenant(), createTenant(), and updateTenant(). | ||
*/ | ||
public final class TenantManager { | ||
|
||
private final FirebaseApp firebaseApp; | ||
private final FirebaseUserManager userManager; | ||
|
||
TenantManager(FirebaseApp firebaseApp, FirebaseUserManager userManager) { | ||
this.firebaseApp = firebaseApp; | ||
this.userManager = userManager; | ||
} | ||
|
||
/** | ||
* Gets a page of tenants starting from the specified {@code pageToken}. Page size will be limited | ||
* to 1000 tenants. | ||
* | ||
* @param pageToken A non-empty page token string, or null to retrieve the first page of tenants. | ||
* @return A {@link ListTenantsPage} instance. | ||
* @throws IllegalArgumentException If the specified page token is empty. | ||
* @throws FirebaseAuthException If an error occurs while retrieving tenant data. | ||
*/ | ||
public ListTenantsPage listTenants(@Nullable String pageToken) throws FirebaseAuthException { | ||
return listTenants(pageToken, FirebaseUserManager.MAX_LIST_TENANTS_RESULTS); | ||
} | ||
|
||
/** | ||
* Gets a page of tenants starting from the specified {@code pageToken}. | ||
* | ||
* @param pageToken A non-empty page token string, or null to retrieve the first page of tenants. | ||
* @param maxResults Maximum number of tenants to include in the returned page. This may not | ||
* exceed 1000. | ||
* @return A {@link ListTenantsPage} instance. | ||
* @throws IllegalArgumentException If the specified page token is empty, or max results value is | ||
* invalid. | ||
* @throws FirebaseAuthException If an error occurs while retrieving tenant data. | ||
*/ | ||
public ListTenantsPage listTenants(@Nullable String pageToken, int maxResults) | ||
throws FirebaseAuthException { | ||
return listTenantsOp(pageToken, maxResults).call(); | ||
} | ||
|
||
/** | ||
* Similar to {@link #listTenants(String)} but performs the operation asynchronously. | ||
* | ||
* @param pageToken A non-empty page token string, or null to retrieve the first page of tenants. | ||
* @return An {@code ApiFuture} which will complete successfully with a {@link ListTenantsPage} | ||
* instance. If an error occurs while retrieving tenant data, the future throws an exception. | ||
* @throws IllegalArgumentException If the specified page token is empty. | ||
*/ | ||
public ApiFuture<ListTenantsPage> listTenantsAsync(@Nullable String pageToken) { | ||
return listTenantsAsync(pageToken, FirebaseUserManager.MAX_LIST_TENANTS_RESULTS); | ||
} | ||
|
||
/** | ||
* Similar to {@link #listTenants(String, int)} but performs the operation asynchronously. | ||
* | ||
* @param pageToken A non-empty page token string, or null to retrieve the first page of tenants. | ||
* @param maxResults Maximum number of tenants to include in the returned page. This may not | ||
* exceed 1000. | ||
* @return An {@code ApiFuture} which will complete successfully with a {@link ListTenantsPage} | ||
* instance. If an error occurs while retrieving tenant data, the future throws an exception. | ||
* @throws IllegalArgumentException If the specified page token is empty, or max results value is | ||
* invalid. | ||
*/ | ||
public ApiFuture<ListTenantsPage> listTenantsAsync(@Nullable String pageToken, int maxResults) { | ||
return listTenantsOp(pageToken, maxResults).callAsync(firebaseApp); | ||
} | ||
|
||
private CallableOperation<ListTenantsPage, FirebaseAuthException> listTenantsOp( | ||
@Nullable final String pageToken, final int maxResults) { | ||
// TODO(micahstairs): Add a check to make sure the app has not been destroyed yet. | ||
final TenantSource tenantSource = new DefaultTenantSource(userManager); | ||
final PageFactory factory = new PageFactory(tenantSource, maxResults, pageToken); | ||
return new CallableOperation<ListTenantsPage, FirebaseAuthException>() { | ||
@Override | ||
protected ListTenantsPage execute() throws FirebaseAuthException { | ||
return factory.create(); | ||
} | ||
}; | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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,17 @@ | ||
{ | ||
"tenants" : [ { | ||
"name" : "TENANT_1", | ||
"displayName" : "DISPLAY_NAME", | ||
"allowPasswordSignup" : true, | ||
"enableEmailLinkSignin" : false, | ||
"disableAuth" : true, | ||
"enableAnonymousUser" : false | ||
}, { | ||
"name" : "TENANT_2", | ||
"displayName" : "DISPLAY_NAME", | ||
"allowPasswordSignup" : true, | ||
"enableEmailLinkSignin" : false, | ||
"disableAuth" : true, | ||
"enableAnonymousUser" : false | ||
} ] | ||
} |
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.
We don't use defaults in
DownloadAccountResponse
. Why were they necessary here?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.
The reason we didn't have to use them in DownloadAccountResponse is because of what we do in ListUsersPage.DefaultUserSource.fetch() with the ListUsersResult class as an intermediate storage class. We handle the null case and empty list case there.
But in ListTenantsPage, we decided not to include ListTenantsResult.
Having these defaults set in ListTenantsResponse does feel clunky to me though. Perhaps I should re-add the ListTenantsResult class for consistency?
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.
Perhaps handle them in the getters?