diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000..7668e4d8f5 Binary files /dev/null and b/.DS_Store differ diff --git a/.env b/.env new file mode 100644 index 0000000000..14f6494f9b --- /dev/null +++ b/.env @@ -0,0 +1 @@ +PORT="8080" diff --git a/.github/.DS_Store b/.github/.DS_Store new file mode 100644 index 0000000000..647859f17e Binary files /dev/null and b/.github/.DS_Store differ diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000000..92550e8e68 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,48 @@ +name: Deploy to Cloud Run + +on: + push: + branches: [main] + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Build production app + run: ./scripts/buildprod.sh + + - name: Authenticate to Google Cloud + uses: google-github-actions/auth@v2 + with: + credentials_json: ${{ secrets.GCP_CREDENTIALS }} + + - name: Set up gcloud + uses: google-github-actions/setup-gcloud@v2 + with: + project_id: industrial-joy-473515-v9 + + - name: Configure Docker for Artifact Registry + run: | + gcloud auth configure-docker us-central1-docker.pkg.dev + + - name: Build and Push Docker image + run: | + gcloud builds submit --tag us-central1-docker.pkg.dev/industrial-joy-473515-v9/notely-ar-repo/notely:latest . + + - name: Deploy to Cloud Run + run: | + gcloud run deploy notely-service \ + --image us-central1-docker.pkg.dev/industrial-joy-473515-v9/notely-ar-repo/notely:latest \ + --region us-central1 \ + --platform managed \ + --allow-unauthenticated diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000000..274ac15713 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: ci + +on: + pull_request: + branches: [main] + +jobs: + tests: + name: Tests + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Run tests + run: go test -cover ./... + + - name: Install gosec + run: go install github.com/securego/gosec/v2/cmd/gosec@latest + + - name: Run gosec + run: gosec ./... + + style: + name: Style + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: "1.25.1" + + - name: Check formatting + run: test -z $(go fmt ./...) + + - name: Install staticcheck + run: go install honnef.co/go/tools/cmd/staticcheck@latest + + - name: Run staticcheck + run: staticcheck ./... \ No newline at end of file diff --git a/README.md b/README.md index c2bec0368b..22cc2859aa 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,5 @@ go build -o notely && ./notely *This starts the server in non-database mode.* It will serve a simple webpage at `http://localhost:8080`. You do *not* need to set up a database or any interactivity on the webpage yet. Instructions for that will come later in the course! + +Fortune's version of Boot.dev's Notely app. diff --git a/bootdev b/bootdev new file mode 100755 index 0000000000..f54f778b14 Binary files /dev/null and b/bootdev differ diff --git a/ci b/ci new file mode 100644 index 0000000000..e69de29bb2 diff --git a/go/.DS_Store b/go/.DS_Store new file mode 100644 index 0000000000..5f17cdb520 Binary files /dev/null and b/go/.DS_Store differ diff --git a/go/bin/bootdev b/go/bin/bootdev new file mode 100755 index 0000000000..f54f778b14 Binary files /dev/null and b/go/bin/bootdev differ diff --git a/go/bin/gopls b/go/bin/gopls new file mode 100755 index 0000000000..25a27c58b8 Binary files /dev/null and b/go/bin/gopls differ diff --git a/go/bin/staticcheck b/go/bin/staticcheck new file mode 100755 index 0000000000..6e758910c1 Binary files /dev/null and b/go/bin/staticcheck differ diff --git a/internal/.DS_Store b/internal/.DS_Store new file mode 100644 index 0000000000..8f63c1189d Binary files /dev/null and b/internal/.DS_Store differ diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go new file mode 100644 index 0000000000..76f126fee3 --- /dev/null +++ b/internal/auth/auth_test.go @@ -0,0 +1,47 @@ +package auth + +import ( + "net/http" + "testing" +) + +// TestGetAPIKey tests the GetAPIKey function. +func TestGetAPIKey(t *testing.T) { + // Sub-test for a valid, well-formed Authorization header. + t.Run("Valid API Key", func(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "ApiKey my-secret-key") + + key, err := GetAPIKey(headers) + if err != nil { + t.Fatalf("expected no error, got %v", err) + } + if key != "my-secret-key" { + t.Errorf("expected key to be 'my-secret-key', got '%s'", key) + } + }) + + // Sub-test for a missing Authorization header. + t.Run("No Auth Header", func(t *testing.T) { + headers := http.Header{} + + _, err := GetAPIKey(headers) + if err == nil { + t.Fatal("expected an error, but got none") + } + if err != ErrNoAuthHeaderIncluded { + t.Errorf("expected error '%v', got '%v'", ErrNoAuthHeaderIncluded, err) + } + }) + + // Sub-test for a malformed Authorization header. + t.Run("Malformed Auth Header", func(t *testing.T) { + headers := http.Header{} + headers.Set("Authorization", "Bearer some-other-token") + + _, err := GetAPIKey(headers) + if err == nil { + t.Fatal("expected an error, but got none") + } + }) +} diff --git a/sql/.DS_Store b/sql/.DS_Store new file mode 100644 index 0000000000..4832d0154d Binary files /dev/null and b/sql/.DS_Store differ diff --git a/vendor/.DS_Store b/vendor/.DS_Store new file mode 100644 index 0000000000..87d982c16e Binary files /dev/null and b/vendor/.DS_Store differ