author | Merge Script |
Thu, 07 Apr 2016 07:08:20 +0200 | |
branch | jv |
changeset 1009 | e25edee0d1e7 |
parent 989 | 4589c38afe55 |
permissions | -rw-r--r-- |
113 | 1 |
"{ Package: 'stx:goodies/monticello' }" |
2 |
||
989
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
3 |
"{ NameSpace: Smalltalk }" |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
4 |
|
113 | 5 |
MCFileBasedRepository subclass:#MCHttpRepository |
6 |
instanceVariableNames:'location user password readerCache' |
|
7 |
classVariableNames:'' |
|
8 |
poolDictionaries:'' |
|
632 | 9 |
category:'SCM-Monticello-Repositories' |
113 | 10 |
! |
11 |
||
12 |
||
192 | 13 |
!MCHttpRepository class methodsFor:'initialization'! |
14 |
||
15 |
clearPasswords |
|
16 |
self allSubInstancesDo: [:ea | ea password: '']. |
|
17 |
||
18 |
! ! |
|
19 |
||
909 | 20 |
!MCHttpRepository class methodsFor:'instance creation'! |
21 |
||
22 |
location: location user: user password: password |
|
23 |
^ self new |
|
24 |
location: location; |
|
25 |
user: user; |
|
26 |
password: password |
|
27 |
! ! |
|
28 |
||
29 |
!MCHttpRepository class methodsFor:'queries'! |
|
113 | 30 |
|
31 |
creationTemplate |
|
192 | 32 |
^self creationTemplateLocation: 'http://www.squeaksource.com/' |
113 | 33 |
user: 'squeak' |
34 |
password: 'squeak' |
|
192 | 35 |
|
113 | 36 |
! |
37 |
||
38 |
creationTemplateLocation: location user: user password: password |
|
192 | 39 |
^ |
113 | 40 |
'MCHttpRepository |
192 | 41 |
location: %1 |
42 |
user: %2 |
|
43 |
password: %3' |
|
44 |
bindWith: location storeString |
|
45 |
with: user storeString |
|
46 |
with: password storeString |
|
47 |
||
48 |
"Modified: / 16-09-2010 / 14:34:12 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
113 | 49 |
! |
50 |
||
51 |
description |
|
52 |
^ 'HTTP' |
|
53 |
! ! |
|
54 |
||
909 | 55 |
!MCHttpRepository methodsFor:'accessing'! |
113 | 56 |
|
778 | 57 |
location |
58 |
^location |
|
59 |
! |
|
60 |
||
113 | 61 |
location: aUrlString |
192 | 62 |
location := aUrlString |
113 | 63 |
! |
64 |
||
65 |
locationWithTrailingSlash |
|
66 |
^ (location endsWith: '/') |
|
67 |
ifTrue: [location] |
|
68 |
ifFalse: [location, '/'] |
|
69 |
! |
|
70 |
||
71 |
password |
|
72 |
self userAndPasswordFromSettingsDo: [:usr :pwd | ^pwd]. |
|
73 |
||
74 |
self user isEmpty ifTrue: [^password]. |
|
75 |
||
76 |
[password isEmpty] whileTrue: [ |
|
77 |
| answer | |
|
78 |
"Give the user a chance to change the login" |
|
192 | 79 |
answer := UIManager default request: 'User name for ' translated, String cr, location |
113 | 80 |
initialAnswer: self user. |
81 |
answer isEmpty |
|
82 |
ifTrue: [^password] |
|
83 |
ifFalse: [self user: answer]. |
|
84 |
||
192 | 85 |
password := UIManager default requestPassword: 'Password for' translated, ' "', self user, '" ', 'at ' translated, String cr, location. |
113 | 86 |
]. |
87 |
||
88 |
^ password |
|
89 |
! |
|
90 |
||
91 |
password: passwordString |
|
192 | 92 |
password := passwordString |
113 | 93 |
! |
94 |
||
95 |
user |
|
96 |
self userAndPasswordFromSettingsDo: [:usr :pwd | ^usr]. |
|
97 |
"not in settings" |
|
98 |
^user |
|
99 |
! |
|
100 |
||
101 |
user: userString |
|
192 | 102 |
user := userString |
909 | 103 |
! ! |
104 |
||
105 |
!MCHttpRepository methodsFor:'as yet unclassified'! |
|
106 |
||
107 |
asCreationTemplate |
|
108 |
^self class creationTemplateLocation: location user: user password: password |
|
109 |
! |
|
110 |
||
111 |
parseFileNamesFromStream: aStream |
|
112 |
| names fullName | |
|
113 |
names := OrderedCollection new. |
|
114 |
[aStream atEnd] whileFalse: |
|
115 |
[[aStream upTo: $<. {$a. $A. nil} includes: aStream next] whileFalse. |
|
116 |
aStream upTo: $". |
|
117 |
aStream atEnd ifFalse: [ |
|
118 |
fullName := aStream upTo: $". |
|
119 |
names add: fullName unescapePercents]]. |
|
120 |
^ names |
|
113 | 121 |
! |
122 |
||
123 |
userAndPasswordFromSettingsDo: aBlock |
|
124 |
"The mcSettings file in ExternalSettings preferenceDirectory should contain entries for each account: |
|
125 |
||
126 |
account1: *myhost.mydomain* user:password |
|
127 |
account2: *otherhost.mydomain/somerep* dXNlcjpwYXNzd29yZA== |
|
128 |
||
129 |
That is it must start with 'account', followed by anything to distinguish accounts, and a colon. Then comes a match expression for the repository url, and after a space the user:password string. |
|
130 |
||
131 |
To not have the clear text password on your disc, you can base64 encode it: |
|
132 |
(Base64MimeConverter mimeEncode: 'user:password' readStream) contents |
|
133 |
" |
|
134 |
||
135 |
| entry userAndPassword | |
|
136 |
Settings ifNotNil: [ |
|
137 |
Settings keysAndValuesDo: [:key :value | |
|
138 |
(key asLowercase beginsWith: 'account') ifTrue: [ |
|
192 | 139 |
entry := value findTokens: ' '. |
113 | 140 |
(entry first match: location) ifTrue: [ |
141 |
userAndPassword := entry second. |
|
142 |
(userAndPassword includes: $:) ifFalse: [ |
|
143 |
userAndPassword := (Base64MimeConverter mimeDecodeToChars: userAndPassword readStream) contents]. |
|
144 |
userAndPassword := userAndPassword findTokens: $:. |
|
145 |
^aBlock value: userAndPassword first |
|
146 |
value: userAndPassword second |
|
147 |
] |
|
148 |
] |
|
149 |
] |
|
150 |
]. |
|
151 |
^nil |
|
152 |
! |
|
153 |
||
154 |
versionReaderForFileNamed: aString |
|
192 | 155 |
readerCache ifNil: [readerCache := Dictionary new]. |
113 | 156 |
^ readerCache at: aString ifAbsent: |
157 |
[self resizeCache: readerCache. |
|
158 |
super versionReaderForFileNamed: aString do: |
|
159 |
[:r | |
|
160 |
r ifNotNil: [readerCache at: aString put: r]]] |
|
161 |
||
162 |
! |
|
163 |
||
164 |
versionReaderForFileNamed: aString do: aBlock |
|
192 | 165 |
|
166 |
| r | |
|
167 |
||
168 |
^(r := self versionReaderForFileNamed: aString) ifNotNil: [aBlock value: r] |
|
169 |
||
170 |
"Modified: / 14-09-2010 / 19:39:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
171 |
! ! |
|
172 |
||
173 |
!MCHttpRepository methodsFor:'displaying'! |
|
174 |
||
175 |
displayString |
|
176 |
||
177 |
^location |
|
178 |
||
179 |
"Created: / 14-09-2010 / 23:20:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
113 | 180 |
! ! |
181 |
||
909 | 182 |
!MCHttpRepository methodsFor:'queries'! |
183 |
||
184 |
urlForFileNamed: aString |
|
185 |
^ self locationWithTrailingSlash, aString utf8Encoded |
|
186 |
||
187 |
"Modified: / 14-09-2010 / 19:32:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
188 |
! ! |
|
189 |
||
113 | 190 |
!MCHttpRepository methodsFor:'required'! |
191 |
||
192 |
allFileNames |
|
192 | 193 |
| response | |
194 |
response := HTTPInterface get: self locationWithTrailingSlash, '?C=M;O=D' userName: self user password: self password. |
|
195 |
response responseCode ~= 200 |
|
473 | 196 |
ifTrue: [self error:('Could not access "',location,'" (',response response asString,')')]. |
192 | 197 |
^ self parseFileNamesFromStream: response data readStream |
198 |
||
199 |
"Modified: / 14-09-2010 / 19:16:59 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
473 | 200 |
"Modified: / 07-09-2011 / 12:34:23 / cg" |
113 | 201 |
! |
202 |
||
203 |
description |
|
204 |
^ location |
|
205 |
! |
|
206 |
||
192 | 207 |
flushCache |
208 |
super flushCache. |
|
209 |
readerCache := nil. |
|
210 |
! |
|
211 |
||
113 | 212 |
readStreamForFileNamed: aString do: aBlock |
192 | 213 |
|
214 |
| response | |
|
215 |
response := HTTPInterface get: (self urlForFileNamed: aString) userName: self user password: self password. |
|
216 |
^response responseCode == 200 |
|
217 |
ifTrue: [aBlock value: response data readStream]. |
|
218 |
||
219 |
"Modified: / 14-09-2010 / 19:38:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
113 | 220 |
! |
221 |
||
222 |
writeStreamForFileNamed: aString replace: ignoreBoolean do: aBlock |
|
989
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
223 |
| stream response | |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
224 |
stream := RWBinaryOrTextStream on: String new. |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
225 |
aBlock value: stream. |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
226 |
"/ response := HTTPSocket |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
227 |
"/ httpPut: stream contents |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
228 |
"/ to: (self urlForFileNamed: aString) |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
229 |
"/ user: self user |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
230 |
"/ passwd: self password. |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
231 |
response := HTTPInterface |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
232 |
request:#PUT |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
233 |
url:(self urlForFileNamed: aString) |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
234 |
fromHost:nil port:nil |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
235 |
accept:#('*/*') |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
236 |
fromDocument:nil |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
237 |
userName:self user password: self password |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
238 |
contentType:'application/octet-stream' |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
239 |
contents:stream contents asString. |
113 | 240 |
|
989
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
241 |
(#( 201 200 ) includes: response responseCode) ifFalse: [self error: response]. |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
242 |
|
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
243 |
"Modified: / 24-04-2015 / 00:12:42 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
113 | 244 |
! ! |
245 |
||
246 |
!MCHttpRepository class methodsFor:'documentation'! |
|
247 |
||
277 | 248 |
version |
909 | 249 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCHttpRepository.st,v 1.7 2014-02-12 14:53:40 cg Exp $' |
277 | 250 |
! |
251 |
||
192 | 252 |
version_CVS |
909 | 253 |
^ '$Header: /cvs/stx/stx/goodies/monticello/MCHttpRepository.st,v 1.7 2014-02-12 14:53:40 cg Exp $' |
192 | 254 |
! |
255 |
||
989
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
256 |
version_HG |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
257 |
|
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
258 |
^ '$Changeset: <not expanded> $' |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
259 |
! |
4589c38afe55
Initial support for commit to MCHttpRepositories.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
909
diff
changeset
|
260 |
|
192 | 261 |
version_SVN |
909 | 262 |
^ '$Id: MCHttpRepository.st,v 1.7 2014-02-12 14:53:40 cg Exp $' |
113 | 263 |
! ! |
778 | 264 |