This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
ignored-paths.go
63 lines (51 loc) · 1.77 KB
/
ignored-paths.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*******************************************************************************
* Copyright (c) 2019 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package apiroutes
import (
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"github.com/eclipse/codewind-installer/pkg/connections"
"github.com/eclipse/codewind-installer/pkg/sechttp"
"github.com/eclipse/codewind-installer/pkg/utils"
)
// IgnoredPaths is the list of paths to ignore, when syncing a project
type IgnoredPaths []string
// GetIgnoredPaths calls pfe to get the default ignoredPaths for that projectType
func GetIgnoredPaths(httpClient utils.HTTPClient, connection *connections.Connection, projectType string, conURL string) (IgnoredPaths, error) {
req, err := http.NewRequest("GET", conURL+"/api/v1/ignoredPaths", nil)
if err != nil {
return nil, err
}
q := req.URL.Query()
q.Add("projectType", projectType)
req.URL.RawQuery = q.Encode()
resp, httpSecError := sechttp.DispatchHTTPRequest(httpClient, req, connection)
if httpSecError != nil {
return nil, httpSecError
}
if resp.StatusCode != 200 {
err := errors.New("IgnoredPaths list not able to be retrieved")
return nil, err
}
defer resp.Body.Close()
byteArray, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var ignoredPaths IgnoredPaths
err = json.Unmarshal(byteArray, &ignoredPaths)
if err != nil {
return nil, err
}
return ignoredPaths, nil
}