@@ -10,17 +10,17 @@ import com.dtolabs.rundeck.core.resources.format.ResourceFormatParser
1010import com.dtolabs.rundeck.core.resources.format.ResourceFormatParserException
1111import com.dtolabs.rundeck.core.resources.format.UnsupportedFormatException
1212import com.dtolabs.utils.Streams
13- import com.dtolabs.rundeck.core.execution.ExecutionContext ;
14- import com.dtolabs.rundeck.core.execution.ExecutionContextImpl ;
13+ import com.dtolabs.rundeck.core.execution.ExecutionContext
14+ import com.dtolabs.rundeck.core.execution.ExecutionContextImpl
1515import com.rundeck.plugin.util.GitPluginUtil
16- import org.rundeck.app.spi.Services ;
17- import com.dtolabs.rundeck.core.storage.keys.KeyStorageTree ;
18- import com.dtolabs.rundeck.core.execution.ExecutionListener
19-
16+ import groovy.transform.CompileStatic
17+ import org.rundeck.app.spi.Services
18+ import com.dtolabs.rundeck.core.storage.keys.KeyStorageTree
2019
2120/**
2221 * Created by luistoledo on 12/18/17.
2322 */
23+ @CompileStatic
2424class GitResourceModel implements ResourceModelSource , WriteableModelSource {
2525
2626 private Properties configuration;
@@ -38,7 +38,14 @@ class GitResourceModel implements ResourceModelSource , WriteableModelSource{
3838 }
3939
4040 GitResourceModel (Services services , Properties configuration , Framework framework ) {
41+ configure(configuration,framework,services)
42+ }
43+
44+ GitResourceModel (Properties configuration , Framework framework ) {
45+ configure(configuration,framework, null )
46+ }
4147
48+ def configure (Properties configuration , Framework framework , Services services ){
4249 this . configuration = configuration
4350 this . framework = framework
4451
@@ -51,61 +58,23 @@ class GitResourceModel implements ResourceModelSource , WriteableModelSource{
5158 gitManager = new GitManager (configuration)
5259 }
5360
54- ExecutionContext context = null ;
55-
56- if (services!= null ){
57- context = new ExecutionContextImpl.Builder ()
61+ if (services && configuration. getProperty(GitResourceModelFactory . GIT_PASSWORD_STORAGE_PATH )){
62+ ExecutionContext context = new ExecutionContextImpl.Builder ()
5863 .framework(framework)
5964 .storageTree(services. getService(KeyStorageTree . class))
6065 .build();
61- }else {
62- context = new ExecutionContextImpl.Builder ()
63- .framework(framework)
64- .build();
65- }
6666
67- if (configuration. getProperty(GitResourceModelFactory . GIT_PASSWORD_STORAGE )){
68- def password = GitPluginUtil . getFromKeyStorage(configuration. getProperty(GitResourceModelFactory . GIT_PASSWORD_STORAGE ), context)
67+ def password = GitPluginUtil . getFromKeyStorage(configuration. getProperty(GitResourceModelFactory . GIT_PASSWORD_STORAGE_PATH ), context)
6968 gitManager. setGitPassword(password)
7069 }
7170
72- if (configuration. getProperty(GitResourceModelFactory . GIT_KEY_STORAGE )) {
73- gitManager. setSshPrivateKeyPath (configuration. getProperty(GitResourceModelFactory . GIT_KEY_STORAGE ))
71+ if (configuration. getProperty(GitResourceModelFactory . GIT_PASSWORD_STORAGE )) {
72+ gitManager. setGitPassword (configuration. getProperty(GitResourceModelFactory . GIT_PASSWORD_STORAGE ))
7473 }
75- }
76-
77- GitResourceModel (Properties configuration , Framework framework ) {
78- this . configuration = configuration
79- this . framework = framework
80-
81- this . extension= configuration. getProperty(GitResourceModelFactory . GIT_FORMAT_FILE )
82- this . writable= Boolean . valueOf(configuration. getProperty(GitResourceModelFactory . WRITABLE ))
83- this . fileName= configuration. getProperty(GitResourceModelFactory . GIT_FILE )
84- this . localPath= configuration. getProperty(GitResourceModelFactory . GIT_BASE_DIRECTORY )
85-
86- if (gitManager== null ){
87- gitManager = new GitManager (configuration)
88- }
89-
90- ExecutionContext context = new ExecutionContextImpl.Builder ()
91- .framework(this . framework)
92- .storageTree(services. getService(KeyStorageTree . class))
93- .build();
94-
95-
96- if (configuration. getProperty(GitResourceModelFactory . GIT_PASSWORD_STORAGE )){
97- def password = GitPluginUtil . getFromKeyStorage(configuration. getProperty(GitResourceModelFactory . GIT_PASSWORD_STORAGE ), context)
98- gitManager. setGitPassword(password)
99- }
100-
101- // if(configuration.getProperty(GitResourceModelFactory.GIT_PASSWORD_STORAGE)) {
102- // gitManager.setGitPassword(configuration.getProperty(GitResourceModelFactory.GIT_PASSWORD_STORAGE))
103- // }
10474
10575 if (configuration. getProperty(GitResourceModelFactory . GIT_KEY_STORAGE )) {
10676 gitManager. setSshPrivateKeyPath(configuration. getProperty(GitResourceModelFactory . GIT_KEY_STORAGE ))
10777 }
108-
10978 }
11079
11180 @Override
@@ -133,7 +102,6 @@ class GitResourceModel implements ResourceModelSource , WriteableModelSource{
133102 throw new ResourceModelSourceException (
134103 " Error requesting Resource Model Source from GIT, " + e. getMessage(),e);
135104 }
136- return null
137105 }
138106
139107 private ResourceFormatParser getResourceFormatParser () throws UnsupportedFormatException {
@@ -151,18 +119,18 @@ class GitResourceModel implements ResourceModelSource , WriteableModelSource{
151119 }
152120
153121 @Override
154- public SourceType getSourceType () {
122+ SourceType getSourceType () {
155123 return writable ? SourceType . READ_WRITE : SourceType . READ_ONLY ;
156124 }
157125
158126 @Override
159- public WriteableModelSource getWriteable () {
127+ WriteableModelSource getWriteable () {
160128 return writable ? this : null ;
161129 }
162130
163131
164132 @Override
165- public String getSyntaxMimeType () {
133+ String getSyntaxMimeType () {
166134 try {
167135 return getResourceFormatParser(). getPreferredMimeType();
168136 } catch (UnsupportedFormatException e) {
@@ -193,7 +161,7 @@ class GitResourceModel implements ResourceModelSource , WriteableModelSource{
193161 }
194162
195163 @Override
196- public long writeData (InputStream data ) throws IOException , ResourceModelSourceException {
164+ long writeData (InputStream data ) throws IOException , ResourceModelSourceException {
197165 if (! writable) {
198166 throw new IllegalArgumentException (" Cannot write to file, it is not configured to be writeable" );
199167 }
@@ -225,7 +193,7 @@ class GitResourceModel implements ResourceModelSource , WriteableModelSource{
225193 }
226194
227195 @Override
228- public String getSourceDescription () {
196+ String getSourceDescription () {
229197 String gitURL= configuration. getProperty(GitResourceModelFactory . GIT_URL )
230198 return " Git repo: " + gitURL+ " , file:" + this . fileName;
231199 }
0 commit comments