001/**
002 * Copyright (C) 2006-2021 Talend Inc. - www.talend.com
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.talend.sdk.component.api;
017
018import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
019import static java.lang.annotation.ElementType.FIELD;
020import static java.lang.annotation.ElementType.PARAMETER;
021import static java.lang.annotation.RetentionPolicy.RUNTIME;
022
023import java.lang.annotation.Retention;
024import java.lang.annotation.Target;
025
026@Target({ FIELD, PARAMETER })
027@Retention(RUNTIME)
028public @interface DecryptedServer {
029
030    /**
031     * @return the settings.xml serverId to match.
032     */
033    String value();
034
035    /**
036     * @return the list of conditions to meet to activate this decrypting.
037     */
038    Conditions conditions() default @Conditions({ @Condition(forSystemProperty = "talend.junit.http.passthrough"),
039            @Condition(forSystemProperty = "talend.maven.decrypter.active") });
040
041    /**
042     * @return true to always try to read the server whatever the condition state
043     * and fallback on the mock values if not found and conditions are met.
044     */
045    boolean alwaysTryLookup() default true;
046
047    /**
048     * @return the username when forSystemProperty test fails.
049     */
050    String defaultUsername() default "username";
051
052    /**
053     * @return the username when forSystemProperty test fails.
054     */
055    String defaultPassword() default "password";
056
057    @Target(ANNOTATION_TYPE)
058    @Retention(RUNTIME)
059    @interface Conditions {
060
061        /**
062         * @return the list of conditions to meet to use an actual server.
063         */
064        Condition[] value();
065
066        /**
067         * @return the way to combine the conditions.
068         */
069        Combination combination() default Combination.OR;
070    }
071
072    enum Combination {
073        AND,
074        OR
075    }
076
077    @Target(ANNOTATION_TYPE)
078    @Retention(RUNTIME)
079    @interface Condition {
080
081        /**
082         * @return a system property name to use for the test.
083         */
084        String forSystemProperty();
085
086        /**
087         * @return the expected system property to activate the condition.
088         */
089        String expectedValue() default "true";
090
091        /**
092         * @return true if the system property can be null.
093         */
094        boolean supportsNull() default false;
095    }
096}