Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

First commits #1

Merged
merged 30 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4424e02
update gitignore
itsmostafa Jan 18, 2023
b9812b7
update gitignore
itsmostafa Jan 18, 2023
4895aa3
update gitignore
itsmostafa Jan 18, 2023
e77ca41
update readme
itsmostafa Jan 18, 2023
e430ffa
update codeowners
itsmostafa Jan 18, 2023
f6622e1
remove python specific pre-commit hooks in favor of golang ones
itsmostafa Jan 18, 2023
e422fca
remove python specific pre-commit hooks in favor of golang ones
itsmostafa Jan 18, 2023
452f9b2
initialize golang project
itsmostafa Jan 18, 2023
43158ba
update golang project structure
itsmostafa Jan 18, 2023
4dd2f64
add back python pre-commit hooks
itsmostafa Jan 18, 2023
9397e89
minimize tab size
itsmostafa Jan 18, 2023
e95a201
update codeowners
itsmostafa Jan 18, 2023
3add000
fix gitignore formatting
itsmostafa Jan 18, 2023
e3c2e82
update pre-commit-config format
itsmostafa Jan 18, 2023
b732ed3
revert quotation change in pre-commit-config
itsmostafa Jan 18, 2023
446b38f
update Makefile format
itsmostafa Jan 18, 2023
8c33d7c
add missing char format in gitignore
itsmostafa Jan 18, 2023
a6d76db
move golang hooks down above python hooks in pre-commit-config
itsmostafa Jan 18, 2023
2effac3
update README.md
itsmostafa Jan 19, 2023
8072434
add codeql analysis workflow
itsmostafa Jan 19, 2023
f0ce5c7
add gh actions step for go test
itsmostafa Jan 26, 2023
cd17276
update gh action tests
itsmostafa Jan 26, 2023
7751db5
update test steps in build.yml
itsmostafa Jan 26, 2023
38c2dcb
add missing caching step
itsmostafa Jan 26, 2023
a892aaf
add gorilla/mux dependancy
itsmostafa Jan 26, 2023
6ab301d
remove unnecessary step
itsmostafa Jan 26, 2023
619b4f5
switch build and test for caching alternatives
itsmostafa Jan 26, 2023
5460a0e
replacing gorilla/mux in favor of chi router
itsmostafa Jan 26, 2023
5b1493b
fix gh actions test step
itsmostafa Jan 26, 2023
98209ca
update build.yml test step format
itsmostafa Jan 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# These owners will be the default owners for everything in the
# repo. Unless a later match takes precedence, these owners will be
# requested for review when someone opens a pull request.
* @dav3r @felddy @jsf9k @mcdonnnj
* @itsmostafa @izzy64

# These folks own any files in the .github directory at the root of
# the repository and any of its subdirectories.
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,43 @@ jobs:
- name: Setup tmate debug session
uses: mxschmitt/action-tmate@v3
if: env.RUN_TMATE
test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- "1.18"
- "1.19"
steps:
- uses: actions/checkout@v3
# We need the Go version and Go cache location for the actions/cache step,
mcdonnnj marked this conversation as resolved.
Show resolved Hide resolved
# so the Go installation must happen before that.
- id: setup-go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- name: Lookup Go cache directory
id: go-cache
run: |
echo "dir=$(go env GOCACHE)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
env:
BASE_CACHE_KEY: "${{ github.job }}-${{ runner.os }}-\
go${{ steps.setup-go.outputs.go-version }}-"
with:
path: |
${{ steps.go-cache.outputs.dir }}
key: "${{ env.BASE_CACHE_KEY }}\
${{ hashFiles('go.mod') }}-\
${{ hashFiles('go.sum') }}"
restore-keys: |
${{ env.BASE_CACHE_KEY }}
- name: Install dependencies
mcdonnnj marked this conversation as resolved.
Show resolved Hide resolved
run: go mod download
- name: Build application
run: go build -v ./...
- name: Test application
run: go test -v ./...
- name: Setup tmate debug session
uses: mxschmitt/action-tmate@v3
if: env.RUN_TMATE
67 changes: 67 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
name: "CodeQL"

