18
18
19
19
import com .google .gson .annotations .Expose ;
20
20
import com .google .gson .annotations .SerializedName ;
21
+ import org .apache .commons .lang3 .StringUtils ;
21
22
import org .joda .time .Period ;
22
23
24
+ import static cd .go .contrib .elasticagent .executors .GetPluginConfigurationExecutor .*;
23
25
import static cd .go .contrib .elasticagent .utils .Util .GSON ;
24
26
25
27
public class PluginSettings {
@@ -39,48 +41,23 @@ public class PluginSettings {
39
41
@ SerializedName ("kubernetes_cluster_url" )
40
42
private String kubernetesClusterUrl ;
41
43
42
- @ Expose
43
- @ SerializedName ("kubernetes_cluster_username" )
44
- private String kubernetesClusterUsername ;
45
-
46
- @ Expose
47
- @ SerializedName ("kubernetes_cluster_password" )
48
- private String kubernetesClusterPassword ;
49
-
50
44
@ Expose
51
45
@ SerializedName ("kubernetes_cluster_ca_cert" )
52
46
private String kubernetesClusterCACert ;
53
47
54
48
private Period autoRegisterPeriod ;
55
49
56
- public static PluginSettings fromJSON (String json ) {
57
- return GSON .fromJson (json , PluginSettings .class );
50
+ public PluginSettings () {
58
51
}
59
52
60
- @ Override
61
- public boolean equals (Object o ) {
62
- if (this == o ) return true ;
63
- if (!(o instanceof PluginSettings )) return false ;
64
- PluginSettings that = (PluginSettings ) o ;
65
-
66
- if (goServerUrl != null ? !goServerUrl .equals (that .goServerUrl ) : that .goServerUrl != null ) return false ;
67
- if (autoRegisterTimeout != null ? !autoRegisterTimeout .equals (that .autoRegisterTimeout ) : that .autoRegisterTimeout != null )
68
- return false ;
69
- if (pendingPodsCount != null ? !pendingPodsCount .equals (that .pendingPodsCount ) : that .pendingPodsCount != null )
70
- return false ;
71
- if (kubernetesClusterUrl != null ? !kubernetesClusterUrl .equals (that .kubernetesClusterUrl ) : that .kubernetesClusterUrl != null )
72
- return false ;
73
- return autoRegisterPeriod != null ? autoRegisterPeriod .equals (that .autoRegisterPeriod ) : that .autoRegisterPeriod == null ;
53
+ public PluginSettings (String goServerUrl , String clusterUrl , String clusterCACert ) {
54
+ this .goServerUrl = goServerUrl ;
55
+ this .kubernetesClusterUrl = clusterUrl ;
56
+ this .kubernetesClusterCACert = clusterCACert ;
74
57
}
75
58
76
- @ Override
77
- public int hashCode () {
78
- int result = goServerUrl != null ? goServerUrl .hashCode () : 0 ;
79
- result = 31 * result + (autoRegisterTimeout != null ? autoRegisterTimeout .hashCode () : 0 );
80
- result = 31 * result + (pendingPodsCount != null ? pendingPodsCount .hashCode () : 0 );
81
- result = 31 * result + (kubernetesClusterUrl != null ? kubernetesClusterUrl .hashCode () : 0 );
82
- result = 31 * result + (autoRegisterPeriod != null ? autoRegisterPeriod .hashCode () : 0 );
83
- return result ;
59
+ public static PluginSettings fromJSON (String json ) {
60
+ return GSON .fromJson (json , PluginSettings .class );
84
61
}
85
62
86
63
public Period getAutoRegisterPeriod () {
@@ -113,19 +90,53 @@ public String getKubernetesClusterUrl() {
113
90
return kubernetesClusterUrl ;
114
91
}
115
92
116
- public String getKubernetesClusterUsername () {
117
- return kubernetesClusterUsername ;
118
- }
119
-
120
- public String getKubernetesClusterPassword () {
121
- return kubernetesClusterPassword ;
122
- }
123
-
124
93
public String getKubernetesClusterCACert () {
125
94
return kubernetesClusterCACert ;
126
95
}
127
96
128
97
public void setGoServerUrl (String goServerUrl ) {
129
98
this .goServerUrl = goServerUrl ;
130
99
}
100
+
101
+ public static PluginSettings fromEnv () {
102
+ final String goServerUrl = System .getenv (GO_SERVER_URL .key ());
103
+ final String clusterUrl = System .getenv (CLUSTER_URL .key ());
104
+ final String clusterCACert = System .getenv (CLUSTER_CA_CERT .key ());
105
+
106
+ if (StringUtils .isAnyBlank (goServerUrl , clusterUrl , clusterCACert )) {
107
+ return null ;
108
+ }
109
+
110
+ return new PluginSettings (goServerUrl , clusterUrl , clusterCACert );
111
+ }
112
+
113
+ @ Override
114
+ public boolean equals (Object o ) {
115
+ if (this == o ) return true ;
116
+ if (!(o instanceof PluginSettings )) return false ;
117
+
118
+ PluginSettings that = (PluginSettings ) o ;
119
+
120
+ if (goServerUrl != null ? !goServerUrl .equals (that .goServerUrl ) : that .goServerUrl != null ) return false ;
121
+ if (autoRegisterTimeout != null ? !autoRegisterTimeout .equals (that .autoRegisterTimeout ) : that .autoRegisterTimeout != null )
122
+ return false ;
123
+ if (pendingPodsCount != null ? !pendingPodsCount .equals (that .pendingPodsCount ) : that .pendingPodsCount != null )
124
+ return false ;
125
+ if (kubernetesClusterUrl != null ? !kubernetesClusterUrl .equals (that .kubernetesClusterUrl ) : that .kubernetesClusterUrl != null )
126
+ return false ;
127
+ if (kubernetesClusterCACert != null ? !kubernetesClusterCACert .equals (that .kubernetesClusterCACert ) : that .kubernetesClusterCACert != null )
128
+ return false ;
129
+ return autoRegisterPeriod != null ? autoRegisterPeriod .equals (that .autoRegisterPeriod ) : that .autoRegisterPeriod == null ;
130
+ }
131
+
132
+ @ Override
133
+ public int hashCode () {
134
+ int result = goServerUrl != null ? goServerUrl .hashCode () : 0 ;
135
+ result = 31 * result + (autoRegisterTimeout != null ? autoRegisterTimeout .hashCode () : 0 );
136
+ result = 31 * result + (pendingPodsCount != null ? pendingPodsCount .hashCode () : 0 );
137
+ result = 31 * result + (kubernetesClusterUrl != null ? kubernetesClusterUrl .hashCode () : 0 );
138
+ result = 31 * result + (kubernetesClusterCACert != null ? kubernetesClusterCACert .hashCode () : 0 );
139
+ result = 31 * result + (autoRegisterPeriod != null ? autoRegisterPeriod .hashCode () : 0 );
140
+ return result ;
141
+ }
131
142
}
0 commit comments