Skip to content

Commit

Permalink
Add docker configs
Browse files Browse the repository at this point in the history
  • Loading branch information
shellbear committed Sep 9, 2019
1 parent ec7d80c commit bcac758
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.git
.gitignore
.github
.goreleaser.yml

vendor
epical
dist
token.json
credentials.json
README.md
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM golang:latest

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN go build -o main .

CMD ["./main"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ Delete all events previously created by EpiCal.

#### Credentials

You can specify the Google Calendar API `credentials.json` file path using the `--credentials` or `-c` option.
You can specify the Google Calendar API folder path containing `credentials.json` and `token.json` files using the `--credentials` or `-c` option.

```bash
./epical --token YOUR_EPITECH_AUTOLOGIN_TOKEN --credentials ~/credentials.json sync
./epical --token YOUR_EPITECH_AUTOLOGIN_TOKEN --credentials /run/secrets/ sync
```
4 changes: 1 addition & 3 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var cli = &cobra.Command{
}

func Execute() {
cli.PersistentFlags().StringVarP(&Credentials, "credentials", "c", "credentials.json", "Google API credentials")
cli.PersistentFlags().StringVarP(&Credentials, "credentials", "c", "./", "Google API credentials folder")

if err := cli.Execute(); err != nil {
fmt.Println(err)
Expand All @@ -30,8 +30,6 @@ func Execute() {
func init() {
listCmd.PersistentFlags().StringVarP(&EpitechToken, "token", "t", "", "Epitech API Token")
listCmd.MarkPersistentFlagRequired("token")
syncCmd.PersistentFlags().StringVarP(&EpitechToken, "token", "t", "", "Epitech API Token")
syncCmd.MarkPersistentFlagRequired("token")

cli.AddCommand(versionCmd)
cli.AddCommand(clearCmd)
Expand Down
9 changes: 5 additions & 4 deletions pkg/epical/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"net/http"
"os"
"path"
"strings"
"time"

Expand Down Expand Up @@ -39,11 +40,11 @@ func getTokenFromWeb(config *oauth2.Config) *oauth2.Token {
return tok
}

func getClient(config *oauth2.Config) *http.Client {
func getClient(config *oauth2.Config, credentialsPath string) *http.Client {
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
tokFile := "token.json"
tokFile := path.Join(credentialsPath, "token.json")
tok, err := tokenFromFile(tokFile)
if err != nil {
tok = getTokenFromWeb(config)
Expand Down Expand Up @@ -191,7 +192,7 @@ func NewGoogleCalendarEvent(event *EpitechEvent) (*calendar.Event, error) {
}

func GetGoogleCalendarService(credentialsPath string) (*calendar.Service, error) {
b, err := ioutil.ReadFile(credentialsPath)
b, err := ioutil.ReadFile(path.Join(credentialsPath, "credentials.json"))
if err != nil {
log.Fatalf("Unable to read client secret file: %v", err)
}
Expand All @@ -202,7 +203,7 @@ func GetGoogleCalendarService(credentialsPath string) (*calendar.Service, error)
log.Fatalf("Unable to parse client secret file to config: %v", err)
}

client := getClient(config)
client := getClient(config, credentialsPath)
calendarService, err := calendar.NewService(context.Background(), option.WithHTTPClient(client))

return calendarService, err
Expand Down

0 comments on commit bcac758

Please sign in to comment.