Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord integration #3

Merged
merged 13 commits into from
Feb 13, 2024
Merged
33 changes: 33 additions & 0 deletions .github/workflows/release_staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Deploy to Azure Staging

on:
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Download artifact
uses: dawidd6/action-download-artifact@v3
with:
workflow: build.yml
name: build-artifact
path: ./deploy

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "16"

- name: Deploy to Azure App Service
uses: azure/webapps-deploy@v2
with:
app-name: auroria-test-faucet # Replace with your Azure App Service name
slot-name: staging
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE_STAGING }} # Azure publish profile secret
package: ./deploy # Path to the downloaded artifact
18 changes: 14 additions & 4 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ var (
versionFlag = flag.Bool("version", false, "Print version number")

//payoutFlag = flag.Int("faucet_amount", 10000, "Number of Ethers to transfer per user request")
intervalFlag = flag.Int("faucet_minutes", 1440, "Number of minutes to wait between funding rounds")
netnameFlag = flag.String("faucet_name", os.Getenv("FAUCET_NAME"), "Network name to display on the frontend")
symbolFlag = flag.String("faucet_symbol", os.Getenv("FAUCET_SYMBOL"), "Token symbol to display on the frontend")
//intervalFlag = flag.Int("faucet_minutes", os.Getenv("FAUCET_MINUTES"), "Number of minutes to wait between funding rounds")
netnameFlag = flag.String("faucet_name", os.Getenv("FAUCET_NAME"), "Network name to display on the frontend")
symbolFlag = flag.String("faucet_symbol", os.Getenv("FAUCET_SYMBOL"), "Token symbol to display on the frontend")

keyJSONFlag = flag.String("wallet_keyjson", os.Getenv("KEYSTORE"), "Keystore file to fund user requests with")
keyPassFlag = flag.String("wallet_keypass", "password.txt", "Passphrase text file to decrypt keystore")
Expand All @@ -37,6 +37,10 @@ var (

hcaptchaSiteKeyFlag = flag.String("hcaptcha_sitekey", os.Getenv("HCAPTCHA_SITEKEY"), "hCaptcha sitekey")
hcaptchaSecretFlag = flag.String("hcaptcha_secret", os.Getenv("HCAPTCHA_SECRET"), "hCaptcha secret")

discordClientId = flag.String("discord_client_id", os.Getenv("DISCORD_CLIENTID"), "Discord client id for oauth2")
discordClientSecret = flag.String("discord_client_secret", os.Getenv("DISCORD_CLIENTSECRET"), "Discord client secret for oauth2")
discordRedirectUrl = flag.String("discord_redirect_url", os.Getenv("DISCORD_REDIRECTURL"), "Discord redirect url for oauth2")
)

func init() {
Expand Down Expand Up @@ -68,13 +72,19 @@ func Execute() {
}
httpPortFlag := flag.Int("httpport", port, "Listener port to serve HTTP connection")

interval, err := strconv.Atoi(os.Getenv("FAUCET_MINUTES"))
if err != nil {
interval = 1440
}
intervalFlag := flag.Int("faucet_minutes", interval, "Number of minutes to wait between funding rounds")

faucetAmount, err := strconv.Atoi(os.Getenv("FAUCET_AMOUNT"))
if err != nil {
faucetAmount = 10000
}
payoutFlag := flag.Int("faucet.amount", faucetAmount, "Number of Ethers to transfer per user request")

config := server.NewConfig(*netnameFlag, *symbolFlag, *httpPortFlag, *intervalFlag, *payoutFlag, *proxyCntFlag, *hcaptchaSiteKeyFlag, *hcaptchaSecretFlag)
config := server.NewConfig(*netnameFlag, *symbolFlag, *httpPortFlag, *intervalFlag, *payoutFlag, *proxyCntFlag, *hcaptchaSiteKeyFlag, *hcaptchaSecretFlag, *discordClientId, *discordClientSecret, *discordRedirectUrl)
go server.NewServer(txBuilder, config).Run()

c := make(chan os.Signal, 1)
Expand Down
40 changes: 23 additions & 17 deletions internal/server/config.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
package server

type Config struct {
network string
symbol string
httpPort int
interval int
payout int
proxyCount int
hcaptchaSiteKey string
hcaptchaSecret string
network string
symbol string
httpPort int
interval int
payout int
proxyCount int
hcaptchaSiteKey string
hcaptchaSecret string
discordClientId string
discordClientSecret string
discordRedirectUrl string
}

func NewConfig(network, symbol string, httpPort, interval, payout, proxyCount int, hcaptchaSiteKey, hcaptchaSecret string) *Config {
func NewConfig(network, symbol string, httpPort, interval, payout, proxyCount int, hcaptchaSiteKey, hcaptchaSecret, discordClientId, discordClientSecret, discordRedirectUrl string) *Config {
return &Config{
network: network,
symbol: symbol,
httpPort: httpPort,
interval: interval,
payout: payout,
proxyCount: proxyCount,
hcaptchaSiteKey: hcaptchaSiteKey,
hcaptchaSecret: hcaptchaSecret,
network: network,
symbol: symbol,
httpPort: httpPort,
interval: interval,
payout: payout,
proxyCount: proxyCount,
hcaptchaSiteKey: hcaptchaSiteKey,
hcaptchaSecret: hcaptchaSecret,
discordClientId: discordClientId,
discordClientSecret: discordClientSecret,
discordRedirectUrl: discordRedirectUrl,
}
}
40 changes: 40 additions & 0 deletions internal/server/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,38 @@ type claimRequest struct {
Address string `json:"address"`
}

type loginRequest struct {
Code string `json:"code"`
}

type claimResponse struct {
Message string `json:"msg"`
}

type loginResponse struct {
Message string `json:"msg"`
}

type discordTokenResponse struct {
AccessToken string `json:"access_token"`
Error string `json:"error"`
ErrorDesc string `json:"error_description"`
}

type infoResponse struct {
Account string `json:"account"`
Network string `json:"network"`
Payout string `json:"payout"`
Symbol string `json:"symbol"`
HcaptchaSiteKey string `json:"hcaptcha_sitekey,omitempty"`
RemoteAddr string `json:"remote_addr,omitempty"`
Forward string `json:"forward,omitempty"`
RealIP string `json:"real_ip,omitempty"`
DiscorClientId string `json:"discord_client_id"`
}

type authResponse struct {
Token string `json:"token"`
}

type malformedRequest struct {
Expand Down Expand Up @@ -92,6 +114,24 @@ func readAddress(r *http.Request) (string, error) {
return claimReq.Address, nil
}

func readCode(r *http.Request) (string, error) {
var loginReq loginRequest
if err := decodeJSONBody(r, &loginReq); err != nil {
return "", err
}

return loginReq.Code, nil
}

func readToken(r *http.Request) (string, error) {
var discordRes discordTokenResponse
if err := decodeJSONBody(r, &discordRes); err != nil {
return "", err
}

return discordRes.AccessToken, nil
}

func renderJSON(w http.ResponseWriter, v interface{}, code int) error {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
Expand Down
Loading
Loading