16
16
17
17
package cd .go .contrib .elasticagent ;
18
18
19
+ import cd .go .contrib .elasticagent .model .AuthenticationStrategy ;
19
20
import com .google .gson .annotations .Expose ;
20
21
import com .google .gson .annotations .SerializedName ;
21
- import org .apache .commons .lang3 .StringUtils ;
22
22
import org .joda .time .Period ;
23
23
24
- import static cd .go .contrib .elasticagent .executors .GetPluginConfigurationExecutor .*;
25
24
import static cd .go .contrib .elasticagent .utils .Util .GSON ;
26
25
27
26
public class PluginSettings {
@@ -31,29 +30,45 @@ public class PluginSettings {
31
30
32
31
@ Expose
33
32
@ SerializedName ("auto_register_timeout" )
34
- private String autoRegisterTimeout ;
33
+ private Integer autoRegisterTimeout = 10 ;
35
34
36
35
@ Expose
37
36
@ SerializedName ("pending_pods_count" )
38
- private String pendingPodsCount ;
37
+ private Integer maxPendingPods = 10 ;
38
+
39
+ @ Expose
40
+ @ SerializedName ("authentication_strategy" )
41
+ private String authenticationStrategy = AuthenticationStrategy .OAUTH_TOKEN .name ();
42
+
43
+ @ Expose
44
+ @ SerializedName ("oauth_token" )
45
+ private String oauthToken ;
39
46
40
47
@ Expose
41
48
@ SerializedName ("kubernetes_cluster_url" )
42
- private String kubernetesClusterUrl ;
49
+ private String clusterUrl ;
43
50
44
51
@ Expose
45
52
@ SerializedName ("kubernetes_cluster_ca_cert" )
46
- private String kubernetesClusterCACert ;
53
+ private String clusterCACertData ;
54
+
55
+ @ Expose
56
+ @ SerializedName ("client_key_data" )
57
+ private String clientKeyData ;
58
+
59
+ @ Expose
60
+ @ SerializedName ("client_cert_data" )
61
+ private String clientCertData ;
47
62
48
63
private Period autoRegisterPeriod ;
49
64
50
65
public PluginSettings () {
51
66
}
52
67
53
- public PluginSettings (String goServerUrl , String clusterUrl , String clusterCACert ) {
68
+ public PluginSettings (String goServerUrl , String clusterUrl , String clusterCACertData ) {
54
69
this .goServerUrl = goServerUrl ;
55
- this .kubernetesClusterUrl = clusterUrl ;
56
- this .kubernetesClusterCACert = clusterCACert ;
70
+ this .clusterUrl = clusterUrl ;
71
+ this .clusterCACertData = clusterCACertData ;
57
72
}
58
73
59
74
public static PluginSettings fromJSON (String json ) {
@@ -62,52 +77,45 @@ public static PluginSettings fromJSON(String json) {
62
77
63
78
public Period getAutoRegisterPeriod () {
64
79
if (this .autoRegisterPeriod == null ) {
65
- this .autoRegisterPeriod = new Period ().withMinutes (Integer . parseInt ( getAutoRegisterTimeout () ));
80
+ this .autoRegisterPeriod = new Period ().withMinutes (getAutoRegisterTimeout ());
66
81
}
67
82
return this .autoRegisterPeriod ;
68
83
}
69
84
70
- String getAutoRegisterTimeout () {
71
- if (autoRegisterTimeout == null ) {
72
- autoRegisterTimeout = "10" ;
73
- }
85
+ Integer getAutoRegisterTimeout () {
74
86
return autoRegisterTimeout ;
75
87
}
76
88
77
- public Integer getMaximumPendingAgentsCount () {
78
- if (pendingPodsCount == null ) {
79
- pendingPodsCount = "10" ;
80
- }
81
-
82
- return Integer .valueOf (pendingPodsCount );
89
+ public Integer getMaxPendingPods () {
90
+ return Integer .valueOf (maxPendingPods );
83
91
}
84
92
85
93
public String getGoServerUrl () {
86
94
return goServerUrl ;
87
95
}
88
96
89
- public String getKubernetesClusterUrl () {
90
- return kubernetesClusterUrl ;
97
+ public AuthenticationStrategy getAuthenticationStrategy () {
98
+ return AuthenticationStrategy . from ( authenticationStrategy ) ;
91
99
}
92
100
93
- public String getKubernetesClusterCACert () {
94
- return kubernetesClusterCACert ;
101
+ public String getOauthToken () {
102
+ return oauthToken ;
95
103
}
96
104
97
- public void setGoServerUrl ( String goServerUrl ) {
98
- this . goServerUrl = goServerUrl ;
105
+ public String getClusterUrl ( ) {
106
+ return clusterUrl ;
99
107
}
100
108
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 ());
109
+ public String getCaCertData () {
110
+ return clusterCACertData ;
111
+ }
105
112
106
- if ( StringUtils . isAnyBlank ( goServerUrl , clusterUrl , clusterCACert ) ) {
107
- return null ;
108
- }
113
+ public String getClientKeyData ( ) {
114
+ return clientKeyData ;
115
+ }
109
116
110
- return new PluginSettings (goServerUrl , clusterUrl , clusterCACert );
117
+ public String getClientCertData () {
118
+ return clientCertData ;
111
119
}
112
120
113
121
@ Override
@@ -120,23 +128,30 @@ public boolean equals(Object o) {
120
128
if (goServerUrl != null ? !goServerUrl .equals (that .goServerUrl ) : that .goServerUrl != null ) return false ;
121
129
if (autoRegisterTimeout != null ? !autoRegisterTimeout .equals (that .autoRegisterTimeout ) : that .autoRegisterTimeout != null )
122
130
return false ;
123
- if (pendingPodsCount != null ? !pendingPodsCount .equals (that .pendingPodsCount ) : that .pendingPodsCount != null )
131
+ if (maxPendingPods != null ? !maxPendingPods .equals (that .maxPendingPods ) : that .maxPendingPods != null )
132
+ return false ;
133
+ if (authenticationStrategy != null ? !authenticationStrategy .equals (that .authenticationStrategy ) : that .authenticationStrategy != null )
124
134
return false ;
125
- if (kubernetesClusterUrl != null ? !kubernetesClusterUrl .equals (that .kubernetesClusterUrl ) : that .kubernetesClusterUrl != null )
135
+ if (clusterUrl != null ? !clusterUrl .equals (that .clusterUrl ) : that .clusterUrl != null ) return false ;
136
+ if (clusterCACertData != null ? !clusterCACertData .equals (that .clusterCACertData ) : that .clusterCACertData != null )
126
137
return false ;
127
- if (kubernetesClusterCACert != null ? !kubernetesClusterCACert .equals (that .kubernetesClusterCACert ) : that .kubernetesClusterCACert != null )
138
+ if (oauthToken != null ? !oauthToken .equals (that .oauthToken ) : that .oauthToken != null ) return false ;
139
+ if (clientKeyData != null ? !clientKeyData .equals (that .clientKeyData ) : that .clientKeyData != null )
128
140
return false ;
129
- return autoRegisterPeriod != null ? autoRegisterPeriod .equals (that .autoRegisterPeriod ) : that .autoRegisterPeriod == null ;
141
+ return clientCertData != null ? clientCertData .equals (that .clientCertData ) : that .clientCertData == null ;
130
142
}
131
143
132
144
@ Override
133
145
public int hashCode () {
134
146
int result = goServerUrl != null ? goServerUrl .hashCode () : 0 ;
135
147
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 );
148
+ result = 31 * result + (maxPendingPods != null ? maxPendingPods .hashCode () : 0 );
149
+ result = 31 * result + (authenticationStrategy != null ? authenticationStrategy .hashCode () : 0 );
150
+ result = 31 * result + (clusterUrl != null ? clusterUrl .hashCode () : 0 );
151
+ result = 31 * result + (clusterCACertData != null ? clusterCACertData .hashCode () : 0 );
152
+ result = 31 * result + (oauthToken != null ? oauthToken .hashCode () : 0 );
153
+ result = 31 * result + (clientKeyData != null ? clientKeyData .hashCode () : 0 );
154
+ result = 31 * result + (clientCertData != null ? clientCertData .hashCode () : 0 );
140
155
return result ;
141
156
}
142
157
}
0 commit comments