on:
push:
# Dependabot triggered push events have read-only access, but uploading code
# scanning requires write access.
branches-ignore:
- dependabot/**
pull_request:
# The branches below must be a subset of the branches above
branches:
- develop
schedule:
- cron: "0 12 * * 5"

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
# required for all workflows
security-events: write
strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are go, javascript, csharp, python, cpp, and java
language:
- go
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

# Autobuild attempts to build any compiled languages (C/C++, C#, or
# Java). If this step fails, then you should remove it and run the build
# manually (see below).
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following
# three lines and modify them (or add more) to build your code if your
# project uses a compiled language

# - run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@
# Files already tracked by Git are not affected.
# See: https://git-scm.com/docs/gitignore

## Binaries ##
*.dll
*.dylib
*.exe
*.exe~
*.so
# Test binary, built with `go test -c`
*.test

## Python ##
__pycache__
.mypy_cache
.python-version
.venv

## Environment variables ##
.env
10 changes: 0 additions & 10 deletions .isort.cfg

This file was deleted.

8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ repos:
hooks:
- id: shell-lint

# Golang hooks
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.0
hooks:
- id: go-fmt
- id: go-unit-tests
- id: no-go-testing

# Python hooks
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
Expand Down
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.PHONY: help run test tidy
include .env

# make all - Default Target. Does nothing.
all:
@echo "Helper commands."
@echo "For more information try 'make help'."

# target: help - Display callable targets.
help:
@egrep "^# target:" [Mm]akefile

# target: run - run the application
run:
go run *.go

# target: test - run application tests
test:
go test -v ./...

# target: tidy - add missing necessary modules and remove unused modules
tidy:
go mod tidy
36 changes: 22 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
# con-pca-tasks #
# Con-PCA Tasks #

[![GitHub Build Status](https://github.com/cisagov/con-pca-tasks/workflows/build/badge.svg)](https://github.com/cisagov/con-pca-tasks/actions)
[![CodeQL](https://github.com/cisagov/con-pca-tasks/workflows/CodeQL/badge.svg)](https://github.com/cisagov/con-pca-tasks/actions/workflows/codeql-analysis.yml)

mcdonnnj marked this conversation as resolved.
Show resolved Hide resolved
This is a generic skeleton project that can be used to quickly get a
new [cisagov](https://github.com/cisagov) GitHub project started.
This skeleton project contains [licensing information](LICENSE), as
well as [pre-commit hooks](https://pre-commit.com) and
[GitHub Actions](https://github.com/features/actions) configurations
appropriate for the major languages that we use.
## Description ##

In many cases you will instead want to use one of the more specific
skeleton projects derived from this one.
This project contains the tasks portion for Continuous Phishing Campaign
Assessment (Con-PCA). This application is reponsible for executing scheduled
tasks for Con-PCA at scale.

## New Repositories from a Skeleton ##
## Related Con-PCA Repositories ##

Please see our [Project Setup guide](https://github.com/cisagov/development-guide/tree/develop/project_setup)
for step-by-step instructions on how to start a new repository from
a skeleton. This will save you time and effort when configuring a
new repository!
- [con-pca-api](https://github.com/cisagov/con-pca-api)
- [con-pca-cicd](https://github.com/cisagov/con-pca-cicd)
- [con-pca-web](https://github.com/cisagov/con-pca-web)

### Running the application ###

```console
make run
```

### Testing the application ###

```console
make test
```

## Contributing ##

Expand Down
11 changes: 11 additions & 0 deletions controllers/controllers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package controllers

import (
"fmt"
"net/http"
)

// HealthCheckHandler indicates that the server is up and running.
func HealthCheckHandler(w http.ResponseWriter, r *http.Request) {
dav3r marked this conversation as resolved.
Show resolved Hide resolved
fmt.Fprintf(w, "Up and running!")
}
23 changes: 23 additions & 0 deletions controllers/controllers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package controllers

import (
"io"
"net/http"
"net/http/httptest"
"testing"
)

func TestHealthCheckHandler(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/", nil)
w := httptest.NewRecorder()
HealthCheckHandler(w, req)
res := w.Result()
defer res.Body.Close()
data, err := io.ReadAll(res.Body)
if err != nil {
t.Errorf("expected error to be nil got %v", err)
}
if string(data) != "Up and running!" {
t.Errorf("expected 'Up and running!', but got %v", string(data))
}
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/cisagov/con-pca-tasks

go 1.19

require github.com/go-chi/chi v1.5.4
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/go-chi/chi v1.5.4 h1:QHdzF2szwjqVV4wmByUnTcsbIg7UGaQ0tPF2t5GcAIs=
github.com/go-chi/chi v1.5.4/go.mod h1:uaf8YgoFazUOkPBG7fxPftUylNumIev9awIWOENIuEg=
18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"log"
"net/http"

"github.com/cisagov/con-pca-tasks/controllers"
"github.com/go-chi/chi"
)

func main() {
mux := chi.NewRouter()
mux.Get("/", controllers.HealthCheckHandler)

port := ":8080"
log.Printf("listening on port %s", port)
log.Println(http.ListenAndServe(port, mux))
}