From 5f5d1c69bc142c43c48d4e2e66900078aaba2f5c Mon Sep 17 00:00:00 2001 From: DJ Schleen Date: Fri, 1 Jul 2022 21:00:20 -0600 Subject: [PATCH 1/3] Functional blockchain code and tests --- .github/dependabot.yml | 8 + .gitignore | 18 ++ .hookz.yaml | 51 +++++ CODE_OF_CONDUCT.md | 76 +++++++ CONTRIBUTING.md | 24 +++ LICENSE | 373 ++++++++++++++++++++++++++++++++++ Makefile | 27 +++ README.md | 19 +- SECURITY.md | 5 + blockchain/blockchain.go | 90 ++++++++ blockchain/blockchain_test.go | 60 ++++++ blockchain/proof.go | 85 ++++++++ go.mod | 11 + go.sum | 15 ++ img/kusari128x128.png | Bin 0 -> 5740 bytes img/kusari512x512.png | Bin 0 -> 26390 bytes 16 files changed, 860 insertions(+), 2 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .gitignore create mode 100644 .hookz.yaml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 SECURITY.md create mode 100644 blockchain/blockchain.go create mode 100644 blockchain/blockchain_test.go create mode 100644 blockchain/proof.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 img/kusari128x128.png create mode 100644 img/kusari512x512.png diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b11780b --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: +- package-ecosystem: gomod + directory: / + schedule: + interval: daily + time: "05:00" + timezone: UTC diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9777af1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +coverage.out +.DS_Store \ No newline at end of file diff --git a/.hookz.yaml b/.hookz.yaml new file mode 100644 index 0000000..84aeb01 --- /dev/null +++ b/.hookz.yaml @@ -0,0 +1,51 @@ + version: 2.4.0 + sources: + - source: github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@latest + - source: github.com/devops-kung-fu/hookz@latest + - source: github.com/devops-kung-fu/lucha@latest + - source: github.com/devops-kung-fu/hinge@latest + - source: github.com/kisielk/errcheck@latest + - source: golang.org/x/lint/golint@latest + - source: github.com/fzipp/gocyclo/cmd/gocyclo@latest + hooks: + - type: pre-commit + actions: + - name: "git: Pull (Ensure there are no upstream changes that are not local)" + exec: git + args: ["pull"] + - name: "go: Tidy mod file" + exec: go + args: ["mod", "tidy"] + - name: "go: Update all dependencies to latest" + exec: go + args: ["get", "-u", "./..."] + - name: "gofmt: Run gofmt to format the code" + exec: gofmt + args: ["-s", "-w", "**/*.go"] + - name: "golint: Lint all go files" + exec: golint + args: ["./..."] #to error out, add the arg "-set_exit_status" + - name: "errcheck: Ensure that errors are checked" + exec: errcheck + args: ["-ignoretests", "./..."] + - name: "gocyclo: Check cyclomatic complexities" + exec: gocyclo + args: ["-over", "5", "."] + - name: Hinge + exec: hinge + args: ["."] + - name: "go: Build (Ensure pulled modules do not break the build)" + exec: go + args: ["build", "-v", "./..."] + - name: "go: Run all tests" + exec: go + args: ["test", "-v", "-coverprofile=coverage.out", "./..."] + - name: "go: Test coverage" + exec: go + args: ["tool", "cover", "-func=coverage.out"] + - name: "cyclone-dx: Generate a Software Bill of Materials (SBoM)" + exec: cyclonedx-gomod + args: ["mod", "-json", "-output", "kusari-sbom.json"] + - name: "git: Add all changed files during the pre-commit stage" + exec: git + args: ["add", "."] \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..fac374d --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..d276d19 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,24 @@ +# Contributing to SHS + +## We Develop with Github + +We use github to host code, to track issues and feature requests, as well as accept pull requests. + +## Use GPG to Sign Your Commits + +Only pull requests that have been signed will be accepted. For more information on setting up a GPG key for your Github account see the instructions [here](https://help.github.com/en/articles/managing-commit-signature-verification). + +## Contributing Code + +All Code Changes Happen Through Pull Requests. Pull requests are the best way to propose changes to the codebase. We actively welcome your pull requests and review regularly. We practice a single trunk development method. + +- Fork the repo and create your branch from main. +- All code requires test coverage. 100% coverage is the target Add new or modify existing tests. +- If you've changed APIs, update the documentation. +- Ensure the tests pass. +- Make sure your code lints (go) +- Create a pull request. + +## Licensing Notes + +Any contributions you make will be under the MIT Software License. When you submit code changes, your submissions are understood to be under the same MIT License that covers the project. Feel free to contact the maintainers if that's a concern. \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a612ad9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c564b54 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +# HELP +# This will output the help for each task +# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +.PHONY: help + +help: ## This help + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +.DEFAULT_GOAL := help + +title: + @echo "kusari Makefile" + @echo "---------------" + +build: ## Builds the application + go get -u ./... + go mod tidy + go build ./... + +test: ## Runs tests and coverage + go test -v -coverprofile=coverage.out ./... && go tool cover -func=coverage.out + +check: build ## Tests the pre-commit hooks if they exist + hookz reset --verbose --debug --verbose-output + . .git/hooks/pre-commit + +all: title build test ## Makes all targets \ No newline at end of file diff --git a/README.md b/README.md index 7249bf6..219739c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ -# kusari -A simple blockchain module for Go. +![](img/kusari128x128.png) + +# kusari (鎖) + +![GitHub release (latest by date)](https://img.shields.io/github/v/release/devops-kung-fu/kusari) [![Go Report Card](https://goreportcard.com/badge/github.com/devops-kung-fu/kusari)](https://goreportcard.com/report/github.com/devops-kung-fu/kusari) [![codecov](https://codecov.io/gh/devops-kung-fu/kusari/branch/main/graph/badge.svg?token=P9WBOBQTOB)](https://codecov.io/gh/devops-kung-fu/kusari) [![SBOM](https://img.shields.io/badge/CyloneDX-SBoM-informational)](kusari-sbom.json) + +A simple blockchain module for Golang. + +## Software Bill of Materials + +```kusari``` uses the CycloneDX to generate a Software Bill of Materials in CycloneDX format (v1.4) every time a developer commits code to this repository. More information for CycloneDX is available [here](https://cyclonedx.org) + +The current SBoM for ```kusari``` is available [here](kusari-sbom.json). + +## Credits + +A big thank-you to our friends at [Freepik](https://www.freepik.com) for the ```kusari``` logo. \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..6f80cfa --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,5 @@ +# Security Policy + +## Reporting a Vulnerability + +We scan for vulnerabilities in both our code and our third party dependencies on a continuous basis. If you discover a vulnerability please create an issue in this repository and one of the administrators will triage. diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go new file mode 100644 index 0000000..9e13121 --- /dev/null +++ b/blockchain/blockchain.go @@ -0,0 +1,90 @@ +package blockchain + +import ( + "bytes" + "encoding/gob" + "errors" + "log" +) + +// Block defines a Block on the BlockChain. +type Block struct { + Hash []byte + Data []byte + PrevHash []byte + Nonce int +} + +// BlockChain represents a BlockChain +type BlockChain []Block + +// IsEmpty checks to see if the blockchain is empty +func (bc *BlockChain) IsEmpty() bool { + return len(*bc) == 0 +} + +// Push pushes new data onto the blockchain +func (bc *BlockChain) Push(data []byte) (err error) { + lastBlock, err := (*bc).Last() + if err != nil { + return + } + block, err := createBlock(data, lastBlock) + *bc = append(*bc, block) + return +} + +// Pop removes and returns the last element of blockchain +func (bc *BlockChain) Last() (block Block, err error) { + if bc.IsEmpty() { + return block, errors.New("blockchain is empty") + } else { + index := len(*bc) - 1 + block = (*bc)[index] + return block, nil + } +} + +// Serialize will serialize a BlockChain into an slice of bytes +func (bc *BlockChain) Serialize() (data []byte, err error) { + var res bytes.Buffer + encoder := gob.NewEncoder(&res) + err = encoder.Encode(bc) + return res.Bytes(), err +} + +// Deserialize deserializes a slice of bytes into a BlockChain +// data the array of bytes to deserialize +func Deserialize(data []byte) (blockchain BlockChain, err error) { + decoder := gob.NewDecoder(bytes.NewReader(data)) + err = decoder.Decode(&blockchain) + return +} + +// NewBlockChain creates an empty BlockChain with a Genesis block +func NewBlockChain() (blockchain BlockChain) { + block, _ := genesis() + blockchain = append(blockchain, block) + return +} + +// CreateBlock Creates a new Block +// data is the string to be put in the block +// prevHash is the Has of the previous Block in the BlockChain +func createBlock(data []byte, lastBlock Block) (block Block, err error) { + log.Println("Creating New Block...") + block = Block{[]byte{}, data, lastBlock.Hash, 0} + proof := NewProof(block) + nonce, hash := proof.Run() + + block.Hash = hash[:] + block.Nonce = nonce + + return +} + +// Genesis creates a genesis Block - the first Block in the BlockChain +func genesis() (block Block, err error) { + var nullBlock Block + return createBlock([]byte("Genesis"), nullBlock) +} diff --git a/blockchain/blockchain_test.go b/blockchain/blockchain_test.go new file mode 100644 index 0000000..7d939f4 --- /dev/null +++ b/blockchain/blockchain_test.go @@ -0,0 +1,60 @@ +package blockchain + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestNewBlockChain(t *testing.T) { + blockchain := NewBlockChain() + assert.False(t, blockchain.IsEmpty()) + + block, err := blockchain.Last() + assert.Equal(t, "Genesis", string(block.Data)) + assert.NoError(t, err) + assert.Empty(t, block.PrevHash) +} + +func TestBlockChain_Serialize(t *testing.T) { + blockchain := NewBlockChain() + output, err := blockchain.Serialize() + assert.NoError(t, err) + assert.Len(t, output, 138) +} + +func TestBlockChain_Pop(t *testing.T) { + var blockchain BlockChain + _, err := blockchain.Last() + assert.Error(t, err) + + blockchain = NewBlockChain() + block, err := blockchain.Last() + assert.NoError(t, err) + assert.Equal(t, []byte("Genesis"), block.Data) +} + +func TestDeserialize(t *testing.T) { + blockchain := NewBlockChain() + output, _ := blockchain.Serialize() + + blockchain, err := Deserialize(output) + assert.NoError(t, err) + assert.Len(t, output, 138) +} + +func TestBlockChain_Push(t *testing.T) { + var blockchain BlockChain + err := blockchain.Push([]byte("TEST")) + assert.Error(t, err) + + blockchain = NewBlockChain() + err = blockchain.Push([]byte("TEST")) + assert.NoError(t, err) + assert.Len(t, blockchain, 2) + + genesisBlock := blockchain[0] + lastBlock, _ := blockchain.Last() + + assert.Equal(t, lastBlock.PrevHash, genesisBlock.Hash, "Previous hash of the last block in this test scenario should be the hash of the genesis block") +} diff --git a/blockchain/proof.go b/blockchain/proof.go new file mode 100644 index 0000000..57a1ad9 --- /dev/null +++ b/blockchain/proof.go @@ -0,0 +1,85 @@ +package blockchain + +import ( + "bytes" + "crypto/sha256" + "encoding/binary" + "log" + "math" + "math/big" +) + +// Difficulty describes the difficulty of the algorithm +const Difficulty = 5 + +type Proof struct { + Block Block + Target *big.Int +} + +func (proof *Proof) init(nonce int) []byte { + nonceHex, _ := ToHex(int64(nonce)) + difficultyHex, _ := ToHex(int64(Difficulty)) + data := bytes.Join( + [][]byte{ + proof.Block.PrevHash, + proof.Block.Data, + nonceHex, + difficultyHex, + }, + []byte{}, + ) + + return data +} + +// NewProof creates a Proof struct from a Block +// b is the Block object to use +func NewProof(b Block) (proof Proof) { + target := big.NewInt(1) + + target.Lsh(target, uint(256-Difficulty)) + proof = Proof{b, target} + + return +} + +func (proof *Proof) Run() (int, []byte) { + var intHash big.Int + var hash [32]byte + nonce := 0 + + for nonce < math.MaxInt64 { + data := proof.init(nonce) + hash = sha256.Sum256(data) + + log.Printf("\r%x", hash) + + intHash.SetBytes(hash[:]) + + if intHash.Cmp(proof.Target) == -1 { + break + } else { + nonce++ + } + } + + return nonce, hash[:] +} + +func (proof *Proof) Validate() bool { + var intHash big.Int + + data := proof.init(proof.Block.Nonce) + hash := sha256.Sum256(data) + intHash.SetBytes(hash[:]) + + return intHash.Cmp(proof.Target) == -1 +} + +func ToHex(num int64) (hex []byte, err error) { + buff := new(bytes.Buffer) + err = binary.Write(buff, binary.BigEndian, num) + + return buff.Bytes(), err +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..639124b --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module github.com/devops-kung-fu/kusari + +go 1.18 + +require github.com/stretchr/testify v1.8.0 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5164829 --- /dev/null +++ b/go.sum @@ -0,0 +1,15 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/img/kusari128x128.png b/img/kusari128x128.png new file mode 100644 index 0000000000000000000000000000000000000000..d67b6aea0f4424ce65e4e4fc077f46b772650e0e GIT binary patch literal 5740 zcmV-y7L)0TP)$EVZR?j$Bk)T_ov=@1jqKw1VB1VkuinMI(O zWvX@mI8{(oow@cobqebHJoW5-R_(pkI_LfEwbtJ2ebA1R*;ZnuU>TMPD#Dd^HPTlq7*SIfK=iItF;;MeV6=qMd#m|cq53b= zezI--v`rFXn2R?Bv%+|LL+3JTdVu@ zc#R&v0BWaI;2As<{@mJ>U$T)YNdZKQjS_rMFd0$7j9yp)97_pa!4JY0y<7LYHZ~Pxo;sNE&}5Pui0t9L{!6hr{g8s&nYOFXx)|D%_R(Mw+d zHB80V!gcXaG{xQpL~FIfYq%-yyia0o!fVm1+Qpr5tOAJE>Mk)YIzG;Pn?d3?oe}*; z_c$|+O#soy&cG~;iYw1%>M;tlqTe_pt_))lK(tPGyg~JpZ8L>rFy4r(C1~&Bf5(^V0d*8y^Oo!Y|I}!*SerTJqK+4{nmMMPB690z{iksBZd?xoe#SEx`CLJbV^o zI*NrwyLn(4FK@0>X5BhuP7i{KVX|qt)*)vBM4R-%0zucT4c){A@MoQvau(w{)&D)> z;QgK4zl_(n9A9oyQm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;~;3rG6lGA z-TsTPSK#*ypw<*wl-5#9??j2he5N1-G&Y}oW=lPV!P_Z+etA;}1q}XkQbi&2$04b93@CKO`P?uZ(h)p3k!cSU`F~nQmv=gvIf$tYUV#R6uao{y%Zs&xPE&$AN zUH&G-wbTIY0>pakWUEHu!5@nXL?8hj6|Ce@xVL0{M_6T!b2IIK(&t?y{w`65h@vS= z_ZB`48jG(8c+~V=EEk1iJdVCHhsQdw2bYj+|0e!7`)^SP8CV=B`8L}gY0JY^MB`Rb*#OKB3CnABzkpX8vQ|>YQ z!oz2Ma>DWwO9frP^X9hb`|H1bsZOp)o9=FEt`q|FuHn0K(VJh9ZAF9;$tu@(m2R<0 zVMzQPnrvXBTy-|1;w_bYq_(vogoiPCS8m)+o}IP&WNGv$Ol7jZ^F=?@mcN|Fyyc{< z7yoqe!VVbXG(bri*)~G%Ijo>4^6*$F*9*Pn9$~-_B8o;NlkeK5Da46E^5`F5`9sLR zp<)4vMAJZ`)gxQkDb<*;yz^R+8`Mt#O~UxOubU7a`^USqYxwYs7iejY z!mSZUJ`~Buz)xt4^788^(K^$lD7L)YK@654yan*PvRvWTsrNM7%v3{zoO4u;+1=jeJ&wX*E@YrU@cF`Y*j;O2Jjm;fR3ht KMya}O#Qy_llRv=# literal 0 HcmV?d00001 From c5b2a7928ccf1ade90249b2108f0c59430fe8997 Mon Sep 17 00:00:00 2001 From: DJ Schleen Date: Fri, 1 Jul 2022 23:07:12 -0600 Subject: [PATCH 2/3] Adds iterator functionality and updated documentation --- README.md | 43 ++++++++++++++++++++++++++++++++++- blockchain/blockchain.go | 28 +++++++++++++++++++---- blockchain/blockchain_test.go | 35 ++++++++++++++++++++++++---- blockchain/proof.go | 6 ++--- 4 files changed, 99 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 219739c..06d53b2 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,55 @@ ![](img/kusari128x128.png) +***NOTE: There's some working code in here, but don't bet the farm on it just yet...*** + # kusari (鎖) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/devops-kung-fu/kusari) [![Go Report Card](https://goreportcard.com/badge/github.com/devops-kung-fu/kusari)](https://goreportcard.com/report/github.com/devops-kung-fu/kusari) [![codecov](https://codecov.io/gh/devops-kung-fu/kusari/branch/main/graph/badge.svg?token=P9WBOBQTOB)](https://codecov.io/gh/devops-kung-fu/kusari) [![SBOM](https://img.shields.io/badge/CyloneDX-SBoM-informational)](kusari-sbom.json) A simple blockchain module for Golang. +## Overview + +[DKFM](https://github.com/devops-kung-fu) is experimenting with a few ideas around using block chain concepts for creating irrefutable evidence that security controls are being executed during build and deployments of code in CI/CD pipelines. + +This module encapsulates functionality to create and manage blockchains. + +## Using kusari + +Well, buyer beware here. Right now this module is in a really early state. It's also really dang noisy and outputs a ton of logs. Ensure that you have good log management in any consumer of this module. + +If you want to suppress logging (you'll have to do this in your app) you can do this: + +``` go + +log.SetOutput(ioutil.Discard) + +``` + +## Development + +## Overview + +In order to use contribute and participate in the development of ```kusari``` you'll need to have an updated Go environment. Before you start, please view the [Contributing](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) files in this repository. + +## Prerequisites + +This project makes use of [DKFM](https://github.com/devops-kung-fu) tools such as [Hookz](https://github.com/devops-kung-fu/hookz), [Hinge](https://github.com/devops-kung-fu/hinge), and other open source tooling. Install these tools with the following commands: + +``` bash + +go install github.com/devops-kung-fu/hookz@latest +go install github.com/devops-kung-fu/lucha@latest +go install github.com/devops-kung-fu/hinge@latest +go install github.com/kisielk/errcheck@latest +go install golang.org/x/lint/golint@latest +go install github.com/fzipp/gocyclo@latest + +``` + ## Software Bill of Materials -```kusari``` uses the CycloneDX to generate a Software Bill of Materials in CycloneDX format (v1.4) every time a developer commits code to this repository. More information for CycloneDX is available [here](https://cyclonedx.org) +```kusari``` uses the CycloneDX to generate a Software Bill of Materials in CycloneDX format (v1.4) every time a developer commits code to this repository (as long as [Hookz](https://github.com/devops-kung-fu/hookz) is being used and is has been initialized in the working directory). More information for CycloneDX is available [here](https://cyclonedx.org) The current SBoM for ```kusari``` is available [here](kusari-sbom.json). diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 9e13121..07f325e 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -15,6 +15,11 @@ type Block struct { Nonce int } +type BlockChainIterator struct { + current int + blockchain *BlockChain +} + // BlockChain represents a BlockChain type BlockChain []Block @@ -45,17 +50,32 @@ func (bc *BlockChain) Last() (block Block, err error) { } } -// Serialize will serialize a BlockChain into an slice of bytes -func (bc *BlockChain) Serialize() (data []byte, err error) { +// Marshal will marshal a BlockChain into an slice of bytes +func (bc *BlockChain) Marshal() (data []byte, err error) { var res bytes.Buffer encoder := gob.NewEncoder(&res) err = encoder.Encode(bc) return res.Bytes(), err } -// Deserialize deserializes a slice of bytes into a BlockChain +func (bc *BlockChain) Iterator() *BlockChainIterator { + return &BlockChainIterator{len(*bc), bc} +} + +// Next walks through the blockchain history from latest to the genesis block +func (iter *BlockChainIterator) Next() (block Block, err error) { + if iter.current == 0 { + err = errors.New("no entries earlier than the genesis block") + return + } + (*iter).current -= 1 + bc := iter.blockchain + return (*bc)[iter.current], nil +} + +// UnMarshal deserializes a slice of bytes into a BlockChain // data the array of bytes to deserialize -func Deserialize(data []byte) (blockchain BlockChain, err error) { +func UnMarshal(data []byte) (blockchain BlockChain, err error) { decoder := gob.NewDecoder(bytes.NewReader(data)) err = decoder.Decode(&blockchain) return diff --git a/blockchain/blockchain_test.go b/blockchain/blockchain_test.go index 7d939f4..483b83c 100644 --- a/blockchain/blockchain_test.go +++ b/blockchain/blockchain_test.go @@ -16,9 +16,9 @@ func TestNewBlockChain(t *testing.T) { assert.Empty(t, block.PrevHash) } -func TestBlockChain_Serialize(t *testing.T) { +func TestBlockChain_Marshal(t *testing.T) { blockchain := NewBlockChain() - output, err := blockchain.Serialize() + output, err := blockchain.Marshal() assert.NoError(t, err) assert.Len(t, output, 138) } @@ -34,11 +34,11 @@ func TestBlockChain_Pop(t *testing.T) { assert.Equal(t, []byte("Genesis"), block.Data) } -func TestDeserialize(t *testing.T) { +func TestUnMarshal(t *testing.T) { blockchain := NewBlockChain() - output, _ := blockchain.Serialize() + output, _ := blockchain.Marshal() - blockchain, err := Deserialize(output) + blockchain, err := UnMarshal(output) assert.NoError(t, err) assert.Len(t, output, 138) } @@ -58,3 +58,28 @@ func TestBlockChain_Push(t *testing.T) { assert.Equal(t, lastBlock.PrevHash, genesisBlock.Hash, "Previous hash of the last block in this test scenario should be the hash of the genesis block") } + +func TestBlockChain_Iterator(t *testing.T) { + blockchain := NewBlockChain() + _ = blockchain.Push([]byte("1")) + _ = blockchain.Push([]byte("2")) + _ = blockchain.Push([]byte("3")) + + iterator := blockchain.Iterator() + assert.Equal(t, len(*iterator.blockchain), iterator.current) + + c, _ := iterator.Next() + assert.Equal(t, "3", string(c.Data)) + b, _ := iterator.Next() + assert.Equal(t, "2", string(b.Data)) + assert.Equal(t, c.PrevHash, b.Hash) + a, _ := iterator.Next() + assert.Equal(t, "1", string(a.Data)) + assert.Equal(t, b.PrevHash, a.Hash) + genesis, _ := iterator.Next() + assert.Equal(t, a.PrevHash, genesis.Hash) + assert.Equal(t, "Genesis", string(genesis.Data)) + _, err := iterator.Next() + assert.Error(t, err) + +} diff --git a/blockchain/proof.go b/blockchain/proof.go index 57a1ad9..7e7b87a 100644 --- a/blockchain/proof.go +++ b/blockchain/proof.go @@ -18,8 +18,8 @@ type Proof struct { } func (proof *Proof) init(nonce int) []byte { - nonceHex, _ := ToHex(int64(nonce)) - difficultyHex, _ := ToHex(int64(Difficulty)) + nonceHex, _ := toHex(int64(nonce)) + difficultyHex, _ := toHex(int64(Difficulty)) data := bytes.Join( [][]byte{ proof.Block.PrevHash, @@ -77,7 +77,7 @@ func (proof *Proof) Validate() bool { return intHash.Cmp(proof.Target) == -1 } -func ToHex(num int64) (hex []byte, err error) { +func toHex(num int64) (hex []byte, err error) { buff := new(bytes.Buffer) err = binary.Write(buff, binary.BigEndian, num) From 9b037ef134c21e2b857c3387a52bfc371cf05d0a Mon Sep 17 00:00:00 2001 From: DJ Schleen Date: Fri, 1 Jul 2022 23:12:02 -0600 Subject: [PATCH 3/3] Adding workflows --- .github/dependabot.yml | 6 +++ .github/workflows/codeql-analysis.yml | 67 +++++++++++++++++++++++++++ .github/workflows/go-quality.yml | 34 ++++++++++++++ dependabot.yml | 14 ++++++ workflows/codeql-analysis.yml | 67 +++++++++++++++++++++++++++ workflows/go-quality.yml | 34 ++++++++++++++ 6 files changed, 222 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/go-quality.yml create mode 100644 dependabot.yml create mode 100644 workflows/codeql-analysis.yml create mode 100644 workflows/go-quality.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b11780b..ec52d8c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,5 +1,11 @@ version: 2 updates: +- package-ecosystem: github-actions + directory: /.github/workflows + schedule: + interval: daily + time: "05:00" + timezone: UTC - package-ecosystem: gomod directory: / schedule: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..5d1ca82 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -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. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ main ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ main ] + schedule: + - cron: '32 16 * * 1' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # 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@v1 + + # ℹī¸ 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@v1 diff --git a/.github/workflows/go-quality.yml b/.github/workflows/go-quality.yml new file mode 100644 index 0000000..d07da39 --- /dev/null +++ b/.github/workflows/go-quality.yml @@ -0,0 +1,34 @@ +name: Go Quality Checks +on: push +jobs: + tests: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '1.18' + - name: Install Dependencies + run: | + go version + go install golang.org/x/lint/golint@latest + go install github.com/fzipp/gocyclo/cmd/gocyclo@latest + - name: Tests + run: | + go test -v -coverprofile=coverage.out ./... + go tool cover -func=coverage.out + - name: CodeCov + run: bash <(curl -s https://codecov.io/bash) + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - name: Build + run: go build ./... + - name: Vet + run: go vet -v ./... + - name: Lint + run: golint ./... + - name: gocyclo + run: gocyclo . + \ No newline at end of file diff --git a/dependabot.yml b/dependabot.yml new file mode 100644 index 0000000..ec52d8c --- /dev/null +++ b/dependabot.yml @@ -0,0 +1,14 @@ +version: 2 +updates: +- package-ecosystem: github-actions + directory: /.github/workflows + schedule: + interval: daily + time: "05:00" + timezone: UTC +- package-ecosystem: gomod + directory: / + schedule: + interval: daily + time: "05:00" + timezone: UTC diff --git a/workflows/codeql-analysis.yml b/workflows/codeql-analysis.yml new file mode 100644 index 0000000..5d1ca82 --- /dev/null +++ b/workflows/codeql-analysis.yml @@ -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. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ main ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ main ] + schedule: + - cron: '32 16 * * 1' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # 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@v1 + + # ℹī¸ 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@v1 diff --git a/workflows/go-quality.yml b/workflows/go-quality.yml new file mode 100644 index 0000000..d07da39 --- /dev/null +++ b/workflows/go-quality.yml @@ -0,0 +1,34 @@ +name: Go Quality Checks +on: push +jobs: + tests: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Setup Go + uses: actions/setup-go@v2 + with: + go-version: '1.18' + - name: Install Dependencies + run: | + go version + go install golang.org/x/lint/golint@latest + go install github.com/fzipp/gocyclo/cmd/gocyclo@latest + - name: Tests + run: | + go test -v -coverprofile=coverage.out ./... + go tool cover -func=coverage.out + - name: CodeCov + run: bash <(curl -s https://codecov.io/bash) + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - name: Build + run: go build ./... + - name: Vet + run: go vet -v ./... + - name: Lint + run: golint ./... + - name: gocyclo + run: gocyclo . + \ No newline at end of file