@Inject
AuthService authService;
@Override
protected void run() throws Exception {
Auth auth = authService.authenticate(null, username, password);
if (auth == null) {
throw new IllegalStateException("Cannot authenticate as " + username);
}
log.info("Authenticated as: {}", username);
List<Long> projectIds = authService.resolveProjectName(auth, projectName);
Long projectId;
if (projectIds.isEmpty()) {
log.info("Creating project: {}", projectName);
projectId = authService.createProject(auth, projectName);
} else {
throw new IllegalArgumentException("Project already exists");
}
auth = authService.authenticate(projectId, username, password);
if (auth == null) {
throw new IllegalStateException("Error authenticating to project");
}
log.info("Authenticated to project");
Project project = auth.getProject();
println("Created project: %s", project.getId());
}