001/* 002 * VM-Operator 003 * Copyright (C) 2024 Michael N. Lipp 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <https://www.gnu.org/licenses/>. 017 */ 018 019package org.jdrupes.vmoperator.manager.events; 020 021import java.util.Optional; 022import org.jdrupes.vmoperator.common.VmDefinitionModel; 023import org.jgrapes.core.Event; 024 025/** 026 * Gets the current display secret and optionally updates it. 027 */ 028@SuppressWarnings("PMD.DataClass") 029public class GetDisplayPassword extends Event<String> { 030 031 private final VmDefinitionModel vmDef; 032 033 /** 034 * Instantiates a new returns the display secret. 035 * 036 * @param vmDef the vm name 037 */ 038 public GetDisplayPassword(VmDefinitionModel vmDef) { 039 this.vmDef = vmDef; 040 } 041 042 /** 043 * Gets the vm definition. 044 * 045 * @return the vm definition 046 */ 047 public VmDefinitionModel vmDefinition() { 048 return vmDef; 049 } 050 051 /** 052 * Return the password. May only be called when the event is completed. 053 * 054 * @return the optional 055 */ 056 public Optional<String> password() { 057 if (!isDone()) { 058 throw new IllegalStateException("Event is not done."); 059 } 060 return currentResults().stream().findFirst(); 061 } 062}