in sources/src/main/java/com/google/solutions/jitaccess/auth/Directory.java [35:89]
public record Directory(
@NotNull Directory.Type type,
@Nullable Domain hostedDomain
) {
public static final @NotNull Directory CONSUMER = new Directory(
Type.CONSUMER,
null);
public static final @NotNull Directory PROJECT = new Directory(
Type.PROJECT,
null);
public Directory {
Preconditions.checkArgument(hostedDomain == null || type == Type.CLOUD_IDENTITY);
Preconditions.checkArgument(hostedDomain == null || hostedDomain.type() == Domain.Type.PRIMARY);
}
public Directory(@NotNull Domain hostedDomain) {
this(Type.CLOUD_IDENTITY, hostedDomain);
}
public Directory(@NotNull String hostedDomain) {
this(Type.CLOUD_IDENTITY, new Domain(hostedDomain, Domain.Type.PRIMARY));
}
@Override
public String toString() {
assert this.type != Type.CLOUD_IDENTITY || this.hostedDomain != null;
return switch (this.type) {
case CONSUMER, PROJECT -> this.type.toString();
case CLOUD_IDENTITY -> this.hostedDomain.toString();
};
}
/**
* Type of directory.
*/
public enum Type {
/**
* Consumer account directory, includes Gmail and all other
* consumer accounts.
*/
CONSUMER,
/**
* A Cloud Identity or Workspace account.
*/
CLOUD_IDENTITY,
/**
* A Google Cloud project.
*/
PROJECT
}
}