Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honouring Proxy Settings in P11 #1750

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BaselineOfIceberg/BaselineOfIceberg.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ BaselineOfIceberg >> libgit: spec [
baseline: 'LibGit'
with: [
spec
repository: 'github://pharo-vcs/libgit2-pharo-bindings:v3.0.6.1';
repository: 'github://pharo-vcs/libgit2-pharo-bindings:v3.0.8';
loads: 'default' ].
spec
project: 'LibGit-Tests'
Expand Down
2 changes: 2 additions & 0 deletions Iceberg-Libgit/IceGitClone.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ IceGitClone >> execute [
repo := LGitRepository on: location.
cloneOptions := repo cloneOptionsStructureClass withCredentialsProvider: (IceCredentialsProvider defaultForRemoteUrl: url).

Iceberg configureLGitProxyOpt: cloneOptions fetchOptions proxyOptions.

"Keeping references, because if not the GC take them."
checkoutOptions := cloneOptions checkoutOptions.
callbacks := cloneOptions fetchOptions callbacks.
Expand Down
58 changes: 39 additions & 19 deletions Iceberg-Libgit/IceGitLocalBranch.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,52 @@ IceGitLocalBranch >> name [

{ #category : #'private - pushing' }
IceGitLocalBranch >> pushBranchToRemote: aRemote gitRemote: gitRemote progress: pushProgress [

gitRemote

| pushOptions |
pushOptions := gitRemote ffiLibrary uniqueInstance
pushOptionsStructureClass defaults
callbacks:
((gitRemote ffiLibrary uniqueInstance
remoteCallbacksStructureClass withProvider:
(IceCredentialsProvider defaultForRemote:
aRemote))
pushTransferProgress: pushProgress;
yourself);
yourself.

Iceberg configureLGitProxyOpt: pushOptions proxyOptions.

gitRemote
pushWithRefSpec: (LGitRefSpec new
source: self fullname;
destination: self fullname;
yourself)
pushOptions: (gitRemote ffiLibrary uniqueInstance pushOptionsStructureClass defaults
callbacks: ((gitRemote ffiLibrary uniqueInstance remoteCallbacksStructureClass withProvider: (IceCredentialsProvider defaultForRemote: aRemote))
pushTransferProgress: pushProgress;
yourself);
yourself)
source: self fullname;
destination: self fullname;
yourself)
pushOptions: pushOptions
]

{ #category : #'private - pushing' }
IceGitLocalBranch >> pushTag: tag toRemote: aRemote gitRemote: gitRemote progress: pushProgress [

gitRemote
| pushOptions |
pushOptions := gitRemote ffiLibrary uniqueInstance
pushOptionsStructureClass defaults
callbacks:
((gitRemote ffiLibrary uniqueInstance
remoteCallbacksStructureClass withProvider:
(IceCredentialsProvider defaultForRemote:
aRemote))
pushTransferProgress: pushProgress;
yourself);
yourself.

Iceberg configureLGitProxyOpt: pushOptions proxyOptions.

gitRemote
pushWithRefSpec: (LGitRefSpec new
source: 'refs/tags/' , tag name;
destination: 'refs/tags/' , tag name;
yourself)
pushOptions: (gitRemote ffiLibrary uniqueInstance pushOptionsStructureClass defaults
callbacks: ((gitRemote ffiLibrary uniqueInstance remoteCallbacksStructureClass withProvider: (IceCredentialsProvider defaultForRemote: aRemote))
pushTransferProgress: pushProgress;
yourself);
yourself)
source: 'refs/tags/' , tag name;
destination: 'refs/tags/' , tag name;
yourself)
pushOptions: pushOptions
]

{ #category : #'private - pushing' }
Expand Down
50 changes: 27 additions & 23 deletions Iceberg-Libgit/IceGitRemote.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,40 @@ IceGitRemote >> branches [
]

{ #category : #fetching }
IceGitRemote >> fetch [
IceGitRemote >> doFetchWithRefSpec: refSpec [

localRepository handleLibgitError: [
[ (LGitRemote of: self repositoryHandle named: self name)
[
(LGitRemote of: self repositoryHandle named: self name)
lookup;
fetchWithCredentials: (IceCredentialsProvider defaultForRemote: self)
andProgressCallback: IceGitTransferProgress new ]
fetchWithCredentials:
(IceCredentialsProvider defaultForRemote: self)
andProgressCallback: IceGitTransferProgress new
refSpec: refSpec
proxyConfigurationBlock: [ :proxyOpt | Iceberg configureLGitProxyOpt: proxyOpt ] ]
on: LGitAbstractError
do: [ :e | e acceptError: (IceLibgitErrorVisitor onContext: self) ].

"Call post fetch to fix unknown commits"
localRepository postFetch ]
do: [ :e | e acceptError: (IceLibgitErrorVisitor onContext: self) ] ]
]

{ #category : #fetching }
IceGitRemote >> fetch [

self doFetchWithRefSpec: nil.

"Call post fetch to fix unknown commits"
localRepository postFetch
]

{ #category : #fetching }
IceGitRemote >> fetchBranch: aBranch [

localRepository handleLibgitError: [
[ | refSpec remote |
refSpec := LGitRefSpec
fromString:
('{2}:refs/remotes/{1}/{2}'
format:
{self name.
aBranch name}).
(remote := LGitRemote of: self repositoryHandle named: self name)
lookup;
fetchWithCredentials: (IceCredentialsProvider defaultForRemote: self) refSpec: refSpec ]
on: LGitAbstractError
do: [ :e | e acceptError: (IceLibgitErrorVisitor onContext: self) ] ]

| refSpec |
refSpec := LGitRefSpec fromString:
('{2}:refs/remotes/{1}/{2}' format: {
self name.
aBranch name }).

self doFetchWithRefSpec: refSpec
]

{ #category : #branches }
Expand Down
79 changes: 79 additions & 0 deletions Iceberg-Tests/IceProxySettingsTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
Class {
#name : #IceProxySettingsTest,
#superclass : #TestCase,
#instVars : [
'oldNetworkSettingsHost',
'oldNetworkSettingsPort'
],
#category : #'Iceberg-Tests-Core-Remotes'
}

{ #category : #asserting }
IceProxySettingsTest >> assertProxyURLExternalStringHasValue: aString [

| value |
value := Iceberg proxyURLExternalString.

self assert: value isExternalAddress.
self deny: value isNull.

self assert: value utf8StringFromCString equals: aString
]

{ #category : #running }
IceProxySettingsTest >> setUp [

super setUp.

oldNetworkSettingsHost := NetworkSystemSettings httpProxyServer.
oldNetworkSettingsPort := NetworkSystemSettings httpProxyPort.
]

{ #category : #running }
IceProxySettingsTest >> tearDown [

NetworkSystemSettings httpProxyServer: oldNetworkSettingsHost.
NetworkSystemSettings httpProxyPort: oldNetworkSettingsPort.

super tearDown
]

{ #category : #tests }
IceProxySettingsTest >> testConfigureProxyOptWithCorrectProxyUrl [

| proxyOpt |

NetworkSystemSettings httpProxyServer: 'myproxy.company.com'.
NetworkSystemSettings httpProxyPort: 8080.

proxyOpt := LGitProxyOptions defaults.
Iceberg configureLGitProxyOpt: proxyOpt.

self assert: proxyOpt prim_url value equals: Iceberg proxyURLExternalString value.
self assert: proxyOpt prim_url utf8StringFromCString equals: 'https://myproxy.company.com:8080'.
]

{ #category : #tests }
IceProxySettingsTest >> testEmptyHostReturnsNullPointer [

NetworkSystemSettings httpProxyServer: ''.

self assert: Iceberg proxyURLExternalString isNull.
]

{ #category : #tests }
IceProxySettingsTest >> testHostAndDefaultPortHasCorrectAddress [

NetworkSystemSettings httpProxyServer: 'myproxy.company.com'.

self assertProxyURLExternalStringHasValue: 'https://myproxy.company.com:80'.
]

{ #category : #tests }
IceProxySettingsTest >> testHostAndPortHasCorrectAddress [

NetworkSystemSettings httpProxyServer: 'myproxy.company.com'.
NetworkSystemSettings httpProxyPort: 8080.

self assertProxyURLExternalStringHasValue: 'https://myproxy.company.com:8080'.
]
54 changes: 54 additions & 0 deletions Iceberg/Iceberg.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Class {
#superclass : #Object,
#classVars : [
'EnableMetacelloIntegration',
'ProxyURLExternalString',
'RemoteTypeSelector',
'ShowSystemRepositories'
],
Expand Down Expand Up @@ -64,6 +65,27 @@ Iceberg class >> bootstrapWithCommitId: commitId packageList: packageNameList [
repository register
]

{ #category : #proxy }
Iceberg class >> configureLGitProxyOpt: aLGitProxyOptions [

| proxyURL |
proxyURL := self proxyURLExternalString.

"If there is not configured proxy, let's return"
proxyURL isNull ifTrue: [ ^ self ].

aLGitProxyOptions prim_url: proxyURL
]

{ #category : #proxy }
Iceberg class >> createProxyURLExternalString [

NetworkSystemSettings httpProxyServer isEmpty
ifTrue: [ ^ ProxyURLExternalString := ExternalAddress null ].

ProxyURLExternalString := ExternalAddress fromString: self formatNetworkSettingsProxyServer.
]

{ #category : #settings }
Iceberg class >> enableMetacelloIntegration [
^ EnableMetacelloIntegration ifNil: [ EnableMetacelloIntegration := true ]
Expand All @@ -74,6 +96,31 @@ Iceberg class >> enableMetacelloIntegration: anObject [
EnableMetacelloIntegration := anObject
]

{ #category : #proxy }
Iceberg class >> ensureProxyURLExternalString [


"If we have a valid string in the external memory, we check its value"
(ProxyURLExternalString isNotNil and: [ ProxyURLExternalString isNull not ]) ifTrue: [

"If it is the same that we want, let's just continue. If it is different, we need to free it so, we can allocate a new one"
ProxyURLExternalString utf8StringFromCString = self formatNetworkSettingsProxyServer
ifTrue: [ ^ self ]
ifFalse: [ ProxyURLExternalString free ] ].

^ self createProxyURLExternalString
]

{ #category : #proxy }
Iceberg class >> formatNetworkSettingsProxyServer [

^ String streamContents: [ :s |
s nextPutAll: 'https://'.
s nextPutAll: NetworkSystemSettings httpProxyServer.
s nextPutAll: ':'.
s nextPutAll: NetworkSystemSettings httpProxyPort printString ]
]

{ #category : #accessing }
Iceberg class >> icebergRepositoriesURLs [
^ {
Expand Down Expand Up @@ -111,6 +158,13 @@ Iceberg class >> packageForCategoryNamed: categoryName [

]

{ #category : #proxy }
Iceberg class >> proxyURLExternalString [

self ensureProxyURLExternalString.
^ ProxyURLExternalString
]

{ #category : #accessing }
Iceberg class >> remoteTypeSelector [
"Should be #scpURL or #httpsURL"
Expand Down
Loading