Skip to content

Commit

Permalink
Merge pull request #2 from Ouest-France/ci
Browse files Browse the repository at this point in the history
Add CI
  • Loading branch information
pablo-ruth authored Mar 11, 2021
2 parents 242319a + f8dc229 commit a057049
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 7 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: PR
on: [pull_request]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15

- name: Run Golang CI Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.33

- name: Build
run: CGO_ENABLED=0 go build -ldflags="-extldflags '-static' -w -s" -o k8s-dashboard-auth-proxy

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ouestfrance/k8s-dashboard-auth-proxy:${{ github.workflow }}-${{ github.run_number }}
48 changes: 48 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Tag
on:
push:
tags:
- "v*.*.*"

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}

- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15

- name: Run Golang CI Lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.33

- name: Build
run: CGO_ENABLED=0 go build -ldflags="-extldflags '-static' -w -s" -o k8s-dashboard-auth-proxy

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ouestfrance/k8s-dashboard-auth-proxy:${{ steps.get_version.outputs.VERSION }}
22 changes: 15 additions & 7 deletions proxy/loginHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ type TanzuAuthResult struct {

// loginGetHandler displays the login form
func loginGetHandler(w http.ResponseWriter, r *http.Request) {
w.Write(loginPage)
_, err := w.Write(loginPage)
if err != nil {
fmt.Printf("failed to write login page: %s", err)
}
}

// loginPostHandler handles the Tanzu authentication logic
Expand All @@ -34,7 +37,7 @@ func loginPostHandler(loginURL, guestClusterName string) func(w http.ResponseWri
// Check that username and password are defined
if username == "" || password == "" {
fmt.Println("username or password empty")
w.Write(loginPage)
http.Redirect(w, r, "/login", 302)
return
}

Expand All @@ -48,7 +51,7 @@ func loginPostHandler(loginURL, guestClusterName string) func(w http.ResponseWri
req, err := http.NewRequest("POST", loginURL, strings.NewReader(payload))
if err != nil {
fmt.Printf("failed to create login request: %s\n", err)
w.Write(loginPage)
http.Redirect(w, r, "/login", 302)
return
}

Expand All @@ -62,7 +65,7 @@ func loginPostHandler(loginURL, guestClusterName string) func(w http.ResponseWri
resp, err := client.Do(req)
if err != nil {
fmt.Printf("login request failed: %s\n", err)
w.Write(loginPage)
http.Redirect(w, r, "/login", 302)
return
}
defer resp.Body.Close()
Expand All @@ -71,18 +74,23 @@ func loginPostHandler(loginURL, guestClusterName string) func(w http.ResponseWri
body, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Printf("failed to read login response body: %s\n", err)
w.Write(loginPage)
http.Redirect(w, r, "/login", 302)
return
}
var TanzuAuthResult TanzuAuthResult
err = json.Unmarshal(body, &TanzuAuthResult)
if err != nil {
fmt.Printf("failed to unmarshal json login response: %s\n", err)
w.Write(loginPage)
http.Redirect(w, r, "/login", 302)
return
}

setTokenCookie(w, TanzuAuthResult.SessionID)
err = setTokenCookie(w, TanzuAuthResult.SessionID)
if err != nil {
fmt.Printf("failed to set token cookie: %s\n", err)
http.Redirect(w, r, "/login", 302)
return
}

http.Redirect(w, r, "/", 302)
}
Expand Down

0 comments on commit a057049

Please sign in to comment.