Skip to content

Commit

Permalink
changed the infrastructure of cms-oauth
Browse files Browse the repository at this point in the history
  • Loading branch information
zephyrz73 committed Aug 26, 2020
1 parent 0b9c511 commit 35af133
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
12 changes: 11 additions & 1 deletion aws-ts-netlify-cms-and-oauth/cms-oauth/infrastructure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const cmsStackConfig = {
githubSecret : pulumiConfig.requireSecret("githubSecret"),
// The domain of the OAuth Server that we want
targetDomain : pulumiConfig.require("targetDomain"),
// (Optional) the github scope we want CMS to edit, the values are in this link https://developer.github.com/apps/building-oauth-apps/understanding-scopes-for-oauth-apps/
// You can also specify multiple scopes and separate by comma
githubScope: pulumiConfig.get("githubScope"),
// (Optional) Port number of the target group if not specified use port 80
targetGroupPort : pulumiConfig.getNumber("targetGroupPort")
}
Expand Down Expand Up @@ -141,6 +144,9 @@ const sessionSecretRandomString = new random.RandomPassword("random", {
length: 32,
}, { additionalSecretOutputs: ["result"] });


let inputGithubScope: pulumi.Input<string> = cmsStackConfig.githubScope!;

// Create a Fargate service task that can scale out.
const appService = new awsx.ecs.FargateService("app-svc", {
cluster,
Expand Down Expand Up @@ -170,7 +176,11 @@ const appService = new awsx.ecs.FargateService("app-svc", {
{
name: "TARGET_PORT",
value: pulumi.interpolate `${inputTargetGroupPort}`
}
},
{
name: "GITHUB_SCOPE",
value: inputGithubScope
},
]
},
},
Expand Down
52 changes: 39 additions & 13 deletions aws-ts-netlify-cms-and-oauth/cms-oauth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"os"
"strings"

"github.com/gorilla/pat"
"github.com/markbates/goth"
Expand Down Expand Up @@ -124,19 +125,38 @@ func init() {
fmt.Sprintf("%s/callback/gitlab", host),
)
}
goth.UseProviders(
github.New(
os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"),
// concatenate with the host name
fmt.Sprintf("%s/callback/github", host),
"public_repo",
),
bitbucket.New(
os.Getenv("BITBUCKET_KEY"), os.Getenv("BITBUCKET_SECRET"),
fmt.Sprintf("%s/callback//bitbucket", host),
),
gitlabProvider,
)

githubScope := os.Getenv("GITHUB_SCOPE")
if githubScope == "" {
goth.UseProviders(
github.New(
os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"),
// concatenate with the host name
fmt.Sprintf("%s/callback/github", host),
"public_repo",
),
bitbucket.New(
os.Getenv("BITBUCKET_KEY"), os.Getenv("BITBUCKET_SECRET"),
fmt.Sprintf("%s/callback//bitbucket", host),
),
gitlabProvider,
)
} else {
scopeArray := strings.Split(githubScope, ",")
goth.UseProviders(
github.New(
os.Getenv("GITHUB_KEY"), os.Getenv("GITHUB_SECRET"),
// concatenate with the host name
fmt.Sprintf("%s/callback/github", host),
scopeArray...,
),
bitbucket.New(
os.Getenv("BITBUCKET_KEY"), os.Getenv("BITBUCKET_SECRET"),
fmt.Sprintf("%s/callback//bitbucket", host),
),
gitlabProvider,
)
}
}

func main() {
Expand All @@ -151,9 +171,15 @@ func main() {
//
http.Handle("/", router)
//
// if TARGET_PORT is unset or do not present then set it to be port 80
targetGroupPort := os.Getenv("TARGET_PORT")
if targetGroupPort == "" {
targetGroupPort = "80"
}
listenPort := ":" + targetGroupPort
fmt.Print("Started running on", listenPort, "\n")
// listen on port 80 where we created the target group
fmt.Println(http.ListenAndServe(listenPort, nil))
}

}
2 changes: 1 addition & 1 deletion aws-ts-netlify-cms-and-oauth/cms/public/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
backend:
name: github
# Replace this with the Github repo you want to make change
repo: your-github-repo
repo: github-username/target-github-repo
# This site_domain and base_url are sudo domains
# Replace site_domain with targetDomain pulumi stack configuration inside cms/infrastructure folder
# Replace base_url with targetDomain pulumi stack configuration inside cms-oauth/infrastructure folder
Expand Down

0 comments on commit 35af133

Please sign in to comment.