cisco

Home Shitty cloud provider
Log | Files | Refs | Submodules | git clone https://git.ne02ptzero.me/git/cisco

commit 89b07202c84982fc48d6d240e752f101878cdb45
Author: Louis Solofrizzo <louis@ne02ptzero.me>
Date:   Thu,  7 Mar 2019 13:41:17 +0100

Tree & Api: Add basic CMake tree and function go SSL API

Signed-off-by: Louis Solofrizzo <louis@ne02ptzero.me>

Diffstat:
A.gitignore | 1+
ACMakeLists.txt | 30++++++++++++++++++++++++++++++
Aapi/CMakeLists.txt | 3+++
Aapi/main.go | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adefs/go/CMakeLists.txt | 47+++++++++++++++++++++++++++++++++++++++++++++++
Ago.mod | 28++++++++++++++++++++++++++++
Ago.sum | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 283 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -0,0 +1,30 @@ +#### +# General Settings +### + +cmake_minimum_required(VERSION 3.4) +enable_testing() + +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + message(FATAL_ERROR "Don't use 'cmake .' Create a build folder first") +endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + +find_program(GO_PATH go) +if (${GO_PATH} STREQUAL "") + message(FATAL_ERROR "The Golang binary was not found in the path") +else () + execute_process(COMMAND ${GO_PATH} "version" OUTPUT_VARIABLE GO_VERSION) + if (NOT ${GO_VERSION} MATCHES ".*go1\.1[1-9].*") + message(FATAL_ERROR "The Golang version is not supported (>= 1.11.*)") + endif () +endif () + +#### +# Compilation Settings +#### +add_subdirectory(defs/go) + +#### +# Software +#### +add_subdirectory(api) diff --git a/api/CMakeLists.txt b/api/CMakeLists.txt @@ -0,0 +1,3 @@ +add_go_component(lf-cloud-api + main.go +) diff --git a/api/main.go b/api/main.go @@ -0,0 +1,103 @@ +package main + +import ( + "crypto/rand" + "crypto/tls" + "crypto/x509" + "io/ioutil" + + log "github.com/sirupsen/logrus" + + "github.com/kataras/iris" +) + +type Instance struct { + Name string `json:"name"` + Architecture string `json:"arch"` + OS string `json:"os"` +} + +func user_keys(ctx iris.Context) { +} + +func user_init(ctx iris.Context) { +} + +func user_add_key(ctx iris.Context) { + +} + +func instance_list(ctx iris.Context) { +} + +func instance_add(ctx iris.Context) { + var instance Instance + + ctx.ReadJSON(&instance) + ctx.Writef("%s - %s - %s", instance.Name, instance.Architecture, instance.OS) +} + +func instance_exists(ctx iris.Context) { + var tls *tls.ConnectionState + + tls = ctx.Request().TLS + //log.Infof("%s", tls.PeerCertificates[0].Subject) + name := ctx.Params().Get("name") + ctx.Writef("Instance %s do exist, and you are %s", name, tls.PeerCertificates[0].Subject.CommonName) +} + +func instance_get(ctx iris.Context) { + +} + +func main() { + app := iris.New() + app.Use(func(ctx iris.Context) { + log.WithFields(log.Fields{ + "ip": ctx.RemoteAddr(), + "path": ctx.Path(), + "method": ctx.Method(), + }).Info("api request") + ctx.Next() + }) + + app.Get("/user/keys", user_keys) + app.Get("/user/init", user_init) + app.Post("/user/add_key", user_add_key) + app.Get("/instance/list", instance_list) + app.Get("/instance/exists/{name:string}", instance_exists) + app.Post("/instance/add", instance_add) + app.Get("/instance/{name:string}", instance_get) + + /* TLS */ + cert, err := tls.LoadX509KeyPair("./api_cloud.crt", "./api_cloud.key") + if err != nil { + log.Fatalf("Failed loading x509 key pair: %s", err) + } + + certpool := x509.NewCertPool() + pem, err := ioutil.ReadFile("./ca.crt") + if err != nil { + log.Fatalf("Failed to read client certificate authority: %v", err) + } + if !certpool.AppendCertsFromPEM(pem) { + log.Fatalf("Can't parse client certificate authority") + } + + tlsconfig := tls.Config{ + Certificates: []tls.Certificate{cert}, + ClientAuth: tls.RequireAndVerifyClientCert, + ClientCAs: certpool, + } + + tlsconfig.Rand = rand.Reader + listener, err := tls.Listen("tcp", "localhost:8080", &tlsconfig) + + if err != nil { + log.Fatalf("Failed to listen: %s", err) + } + + app.Run(iris.Listener(listener), iris.WithConfiguration(iris.Configuration{ + FireMethodNotAllowed: true, + })) +} diff --git a/defs/go/CMakeLists.txt b/defs/go/CMakeLists.txt @@ -0,0 +1,47 @@ +# Fake CMake rule +function(add_go_component NAME) + add_custom_target(${NAME} ALL) + + # GoPath settings + set(GOPATH "${CMAKE_BINARY_DIR}/go") + file(MAKE_DIRECTORY ${GOPATH}) + + # Add sources + foreach(DEP ${ARGN}) + set(GO_SRC "${GO_SRC} ${CMAKE_CURRENT_LIST_DIR}/${DEP}") + endforeach() + + add_custom_command( + TARGET ${NAME} + DEPENDS + ${GO_SRC} + COMMAND + export GOPATH=${GOPATH} && export GO111MODULE=on && + export GOMOD=${CMAKE_SOURCE_DIR}/.go.mod && + /usr/bin/env bash -c + "go build -o ${CMAKE_CURRENT_BINARY_DIR}/${NAME} ${CMAKE_GO_FLAGS} ${GO_SRC}" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) +endfunction(add_go_component) + +function(add_go_test NAME) + if (WITH_TESTS STREQUAL "ON") + add_test(NAME ${NAME} COMMAND go test -v WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + endif() +endfunction() + +macro(add_to_pkg_config_path PATH) + set(PKG_CONFIG_PATH "${PKG_CONFIG_PATH}:${PATH}" CACHE INTERNAL "") +endmacro() + +macro(add_to_cgo_libraries PATH) + set(CGO_LDFLAGS "${CGO_LDFLAGS};-L${PATH}" CACHE INTERNAL "") +endmacro() + +macro(add_to_cgo_includes PATH) + set(CGO_CFLAGS "${CGO_CFLAGS};-I${PATH}" CACHE INTERNAL "") +endmacro() + +macro(add_to_cgo_cflags FLAG) + set(CGO_CFLAGS "${CGO_CFLAGS};${FLAG}" CACHE INTERNAL "") +endmacro() diff --git a/go.mod b/go.mod @@ -0,0 +1,28 @@ +module cisco + +go 1.12 + +require ( + github.com/BurntSushi/toml v0.3.1 // indirect + github.com/Joker/jade v1.0.0 // indirect + github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398 // indirect + github.com/aymerick/raymond v2.0.2+incompatible // indirect + github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 // indirect + github.com/fatih/structs v1.1.0 // indirect + github.com/flosch/pongo2 v0.0.0-20181225140029-79872a7b2769 // indirect + github.com/iris-contrib/blackfriday v2.0.0+incompatible // indirect + github.com/iris-contrib/formBinder v0.0.0-20190104093907-fbd5963f41e1 // indirect + github.com/iris-contrib/go.uuid v2.0.0+incompatible // indirect + github.com/json-iterator/go v1.1.5 // indirect + github.com/kataras/golog v0.0.0-20180321173939-03be10146386 // indirect + github.com/kataras/iris v11.1.1+incompatible // indirect + github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d // indirect + github.com/klauspost/compress v1.4.1 // indirect + github.com/klauspost/cpuid v1.2.0 // indirect + github.com/microcosm-cc/bluemonday v1.0.2 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/ryanuber/columnize v2.1.0+incompatible // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/sirupsen/logrus v1.3.0 // indirect +) diff --git a/go.sum b/go.sum @@ -0,0 +1,71 @@ +github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Joker/hpp v0.0.0-20180418125244-6893e659854a/go.mod h1:MzD2WMdSxvbHw5fM/OXOFily/lipJWRc9C1px0Mt0ZE= +github.com/Joker/jade v1.0.0 h1:lOCEPvTAtWfLpSZYMOv/g44MGQFAolbKh2khHHGu0Kc= +github.com/Joker/jade v1.0.0/go.mod h1:efZIdO0py/LtcJRSa/j2WEklMSAw84WV0zZVMxNToB8= +github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398 h1:WDC6ySpJzbxGWFh4aMxFFC28wwGp5pEuoTtvA4q/qQ4= +github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0= +github.com/aymerick/raymond v2.0.2+incompatible h1:VEp3GpgdAnv9B2GFyTvqgcKvY+mfKMjPOA3SbKLtnU0= +github.com/aymerick/raymond v2.0.2+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o= +github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= +github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= +github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= +github.com/flosch/pongo2 v0.0.0-20181225140029-79872a7b2769 h1:XToLChWPMXLomJ2InnkrmUkddaXfevrmomMTFL+MaKU= +github.com/flosch/pongo2 v0.0.0-20181225140029-79872a7b2769/go.mod h1:tbAXHifHQWNSpWbiJHpJTZH5fi3XHhDMdP//vuz9WS4= +github.com/go-check/check v1.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= +github.com/iris-contrib/blackfriday v2.0.0+incompatible h1:o5sHQHHm0ToHUlAJSTjW9UWicjJSDDauOOQ2AHuIVp4= +github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI= +github.com/iris-contrib/formBinder v0.0.0-20190104093907-fbd5963f41e1 h1:7GsNnSLoVceNylMpwcfy5aFNz/S5/TV25crb34I5PEo= +github.com/iris-contrib/formBinder v0.0.0-20190104093907-fbd5963f41e1/go.mod h1:i8kTYUOEstd/S8TG0ChTXQdf4ermA/e8vJX0+QruD9w= +github.com/iris-contrib/go.uuid v2.0.0+incompatible h1:XZubAYg61/JwnJNbZilGjf3b3pB80+OQg2qf6c8BfWE= +github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0= +github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswDE= +github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 h1:rhqTjzJlm7EbkELJDKMTU7udov+Se0xZkWmugr6zGok= +github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= +github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= +github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= +github.com/kataras/golog v0.0.0-20180321173939-03be10146386 h1:VT6AeCHO/mc+VedKBMhoqb5eAK8B1i9F6nZl7EGlHvA= +github.com/kataras/golog v0.0.0-20180321173939-03be10146386/go.mod h1:PcaEvfvhGsqwXZ6S3CgCbmjcp+4UDUh2MIfF2ZEul8M= +github.com/kataras/iris v11.1.1+incompatible h1:c2iRKvKLpTYMXKdVB8YP/+A67NtZFt9kFFy+ZwBhWD0= +github.com/kataras/iris v11.1.1+incompatible/go.mod h1:ki9XPua5SyAJbIxDdsssxevgGrbpBmmvoQmo/A0IodY= +github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d h1:V5Rs9ztEWdp58oayPq/ulmlqJJZeJP6pP79uP3qjcao= +github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d/go.mod h1:NV88laa9UiiDuX9AhMbDPkGYSPugBOV6yTZB1l2K9Z0= +github.com/klauspost/compress v1.4.1 h1:8VMb5+0wMgdBykOV96DwNwKFQ+WTI4pzYURP99CcB9E= +github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= +github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE= +github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw= +github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s= +github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/ryanuber/columnize v2.1.0+incompatible h1:j1Wcmh8OrK4Q7GXY+V7SVSY8nUWQxHW5TkBe7YUl+2s= +github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME= +github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=