Skip to content

Commit

Permalink
Switch to Microbox names/namespaces & MIT license
Browse files Browse the repository at this point in the history
  • Loading branch information
danhunsaker committed Jun 18, 2023
1 parent f463375 commit 4a6e1cb
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 397 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ _testmain.go
*.exe
*.test
*.prof

butter
361 changes: 21 additions & 340 deletions LICENSE

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![butter logo](http://nano-assets.gopagoda.io/readme-headers/butter.png)](http://nanobox.io/open-source#butter)
[![Build Status](https://travis-ci.org/nanopack/butter.svg)](https://travis-ci.org/nanopack/butter)
[![butter logo](http://microbox.rocks/assets/readme-headers/butter.png)](http://microbox.cloud/open-source#butter)
[![Build Status](https://github.com/mu-box/butter/actions/workflows/ci.yaml/badge.svg)](https://github.com/mu-box/butter/actions)

## Butter

Expand All @@ -12,15 +12,15 @@ Experimental/Unstable/Incomplete

| Route | Description | Payload | Response |
| --- | --- | --- | --- |
| `/files?ref={ref}` | Show the names of all the files at the specific ref, or MASTER | nil | `{file contents}` |
| `/files/{file}?ref={ref}` | Get the content of the file at the specific ref, or MASTER | nil | `{file contents}` |
| `/branches` | Get the names of all branches pushed | nil | `["master"]` |
| `/files?ref={ref}` | Show the names of all the files at the specific ref, or MAIN | nil | `{file contents}` |
| `/files/{file}?ref={ref}` | Get the content of the file at the specific ref, or MAIN | nil | `{file contents}` |
| `/branches` | Get the names of all branches pushed | nil | `["main"]` |
| `/commits` | Get a list of all the commits | nil | `[{"id":"sha","message":"this is a message","author":"me"}]` |
| `/commits/{commit}` | Get details about a specific commit | nil | `[{"id":"sha","author":"me","message":"this is a message","author_date":"jan","author_email":"[email protected]"}]` |

[![butter logo](http://nano-assets.gopagoda.io/open-src/nanobox-open-src.png)](http://nanobox.io/open-source)
[![butter logo](http://microbox.rocks/assets/open-src/microbox-open-src.png)](http://microbox.cloud/open-source)


## TODO
build a cli
Write tests
Write tests
8 changes: 4 additions & 4 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package api

import (
"net/http"

"encoding/json"

"github.com/gorilla/pat"
"github.com/nanobox-io/nanoauth"
"github.com/nanopack/butter/config"
"github.com/mu-box/butter/config"
"github.com/mu-box/golang-microauth"
)

func Start() error {
Expand All @@ -21,7 +21,7 @@ func Start() error {

// blocking...
config.Log.Info("Api Listening on %s", config.HttpListenAddress)
return nanoauth.ListenAndServeTLS(config.HttpListenAddress, config.Token, router)
return microauth.ListenAndServeTLS(config.HttpListenAddress, config.Token, router)
}

// handleRequest
Expand Down
3 changes: 2 additions & 1 deletion api/branch.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package api

import (
"github.com/nanopack/butter/repo"
"net/http"

"github.com/mu-box/butter/repo"
)

func showBranches(rw http.ResponseWriter, req *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions api/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"net/http"
"strconv"

"github.com/nanopack/butter/repo"
"github.com/mu-box/butter/repo"
)

func showCommits(rw http.ResponseWriter, req *http.Request) {
page, _ := strconv.Atoi(req.FormValue("page"))
branch := req.FormValue("branch")
if branch == "" {
branch = "master"
branch = "main"
}
commits, err := repo.ListCommits(branch, page)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions api/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"io"
"net/http"

"github.com/nanopack/butter/repo"
"github.com/mu-box/butter/repo"
)

func listFiles(rw http.ResponseWriter, req *http.Request) {
comm := req.FormValue("commit")
fmt.Println("commmmm",comm)
fmt.Println("commmmm", comm)
files, err := repo.ListFiles(comm)
if err != nil {
rw.Write([]byte(err.Error()))
Expand Down
2 changes: 1 addition & 1 deletion auth/auth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package auth

import (
"github.com/nanopack/butter/config"
"github.com/mu-box/butter/config"
"golang.org/x/crypto/ssh"
)

Expand Down
7 changes: 4 additions & 3 deletions auth/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"encoding/base64"
"fmt"
"golang.org/x/crypto/ssh"
"os"
"os/exec"

"github.com/nanopack/butter/config"
"golang.org/x/crypto/ssh"

"github.com/mu-box/butter/config"
)

type (
Expand Down Expand Up @@ -67,7 +68,7 @@ func (s ScriptPassAuth) Auth(conn ssh.ConnMetadata, password []byte) (*ssh.Permi

func (s ScriptKeyAuth) Auth(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
cmd := exec.Command(config.KeyAuthLocation, conn.User(), conn.RemoteAddr().String())
k := fmt.Sprintf("%s\n",base64.StdEncoding.EncodeToString(key.Marshal()))
k := fmt.Sprintf("%s\n", base64.StdEncoding.EncodeToString(key.Marshal()))
keyReader := bytes.NewReader([]byte(k))
cmd.Stdin = keyReader
output, err := cmd.CombinedOutput()
Expand Down
Binary file removed butter
Binary file not shown.
22 changes: 8 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,17 @@ func Parse(configFile string) {
if c["key_auth_location"] != "" {
KeyAuthLocation = c["key_auth_location"]
}
if c["repo_type"] != "" {
RepoType = c["repo_type"]
}
if c["repo_location"] != "" {
RepoLocation = c["repo_location"]
}
if c["repo_type"] != "" {
RepoType = c["repo_type"]
if c["pass_auth_type"] != "" {
PassAuthType = c["pass_auth_type"]
}
if c["repo_location"] != "" {
RepoLocation = c["repo_location"]
if c["pass_auth_location"] != "" {
PassAuthLocation = c["pass_auth_location"]
}
if c["repo_type"] != "" {
RepoType = c["repo_type"]
if c["deploy_type"] != "" {
DeployType = c["deploy_type"]
}
if c["repo_location"] != "" {
RepoLocation = c["repo_location"]
if c["deploy_location"] != "" {
DeployLocation = c["deploy_location"]
}
if c["token"] != "" {
Token = c["token"]
Expand Down
3 changes: 2 additions & 1 deletion deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package deploy

import (
"github.com/nanopack/butter/config"
"io"

"github.com/mu-box/butter/config"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion deploy/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"os/exec"

"github.com/nanopack/butter/config"
"github.com/mu-box/butter/config"
)

type (
Expand Down
18 changes: 18 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module github.com/mu-box/butter

go 1.20

require (
github.com/ghodss/yaml v1.0.0
github.com/gorilla/pat v1.0.1
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25
github.com/shazow/go-git v0.0.0-20160121233150-de8e3e7d8e33
github.com/spf13/cobra v1.7.0
golang.org/x/crypto v0.8.0
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.7.0 // indirect
)
23 changes: 23 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gorilla/pat v1.0.1 h1:OeSoj6sffw4/majibAY2BAUsXjNP7fEE+w30KickaL4=
github.com/gorilla/pat v1.0.1/go.mod h1:YeAe0gNeiNT5hoiZRI4yiOky6jVdNvfO2N6Kav/HmxY=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25 h1:EFT6MH3igZK/dIVqgGbTqWVvkZ7wJ5iGN03SVtvvdd8=
github.com/jcelliott/lumber v0.0.0-20160324203708-dd349441af25/go.mod h1:sWkGw/wsaHtRsT9zGQ/WyJCotGWG/Anow/9hsAcBWRw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shazow/go-git v0.0.0-20160121233150-de8e3e7d8e33 h1:BrlSMEdfCHjKx0/B2ahYMY2yCq7bL6M/j+/Y66YRrvA=
github.com/shazow/go-git v0.0.0-20160121233150-de8e3e7d8e33/go.mod h1:4daBY6o1+mu3KD0gNk+IaWqr637s0nF9n8EK72x9gEM=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package main

import (
"github.com/nanopack/butter/api"
"github.com/nanopack/butter/auth"
"github.com/nanopack/butter/config"
"github.com/nanopack/butter/deploy"
"github.com/nanopack/butter/repo"
"github.com/nanopack/butter/server"
"github.com/mu-box/butter/api"
"github.com/mu-box/butter/auth"
"github.com/mu-box/butter/config"
"github.com/mu-box/butter/deploy"
"github.com/mu-box/butter/repo"
"github.com/mu-box/butter/server"

"github.com/spf13/cobra"
)
Expand Down
18 changes: 9 additions & 9 deletions repo/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

"github.com/shazow/go-git"

"github.com/nanopack/butter/config"
"github.com/nanopack/butter/deploy"
"github.com/mu-box/butter/config"
"github.com/mu-box/butter/deploy"
)

type (
Expand Down Expand Up @@ -81,7 +81,7 @@ func (g gitRepo) ListCommits(branch string, page int) ([]Commit, error) {
}
page = page - 1
for i := 0; i < list.Len() && elem != nil; i++ {
if !paging || i / 100 == page {
if !paging || i/100 == page {
c, ok := elem.Value.(*git.Commit)
if !ok {
return nil, fmt.Errorf("the element value is of type %#v", elem.Value)
Expand All @@ -96,9 +96,9 @@ func (g gitRepo) ListCommits(branch string, page int) ([]Commit, error) {
commits = append(commits, com)

}
elem = elem.Next()
elem = elem.Next()
}
for ; elem != nil; {
for elem != nil {
}
return commits, nil
}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (g gitRepo) ListFiles(commit string) ([]File, error) {
// ModTime: scanner.TreeEntry().ModTime(),
// }
// files = append(files, file)
// }
// }

return files, nil
}
Expand Down Expand Up @@ -203,7 +203,7 @@ func (g gitRepo) GetFile(commit, path string) (File, error) {
}

func (g gitRepo) GetFileReader(commit, path string) (io.ReadCloser, error) {
fmt.Println("thisisafadsfasfsdaf",path)
fmt.Println("thisisafadsfasfsdaf", path)
repo, err := g.repo()
if err != nil {
fmt.Println("repo")
Expand Down Expand Up @@ -231,10 +231,10 @@ func (push Push) Match(command string) bool {
}

func (push Push) Run(command string, ch ssh.Channel) (uint64, error) {
//TODO make "master" be dynamic
//TODO make "main" be dynamic
code, err := gitShell(ch, ch.Stderr(), command)
if err == nil {
newCommit := getCommit("master")
newCommit := getCommit("main")
stream := ch.Stderr()
err = deploy.Run(stream, newCommit)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"golang.org/x/crypto/ssh"

"github.com/nanopack/butter/config"
"github.com/mu-box/butter/config"
)

type (
Expand Down
5 changes: 3 additions & 2 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package server
import (
"encoding/binary"
"errors"

"golang.org/x/crypto/ssh"

"github.com/nanopack/butter/config"
"github.com/nanopack/butter/repo"
"github.com/mu-box/butter/config"
"github.com/mu-box/butter/repo"
)

type (
Expand Down
8 changes: 5 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package server

import (
"fmt"
"github.com/nanopack/butter/auth"
"github.com/nanopack/butter/config"
"golang.org/x/crypto/ssh"
"io"
"io/ioutil"
"net"

"github.com/mu-box/butter/auth"
"github.com/mu-box/butter/config"

"golang.org/x/crypto/ssh"
)

var sshServer *ssh.ServerConfig
Expand Down

0 comments on commit 4a6e1cb

Please sign in to comment.