-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Authenticate Incoming HTTP Requests (#3)
* authenticate incoming HTTP requests * gofmt * polish
- Loading branch information
Showing
6 changed files
with
111 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
PORT=XXXX | ||
# GitHub Config | ||
PERSONAL_ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
ORG_NAME=Portchain | ||
USER_NAME=utkuufuk | ||
SUBSCRIBED_REPOS=entrello,github-service | ||
|
||
# Server Config | ||
PORT=XXXX | ||
SECRET=xxxxxxxxxxxxxxxxxxxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,63 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/joho/godotenv" | ||
"github.com/utkuufuk/github-service/internal/logger" | ||
) | ||
|
||
var ( | ||
Port int | ||
PersonalAccessToken string | ||
type GitHubConfig struct { | ||
OrgName string | ||
UserName string | ||
PersonalAccessToken string | ||
SubscribedRepos []string | ||
) | ||
UserName string | ||
} | ||
|
||
type Config struct { | ||
// GitHub config | ||
GitHub GitHubConfig | ||
|
||
// additional server mode config | ||
Port int | ||
Secret string | ||
} | ||
|
||
func init() { | ||
var err error | ||
func ParseGitHubConfig() (cfg GitHubConfig, err error) { | ||
godotenv.Load() | ||
|
||
port := os.Getenv("PORT") | ||
Port, err = strconv.Atoi(port) | ||
if err != nil { | ||
logger.Error("PORT not set") | ||
os.Exit(1) | ||
cfg.PersonalAccessToken = os.Getenv("PERSONAL_ACCESS_TOKEN") | ||
if cfg.PersonalAccessToken == "" { | ||
return cfg, fmt.Errorf("PERSONAL_ACCESS_TOKEN not set") | ||
} | ||
|
||
PersonalAccessToken = os.Getenv("PERSONAL_ACCESS_TOKEN") | ||
if PersonalAccessToken == "" { | ||
logger.Error("PERSONAL_ACCESS_TOKEN not set") | ||
os.Exit(1) | ||
cfg.OrgName = os.Getenv("ORG_NAME") | ||
if cfg.OrgName == "" { | ||
return cfg, fmt.Errorf("ORG_NAME not set") | ||
} | ||
|
||
OrgName = os.Getenv("ORG_NAME") | ||
if OrgName == "" { | ||
logger.Error("ORG_NAME not set") | ||
os.Exit(1) | ||
cfg.UserName = os.Getenv("USER_NAME") | ||
if cfg.UserName == "" { | ||
return cfg, fmt.Errorf("USER_NAME not set") | ||
} | ||
|
||
UserName = os.Getenv("USER_NAME") | ||
if UserName == "" { | ||
logger.Error("USER_NAME not set") | ||
os.Exit(1) | ||
cfg.SubscribedRepos = strings.Split(os.Getenv("SUBSCRIBED_REPOS"), ",") | ||
|
||
return cfg, nil | ||
} | ||
|
||
func ParseServerConfig() (cfg Config, err error) { | ||
ghCfg, err := ParseGitHubConfig() | ||
cfg.GitHub = ghCfg | ||
|
||
port := os.Getenv("PORT") | ||
cfg.Port, err = strconv.Atoi(port) | ||
if err != nil { | ||
return cfg, fmt.Errorf("PORT not set") | ||
} | ||
|
||
SubscribedRepos = strings.Split(os.Getenv("SUBSCRIBED_REPOS"), ",") | ||
cfg.Secret = os.Getenv("SECRET") | ||
return cfg, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters