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

Migrate to golang modules, add some new features #8

Merged
merged 4 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
63 changes: 63 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
TEST?=$$(go list ./... |grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=opsgenie

default: build

build: fmtcheck
go install

test: fmtcheck
go test -i $(TEST) || exit 1
echo $(TEST) | \
xargs -t -n4 go test $(TESTARGS) -timeout=30s -parallel=4

testacc: fmtcheck
TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout 120m

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
echo ""; \
echo "Vet found suspicious constructs. Please check the reported constructs"; \
echo "and fix them if necessary before submitting the code for review."; \
exit 1; \
fi

fmt:
gofmt -w $(GOFMT_FILES)

fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

errcheck:
@sh -c "'$(CURDIR)/scripts/errcheck.sh'"

vendor-status:
@govendor status

test-compile:
@if [ "$(TEST)" = "./..." ]; then \
echo "ERROR: Set TEST to a specific package. For example,"; \
echo " make test-compile TEST=./$(PKG_NAME)"; \
exit 1; \
fi
go test -c $(TEST) $(TESTARGS)

website:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

website-test:
ifeq (,$(wildcard $(GOPATH)/src/$(WEBSITE_REPO)))
echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test

62 changes: 62 additions & 0 deletions datasource_user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/schema"
"github.com/timdurward/slack"
)

func dataSourceSlackUser() *schema.Resource {
return &schema.Resource{
Read: dataSourceSlackUserRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"real_name": {
Type: schema.TypeString,
Optional: true,
},
"display_name": {
Type: schema.TypeString,
Optional: true,
},
"email": {
Type: schema.TypeString,
Required: true,
},
},
}
}

func dataSourceSlackUserRead(d *schema.ResourceData, meta interface{}) error {
api := slack.New(meta.(*Config).APIToken)

email := d.Get("email").(string)
log.Printf("[INFO] Reading Slack user '%s'", email)
// user, err := api.GetUserByEmail(email)
// if err != nil {
// return fmt.Errorf("Invalid user with email '%s'", email)
// }

users, err := api.GetUsers()
if err != nil {
return err
}
for _, user := range users {
if user.Profile.Email == email {
log.Printf("[DEBUG] Slack user: %v", user)
d.SetId(user.ID)
d.Set("name", user.Name)
d.Set("real_name", user.RealName)
d.Set("email", user.Profile.Email)
return nil
}
}

return fmt.Errorf("Invalid user with email '%s'", email)
}
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/TimDurward/terraform-provider-slack

go 1.12

require (
github.com/hashicorp/terraform v0.12.0
github.com/timdurward/slack v0.1.1-0.20180526230822-e450e1c3c16a
)
391 changes: 391 additions & 0 deletions go.sum

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions resource_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,20 @@ func resourceChannelRead(d *schema.ResourceData, meta interface{}) error {
}

func resourceChannelUpdate(d *schema.ResourceData, meta interface{}) error {
api := slack.New(meta.(*Config).APIToken)

name := d.Get("channel_name").(string)
if _, err := api.RenameChannel(d.Id(), name); err != nil {
return err
}
return nil
}

func resourceChannelDelete(d *schema.ResourceData, meta interface{}) error {
api := slack.New(meta.(*Config).APIToken)

// Deletes Slack Channel and clears state
_, err := api.DeleteChannel(d.Id())
if err != nil {
if _, err := api.DeleteChannel(d.Id()); err != nil {
return err
}

Expand Down
31 changes: 31 additions & 0 deletions scripts/changelog-links.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# This script rewrites [GH-nnnn]-style references in the CHANGELOG.md file to
# be Markdown links to the given github issues.
#
# This is run during releases so that the issue references in all of the
# released items are presented as clickable links, but we can just use the
# easy [GH-nnnn] shorthand for quickly adding items to the "Unrelease" section
# while merging things between releases.

set -e

if [[ ! -f CHANGELOG.md ]]; then
echo "ERROR: CHANGELOG.md not found in pwd."
echo "Please run this from the root of the terraform provider repository"
exit 1
fi

if [[ `uname` == "Darwin" ]]; then
echo "Using BSD sed"
SED="sed -i.bak -E -e"
else
echo "Using GNU sed"
SED="sed -i.bak -r -e"
fi

PROVIDER_URL="https:\/\/github.com\/terraform-providers\/terraform-provider-opsgenie\/issues"

$SED "s/GH-([0-9]+)/\[#\1\]\($PROVIDER_URL\/\1\)/g" -e 's/\[\[#(.+)([0-9])\)]$/(\[#\1\2))/g' CHANGELOG.md

rm CHANGELOG.md.bak
2 changes: 1 addition & 1 deletion scripts/errcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ if [[ -n ${err_files} ]]; then
exit 1
fi

exit 0
exit 0
2 changes: 1 addition & 1 deletion scripts/gofmtcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ if [[ -n ${gofmt_files} ]]; then
exit 1
fi

exit 0
exit 0
10 changes: 10 additions & 0 deletions scripts/gogetcookie.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

touch ~/.gitcookies
chmod 0600 ~/.gitcookies

git config --global http.cookiefile ~/.gitcookies

tr , \\t <<\__END__ >>~/.gitcookies
.googlesource.com,TRUE,/,TRUE,2147483647,o,git-paul.hashicorp.com=1/z7s05EYPudQ9qoe6dMVfmAVwgZopEkZBb1a2mA5QtHE
__END__
15 changes: 15 additions & 0 deletions vendor/cloud.google.com/go/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions vendor/cloud.google.com/go/CONTRIBUTORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading