Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Commit

Permalink
(#1): add DM auth, currently a placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
sharefile-kt committed Sep 21, 2019
1 parent a2a8979 commit 203dbe1
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 30 deletions.
55 changes: 29 additions & 26 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,32 @@ jobs:
env:
GO111MODULES: on

build_publish:
name: Build and Publish
runs-on: ubuntu-latest
needs: go_test
steps:
- uses: actions/checkout@master

- name: Buildkit master to :latest
uses: roleypoly/actions-buildkit@master
if: github.ref == 'refs/heads/master'
with:
tag: roleypoly/discord:latest
platforms: linux/amd64,linux/arm64,linux/arm/v6
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}

- name: Buildkit develop to :next
uses: roleypoly/actions-buildkit@master
if: github.ref == 'refs/heads/develop'
with:
tag: roleypoly/discord:next
platforms: linux/amd64,linux/arm64,linux/arm/v6
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
build_publish:
name: Build and Publish
runs-on: ubuntu-latest
needs: go_test
steps:
- uses: actions/checkout@master

- name: Build Docker Image (Push)
uses: roleypoly/actions-buildkit@master
if: github.event_name == 'push'
with:
tag: ${{ github.repository }}:${{ github.sha }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}

- name: Retag Image
if: github.event_name == 'push'
run: |
retag() {
curl -sSL https://github.com/docker/buildx/releases/download/v0.3.0/buildx-v0.3.0.linux-amd64 > $HOME/buildx &&\
chmod a+x $HOME/buildx &&\
$HOME/buildx imagetools create --tag "${{ github.repository }}:$1" "${{ github.repository }}:${{ github.sha }}"
}
test ${{ github.ref }} = "refs/heads/master" && retag latest || \
test ${{ github.ref }} = "refs/heads/develop" && retag next || \
test ${{ github.ref }} = "refs/heads/ci-testing" && retag scratch || \
echo "not a well-known branch, not retagging"
43 changes: 43 additions & 0 deletions auth/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package auth

import (
"os"

"context"

pbAuth "github.com/roleypoly/rpc/auth/backend"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)

type AuthConnector struct {
Client pbAuth.AuthBackendClient
}

type sharedSecretCredential struct{}

func (sharedSecretCredential) GetRequestMetadata(ctx context.Context, _ ...string) (map[string]string, error) {
return map[string]string{
"Authorization": "Shared " + os.Getenv("SHARED_SECRET"),
}, nil
}

func (sharedSecretCredential) RequireTransportSecurity() bool {
return true
}

func NewAuthConnector() (*AuthConnector, error) {
var cred sharedSecretCredential

grpcConn, err := grpc.Dial(
os.Getenv("AUTH_SVC_DIAL"),
grpc.WithPerRPCCredentials(cred),
grpc.WithTransportCredentials(credentials.NewTLS(nil)),
)
if err != nil {
return nil, err
}
return &AuthConnector{
Client: pbAuth.NewAuthBackendClient(grpcConn),
}, nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/improbable-eng/grpc-web v0.11.0
github.com/joho/godotenv v1.3.0
github.com/roleypoly/gripkit v0.0.0-20190819014327-7141453fff6a
github.com/roleypoly/rpc v0.0.0-20190908183221-801f93147031
github.com/roleypoly/rpc v0.0.0-20190921034711-ecdc7744d4c7
google.golang.org/grpc v1.22.1
)

Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ github.com/roleypoly/rpc v0.0.0-20190819014223-424feddd4840 h1:dO3WQAc0pwojbrNYq
github.com/roleypoly/rpc v0.0.0-20190819014223-424feddd4840/go.mod h1:FG1IODIUUs67+afivRw2DFzYjtQOSRDNDzT5vwh/i70=
github.com/roleypoly/rpc v0.0.0-20190908183221-801f93147031 h1:QKGgwFuHnx2GOPQP/LU+0CA+TvrqamnJiGieGIyqMN0=
github.com/roleypoly/rpc v0.0.0-20190908183221-801f93147031/go.mod h1:FG1IODIUUs67+afivRw2DFzYjtQOSRDNDzT5vwh/i70=
github.com/roleypoly/rpc v0.0.0-20190921034711-ecdc7744d4c7 h1:H1bY6DMimuk+cj5O1uEsmiQbINfPMUnvqqcH//CRCHc=
github.com/roleypoly/rpc v0.0.0-20190921034711-ecdc7744d4c7/go.mod h1:FG1IODIUUs67+afivRw2DFzYjtQOSRDNDzT5vwh/i70=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
Expand Down Expand Up @@ -315,6 +317,7 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
22 changes: 21 additions & 1 deletion responders/dm/dm_responder.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package dm

import (
"fmt"
"log"
"regexp"
"strings"

"context"

"github.com/bwmarrin/discordgo"
"github.com/roleypoly/discord/auth"
"github.com/roleypoly/discord/responders"
pbAuth "github.com/roleypoly/rpc/auth/backend"
)

var dmResponder = &responders.Responder{
Expand All @@ -20,5 +26,19 @@ func DMResponder(s *discordgo.Session, m *discordgo.MessageCreate) {
}

func handleAuth(_ [][]string, s *discordgo.Session, m *discordgo.MessageCreate) string {
return `This function is currently disabled.`
authConn, err := auth.NewAuthConnector()
if err != nil {
log.Println(err)
return ""
}

authChallenge, err := authConn.Client.GetSessionChallenge(context.Background(), &pbAuth.UserSlug{
UserID: m.Author.ID,
})
if err != nil {
log.Println(err)
return ""
}

return fmt.Sprintf("Hey there <@%s>! Tell me `%s` or click %s!", authChallenge.UserID, authChallenge.MagicWords, authChallenge.MagicUrl)
}
4 changes: 2 additions & 2 deletions rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// DiscordService is a gRPC implementation of rpc/discord.proto#Discord.
type DiscordService struct {
// pb.UnimplementedDiscordServer
pb.UnimplementedDiscordServer
Discord *discordgo.Session
}

Expand Down Expand Up @@ -83,7 +83,7 @@ func (d *DiscordService) GetUser(ctx context.Context, req *pb.IDQuery) (*pb.User
return msgbuilder.User(user), err
}

func (d *DiscordService) OwnUser(ctx context.Context, req *pb.IDQuery) (*pb.User, error) {
func (d *DiscordService) OwnUser(ctx context.Context, req *empty.Empty) (*pb.User, error) {
user := d.Discord.State.User
return msgbuilder.User(user), nil
}

0 comments on commit 203dbe1

Please sign in to comment.