Skip to content

Commit

Permalink
Merge pull request #9 from y0rune/add-opsgenie-api-key
Browse files Browse the repository at this point in the history
Added `OPSGENIE_API_KEY` from env
  • Loading branch information
y0rune authored Oct 31, 2022
2 parents 88d2a11 + 128bc51 commit 9abc0fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ go get

```
-apiKey string
# ApiKey for use in that script
# ApiKey for use in that script.
# You can use the export OPSGENIE_API_KEY="XXXXXXXXXXXXXXX"
-delete
# Delete schedule
-scheduleEnabledFlag
Expand All @@ -38,7 +39,14 @@ go get
### How to use it in the console?

```bash
go run main.go --apiKey XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX --scheduleTeam TestTeam --scheduleName "YEAR_2023" --scheduleYear 2023
export OPSGENIE_API_KEY="XXXXXXXXXXXXXXX"
go run main.go --scheduleTeam TestTeam --scheduleName "YEAR_2023" --scheduleYear 2023
```

Alternative use:

```bash
go run main.go --apiKey XXXXXXXXXXXXXXX --scheduleTeam TestTeam --scheduleName "YEAR_2023" --scheduleYear 2023
```

### Output console
Expand Down
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ var defaultSchedule = [...]og.Restriction{
}

func createApi(apiKey string) *schedule.Client {
if apiKey == "" {
fmt.Printf("Empty apiKey... Please use -apiKey \n")
apiKeyEnv := os.Getenv("OPSGENIE_API_KEY")

if apiKeyEnv != "" {
apiKey = apiKeyEnv
} else if apiKey == "" {
fmt.Printf("Empty apiKey...\nPlease use -apiKey or export OPSGENIE_API_KEY=\"XXXXXXXXXXXXXXX\" \n")
os.Exit(1)
}

Expand Down Expand Up @@ -183,7 +187,7 @@ func getListRotation(scheduleClient schedule.Client, scheduleID string) *schedul
}

func main() {
apiKey := flag.String("apiKey", "", "# ApiKey for use in that script")
apiKey := flag.String("apiKey", "", "# ApiKey for use in that script.\n# You can use the export OPSGENIE_API_KEY=\"XXXXXXXXXXXXXXX\"")
scheduleName := flag.String("scheduleName", staticScheduleName, "# Name of schedule")
scheduleID := flag.String("scheduleID", staticScheduleID, "# ID of schedule")
scheduleTimezone := flag.String("scheduleTimezone", staticScheduleTimezone, "# Timezone of the schedule")
Expand Down

0 comments on commit 9abc0fb

Please sign in to comment.