Skip to content

Commit

Permalink
Merge pull request #64 from OperationSpark/62-support-for-auto-enroll…
Browse files Browse the repository at this point in the history
…ment

Support for auto enrollment
  • Loading branch information
harveysanders authored Jan 3, 2024
2 parents 2c7895f + 34ba9ec commit 511801b
Show file tree
Hide file tree
Showing 20 changed files with 393 additions and 129 deletions.
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ SLACK_WEBHOOK_URL="[Slack Webhook URL]"
# Greenlight API
# Where to POST signups for the Greenlight Database
GREENLIGHT_WEBHOOK_URL=http://greenlight.operationspark.opg/api/signup
GREENLIGHT_HOST="https://greenlight.operationspark.org/"


# Mailgun API
MAIL_DOMAIN=mail.operationspark.org
Expand All @@ -30,3 +32,6 @@ TWILIO_CONVERSATIONS_SID="[Twilio Conversations SID]"
URL_SHORTENER_API_KEY="[Operation Spark URL Shortener API Key]"

OS_MESSAGING_SERVICE_URL="[Operation Spark Messenger Service URL (e.g. https://messenger.operationspark.org)]"

MONGO_URI="mongodb://localhost:27017/greenlight"

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
filename: coverage.out

- name: Verify Changed files
uses: tj-actions/verify-changed-files@v9.1
uses: tj-actions/verify-changed-files@v17
id: verify-changed-files
with:
files: README.md
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
MAIL_DOMAIN=${{secrets.MAIL_DOMAIN}},
MAILGUN_API_KEY=${{secrets.MAILGUN_API_KEY}},
GREENLIGHT_WEBHOOK_URL=${{secrets.GREENLIGHT_WEBHOOK_URL}},
GREENLIGHT_HOST=${{secrets.GREENLIGHT_HOST}},
GREENLIGHT_API_KEY=${{secrets.GREENLIGHT_API_KEY}},
ZOOM_ACCOUNT_ID=${{secrets.ZOOM_ACCOUNT_ID}},
ZOOM_CLIENT_ID=${{secrets.ZOOM_CLIENT_ID}},
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/deploy-testing.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: GCP Cloud Functions Deploy (Testing)
on:
workflow_dispatch:
push:
branches:
- "testing"

jobs:
build-deploy-cloud-function:
Expand Down Expand Up @@ -35,6 +32,7 @@ jobs:
MAIL_DOMAIN=${{secrets.MAIL_DOMAIN}},
MAILGUN_API_KEY=${{secrets.MAILGUN_API_KEY}},
GREENLIGHT_WEBHOOK_URL=${{secrets.GREENLIGHT_WEBHOOK_URL}},
GREENLIGHT_HOST=${{secrets.GREENLIGHT_HOST}},
GREENLIGHT_API_KEY=${{secrets.GREENLIGHT_API_KEY}},
ZOOM_ACCOUNT_ID=${{secrets.ZOOM_ACCOUNT_ID}},
ZOOM_CLIENT_ID=${{secrets.ZOOM_CLIENT_ID}},
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
MAIL_DOMAIN=${{secrets.MAIL_DOMAIN}},
MAILGUN_API_KEY=${{secrets.MAILGUN_API_KEY}},
GREENLIGHT_WEBHOOK_URL=${{secrets.GREENLIGHT_WEBHOOK_URL}},
GREENLIGHT_HOST=${{secrets.GREENLIGHT_HOST}},
GREENLIGHT_API_KEY=${{secrets.GREENLIGHT_API_KEY}},
ZOOM_ACCOUNT_ID=${{secrets.ZOOM_ACCOUNT_ID}},
ZOOM_CLIENT_ID=${{secrets.ZOOM_CLIENT_ID}},
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"go.testEnvFile": "${workspaceFolder}/.env.smoke",
"cSpell.words": [
"Emptyf",
"gldb",
"stretchr"
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Session Sign Up Service

![Coverage](https://img.shields.io/badge/Coverage-56.7%25-yellow)
![Coverage](https://img.shields.io/badge/Coverage-56.6%25-yellow)

When someone signs up for an Info Session on [operationspark.org](https://operationspark.org),
this service runs a series of tasks:
Expand Down
1 change: 1 addition & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func main() {
if envPort := os.Getenv("PORT"); envPort != "" {
port = envPort
}
log.Printf("server starting on port: %s\n", port)
if err := funcframework.Start(port); err != nil {
log.Fatalf("funcframework.Start: %v\n", err)
}
Expand Down
20 changes: 20 additions & 0 deletions function.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"time"

"github.com/GoogleCloudPlatform/functions-framework-go/functions"
"github.com/operationspark/service-signup/mongodb"
"github.com/operationspark/service-signup/notify"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
Expand Down Expand Up @@ -82,6 +83,18 @@ func checkEnvVars(skip bool) error {
return nil
}

func getMongoClient() (*mongo.Client, string, error) {
mongoURI := os.Getenv("MONGO_URI")
isCI := os.Getenv("CI") == "true"
parsed, err := url.Parse(mongoURI)
if isCI || (mongoURI == "" || err != nil) {
return nil, "", fmt.Errorf("invalid 'MONGO_URI' environmental variable: %q", mongoURI)
}
dbName := strings.TrimPrefix(parsed.Path, "/")
m, err := mongo.Connect(context.Background(), options.Client().ApplyURI(mongoURI))
return m, dbName, err
}

func NewNotifyServer() *notify.Server {
mongoURI := os.Getenv("MONGO_URI")
isCI := os.Getenv("CI") == "true"
Expand Down Expand Up @@ -160,6 +173,12 @@ func NewSignupServer() *signupServer {
conversationsSid: twilioConversationsSid,
})

mongoClient, dbName, err := getMongoClient()
if err != nil && os.Getenv("CI") != "true" {
log.Fatalf("Could not connect to MongoDB: %v\n", err)
}

gldbService := mongodb.New(dbName, mongoClient)
snapMailURL := os.Getenv("SNAP_MAIL_URL")
snapMailSvc := NewSnapMail(snapMailURL, WithSigningSecret(os.Getenv("SIGNING_SECRET")))

Expand All @@ -171,6 +190,7 @@ func NewSignupServer() *signupServer {
},
// registering the user for the Zoom meeting,
zoomService: zoomSvc,
gldbService: gldbService,
// Registration tasks:
// (executed concurrently)
tasks: []Task{
Expand Down
32 changes: 17 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ require (
require (
cloud.google.com/go/compute v1.23.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/continuity v0.4.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/cli v20.10.14+incompatible // indirect
github.com/docker/docker v20.10.7+incompatible // indirect
github.com/docker/cli v24.0.7+incompatible // indirect
github.com/docker/docker v24.0.7+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-chi/chi/v5 v5.0.11 // indirect
github.com/go-logr/logr v1.4.1 // indirect
Expand All @@ -35,22 +35,22 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/opencontainers/runc v1.1.2 // indirect
github.com/opencontainers/runc v1.1.11 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
Expand All @@ -60,15 +60,17 @@ require (
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand All @@ -81,7 +83,7 @@ require (
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/ory/dockertest/v3 v3.9.1
github.com/ory/dockertest/v3 v3.10.0
github.com/stretchr/testify v1.8.4
github.com/twilio/twilio-go v1.16.0
go.mongodb.org/mongo-driver v1.13.1
Expand Down
Loading

0 comments on commit 511801b

Please sign in to comment.