~ols/whois

ab784f91bcb14e9970074942f4ff7aa7ce17062a — Oliver Leaver-Smith a month ago
Initial commit of code
4 files changed, 203 insertions(+), 0 deletions(-)

A Gopkg.toml
A Makefile
A main.go
A serverless.yml
A  => Gopkg.toml +25 -0
@@ 1,25 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
#   name = "github.com/user/project"
#   version = "1.0.0"
#
# [[constraint]]
#   name = "github.com/user/project2"
#   branch = "dev"
#   source = "github.com/myfork/project2"
#
# [[override]]
#  name = "github.com/x/y"
#  version = "2.4.0"


[[constraint]]
  name = "github.com/aws/aws-lambda-go"
  version = "1.x"

A  => Makefile +11 -0
@@ 1,11 @@
.PHONY: build clean deploy

build:
	dep ensure -v
	env GOOS=linux go build -ldflags="-s -w" -o bin/whoami main.go

clean:
	rm -rf ./bin ./vendor Gopkg.lock

deploy: clean build
	sls deploy --verbose

A  => main.go +149 -0
@@ 1,149 @@
package main

import (
	"bytes"
	"context"
	"encoding/json"
	"time"

	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
)

// Response is of type APIGatewayProxyResponse since we're leveraging the
// AWS Lambda Proxy Request functionality (default behavior)
//
// https://serverless.com/framework/docs/providers/aws/events/apigateway/#lambda-proxy-integration
type Response events.APIGatewayProxyResponse

// Handler is our lambda handler invoked by the `lambda.Start` function call
func Handler(ctx context.Context) (Response, error) {
	var buf bytes.Buffer
	timeSince := time.Since(time.Date(1990, time.Month(3), 9, 0, 22, 0, 0, time.UTC)).String()

	type jsonPayload struct {
		About           string
		Bio             string
		PersonalDetails struct {
			Name struct {
				Fullname struct {
					Canonical string
					Preferred string
				}
				Firstname struct {
					Canonical string
					Preferred string
				}
				FamilyName  string
				MiddleNames string
				Initials    struct {
					Canonical string
					Preferred string
				}
			}
			Age      string
			Pronouns string
		}
		ContactDetails struct {
			PhoneNumbers struct {
				Mobile   string
				Landline string
			}
			Email  string
			Social struct {
				Fediverse string
				Twitter   string
				Instagram string
				IRC       struct {
					Freenode struct {
						Server string
						Nick   string
					}
					Hackint struct {
						Server string
						Nick   string
					}
					Terahertz struct {
						Server string
						Nick   string
					}
					Nixers struct {
						Server string
						Nick   string
					}
					TildeChat struct {
						Server string
						Nick   string
					}
				}
			}
			Wire    string
			Keybase string
			Discord string
		}
		WorkDetails struct {
			Employer string
			JobTitle string
		}
	}

	values := jsonPayload{}
	values.About = `This is a simple application to display my "whois". It includes all the details you should need in order to get in touch with me, and also to decide if you actually want to. It is as Lambda function hosted in AWS, behind their API Gateway product, available the domain https://api.ols.wtf/whois (but as you're here, you probably already knew that). The code is hosted here: https://git.sr.ht/~ols/whois`
	values.Bio = `Oliver Leaver-Smith, better known as ols, is a distinguished technologist currently working as a Senior Platform Engineer at Sky Betting and Gaming. His topics of expertise include OpenBSD, automation, chaos and resilience engineering, and Nerf warfare.

He is also interested in security, privacy, opensource, decentralisation and federation, hardware hacking, and cyberdecks.

Interested in technology (specifically how it breaks) from a young age, his first foray into Linux was in 2003 when, while blindly following the installation instructions in Sams Teach Yourself Red Hat Linux, he upgraded his dad’s Windows XP machine to Red Hat 9. This resulted in him getting his own computer, so has been widely regarded as a good thing.`
	values.PersonalDetails.Name.Fullname.Canonical = "Oliver John Leaver-Smith"
	values.PersonalDetails.Name.Fullname.Preferred = "Oliver Leaver-Smith"
	values.PersonalDetails.Name.Firstname.Canonical = "Oliver"
	values.PersonalDetails.Name.Firstname.Preferred = "ols"
	values.PersonalDetails.Name.FamilyName = "Leaver-Smith"
	values.PersonalDetails.Name.MiddleNames = "John"
	values.PersonalDetails.Name.Initials.Canonical = "OJLS"
	values.PersonalDetails.Name.Initials.Preferred = "OLS"
	values.PersonalDetails.Age = timeSince
	values.PersonalDetails.Pronouns = "he/him"
	values.ContactDetails.PhoneNumbers.Mobile = "+447450217558"
	values.ContactDetails.PhoneNumbers.Landline = "+441143601337"
	values.ContactDetails.Email = "oliver+whois@leaversmith.com"
	values.ContactDetails.Social.Fediverse = "chaos.social/@ols"
	values.ContactDetails.Social.Twitter = "@heyitsols"
	values.ContactDetails.Social.Instagram = "@heyitsols"
	values.ContactDetails.Social.IRC.Freenode.Server = "chat.freenode.net"
	values.ContactDetails.Social.IRC.Freenode.Nick = "ols"
	values.ContactDetails.Social.IRC.Hackint.Server = "irc.hackint.org"
	values.ContactDetails.Social.IRC.Hackint.Nick = "ols"
	values.ContactDetails.Social.IRC.Terahertz.Server = "irc.terahertz.org"
	values.ContactDetails.Social.IRC.Terahertz.Nick = "ols"
	values.ContactDetails.Social.IRC.Nixers.Server = "irc.nixers.net"
	values.ContactDetails.Social.IRC.Nixers.Nick = "ols"
	values.ContactDetails.Social.IRC.TildeChat.Server = "irc.tilde.chat"
	values.ContactDetails.Social.IRC.TildeChat.Nick = "ols"
	values.ContactDetails.Wire = "@heyitsols"
	values.ContactDetails.Keybase = "mugoftea"
	values.ContactDetails.Discord = "ols#7774"
	values.WorkDetails.Employer = "Sky Betting and Gaming"
	values.WorkDetails.JobTitle = "Senior Platform Engineer"

	body, err := json.Marshal(values)
	if err != nil {
		return Response{StatusCode: 404}, err
	}
	json.HTMLEscape(&buf, body)

	resp := Response{
		StatusCode:      200,
		IsBase64Encoded: false,
		Body:            buf.String(),
		Headers: map[string]string{
			"Content-Type": "application/json",
		},
	}

	return resp, nil
}

func main() {
	lambda.Start(Handler)
}

A  => serverless.yml +18 -0
@@ 1,18 @@
service: ols-whoami-serverless
frameworkVersion: '>=1.28.0 <2.0.0'
provider:
  name: aws
  runtime: go1.x
  region: eu-west-2
package:
  exclude:
    - ./**
  include:
    - ./bin/**
functions:
  hello:
    handler: bin/whoami
    events:
      - http:
          path: /
          method: get