Skip to content

Commit 84d47ed

Browse files
committed
Bug fixes for cf
1 parent 5fe6ba1 commit 84d47ed

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

electron/index.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function createWindow() {
8181
jetstream = spawn(prog, [], {
8282
env: getEnvironment(url),
8383
cwd: __dirname,
84-
//stdio: 'inherit'
84+
stdio: 'inherit'
8585
});
8686

8787
waitForBackend(`https://${url}`, () => {
@@ -144,10 +144,15 @@ function doCreateWindow(url) {
144144
// Open the DevTools.
145145
//mainWindow.webContents.openDevTools({mode:'undocked'});
146146

147-
// Watch for the helm repository file to change
148-
const watcher = chokidar.watch(getHelmRepoFolder());
149-
watcher.on('all', () => {
150-
mainWindow.webContents.send('endpointsChanged', 'HELM');
147+
// Watch for changed in ant of the local configuration files
148+
// We will reload endpoints when these change
149+
const watcher = chokidar.watch([
150+
getCFConfigFile(),
151+
getKubeConfigFile(),
152+
getHelmRepoFolder()
153+
]);
154+
watcher.on('all', (action, filePath) => {
155+
mainWindow.webContents.send('endpointsChanged', action, filePath);
151156
});
152157
}
153158

@@ -233,3 +238,11 @@ function getHelmRepoFolder() {
233238
}
234239
return path.join(homeDir, '.config', 'helm');
235240
}
241+
242+
function getCFConfigFile() {
243+
return path.join(homeDir, '.cf', 'config.json');
244+
}
245+
246+
function getKubeConfigFile() {
247+
return process.env.KUBECONFIG || path.join(homeDir, '.kube', 'config');
248+
}

src/jetstream/plugins/desktop/cloudfoundry.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ func ListCloudFoundry() ([]*interfaces.CNSIRecord, error) {
3232
return nil, err
3333
}
3434

35+
// Ignore if the api endpoint is empty
36+
if len(cfg.APIEndpoint) == 0 {
37+
return nil, nil
38+
}
39+
3540
eps := make([]*interfaces.CNSIRecord, 1)
3641
eps[0] = &interfaces.CNSIRecord{
3742
GUID: getEndpointGUID(cfg.APIEndpoint),
@@ -57,6 +62,11 @@ func ListConnectedCloudFoundry() ([]*interfaces.ConnectedEndpoint, error) {
5762
return nil, err
5863
}
5964

65+
// Ignore if the api endpoint is empty
66+
if len(cfg.APIEndpoint) == 0 {
67+
return nil, nil
68+
}
69+
6070
//TODO: Token expiry
6171
eps := make([]*interfaces.ConnectedEndpoint, 1)
6272
eps[0] = &interfaces.ConnectedEndpoint{
@@ -95,9 +105,11 @@ func readCFFile() (*CFConfigFile, *url.URL, error) {
95105
return nil, url, fmt.Errorf("Can not parse Cloud Foundry config file: %s", err)
96106
}
97107

98-
url, err = url.Parse(config.APIEndpoint)
99-
if err != nil {
100-
return nil, url, err
108+
if len(config.APIEndpoint) > 0 {
109+
url, err = url.Parse(config.APIEndpoint)
110+
if err != nil {
111+
return nil, url, err
112+
}
101113
}
102114
return config, url, nil
103115
}

src/jetstream/plugins/desktop/endpoints.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func (d *DesktopEndpointStore) List(encryptionKey []byte) ([]*interfaces.CNSIRec
2424
func (d *DesktopEndpointStore) ListByUser(userGUID string) ([]*interfaces.ConnectedEndpoint, error) {
2525
local, err := ListConnectedCloudFoundry()
2626
db, err := d.store.ListByUser(userGUID)
27-
2827
merged := mergeConnectedEndpoints(db, local)
2928
return merged, err
3029
}
@@ -71,6 +70,15 @@ func (d *DesktopEndpointStore) SaveOrUpdate(endpoint interfaces.CNSIRecord, encr
7170

7271
// Merge endpoints, over-riding any in first with those in second
7372
func mergeEndpoints(first, second []*interfaces.CNSIRecord) []*interfaces.CNSIRecord {
73+
74+
if first == nil {
75+
return second
76+
}
77+
78+
if second == nil {
79+
return first
80+
}
81+
7482
urls := make(map[string]bool, 0)
7583
for _, endpoint := range second {
7684
urls[endpoint.APIEndpoint.String()] = true
@@ -92,6 +100,15 @@ func mergeEndpoints(first, second []*interfaces.CNSIRecord) []*interfaces.CNSIRe
92100

93101
// Merge endpoints, over-riding any in first with those in second
94102
func mergeConnectedEndpoints(first, second []*interfaces.ConnectedEndpoint) []*interfaces.ConnectedEndpoint {
103+
104+
if first == nil {
105+
return second
106+
}
107+
108+
if second == nil {
109+
return first
110+
}
111+
95112
urls := make(map[string]bool, 0)
96113
for _, endpoint := range second {
97114
urls[endpoint.APIEndpoint.String()] = true

0 commit comments

Comments
 (0)