-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update building process, refactor code, various cleanup
- Loading branch information
1 parent
d23fb49
commit 3cb755d
Showing
8 changed files
with
222 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Remove old instance | ||
echo -e "Removing old builds (if present)\n" | ||
docker rm builder | ||
docker rmi openconnect-sso-builder | ||
rm -rf out | ||
|
||
# Tag dockerfile | ||
echo -e "Build and tag container\n" | ||
docker build -t openconnect-sso-builder . | ||
|
||
OVERRIDE_GO_VARIABLES="" | ||
|
||
if [ -n "${GOOS}" ]; then | ||
OVERRIDE_GO_VARIABLES+=" -e \"GOOS=${GOOS}\"" | ||
fi | ||
|
||
if [ -n "${GOARCH}" ]; then | ||
OVERRIDE_GO_VARIABLES+=" -e \"GOARCH=${GOARCH}\"" | ||
fi | ||
|
||
# Run builder to create executable | ||
docker run --name builder openconnect-sso-builder | ||
echo -e "Run container and assign it the name \"builder\"\n" | ||
sh -c "docker run ${OVERRIDE_GO_VARIABLES} --name builder openconnect-sso-builder" | ||
|
||
# Copy output directory to current directory | ||
docker cp builder:/opt/out ./out | ||
echo -e "Copy executable from container to ./out directory\n" | ||
docker cp builder:/opt/out ./out | ||
|
||
#echo "Copying ./out/go-openconnect-sso to /usr/bin/go-openconnect-sso" | ||
#sudo cp ./out/go-openconnect-sso /usr/bin/go-openconnect-sso |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package internal | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
// CustomHeaderTransport is used to add our custom http headers to http requests | ||
type CustomHeaderTransport struct { | ||
Transport http.RoundTripper | ||
Headers *map[string]string | ||
} | ||
|
||
// RoundTrip adds our custom headers and then uses the default http transport to RoundTrip | ||
func (cht *CustomHeaderTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
|
||
if cht.Headers != nil { | ||
for key, value := range *cht.Headers { | ||
req.Header.Add(key, value) | ||
} | ||
} | ||
return cht.Transport.RoundTrip(req) | ||
} | ||
|
||
// NewHttpClient creates a new HTTP client and adds serverName to the TLS configuration. | ||
// this part is important to have accurate and valid TLS sessions (solved an old issue with DTLS). | ||
func NewHttpClient(serverName string) *http.Client { | ||
defaultTransport := http.DefaultTransport.(*http.Transport) | ||
systemCerts, err := x509.SystemCertPool() | ||
if err != nil { | ||
log.Fatal("Could not load system cert pool.") | ||
} | ||
|
||
defaultTransport.TLSClientConfig = &tls.Config{ | ||
ServerName: serverName, | ||
InsecureSkipVerify: false, | ||
RootCAs: systemCerts, | ||
} | ||
|
||
return &http.Client{ | ||
CheckRedirect: func(req *http.Request, via []*http.Request) error { | ||
log.Println("Redirected from", via[len(via)-1].URL.String(), "to", req.URL.String()) | ||
return nil | ||
}, | ||
Transport: &CustomHeaderTransport{ | ||
Transport: defaultTransport, | ||
Headers: &map[string]string{ | ||
"User-Agent": "AnyConnect Linux_64 4.7.00136", | ||
"Accept": "*/*", | ||
"Accept-Encoding": "identity", | ||
"X-Transcend-Version": "1", | ||
"X-Aggregate-Auth": "1", | ||
"X-Support-HTTP-Auth": "true", | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
"Connection": "keep-alive", | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.