Skip to content

Commit

Permalink
Merge pull request #2 from int-tt/feature/private-channel
Browse files Browse the repository at this point in the history
Feature/private channel
  • Loading branch information
int-tt committed Dec 17, 2021
1 parent b8e764f commit 27de1eb
Show file tree
Hide file tree
Showing 130 changed files with 4,880 additions and 1,909 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ build:
go build -v

install: build
mkdir -p ~/.terraform.d/plugins/
mv terraform-provider-slack ~/.terraform.d/plugins/
mkdir -p ~/.terraform.d/plugins/local/default/slack/0.0.2/darwin_arm64/
mv terraform-provider-slack ~/.terraform.d/plugins/local/default/slack/0.0.2/darwin_arm64/terraform-provider-slack

test:
go test $(TEST) -timeout=30s -parallel=4 -v
Expand All @@ -26,4 +26,4 @@ tools:

vendor:
GO111MODULE=on go mod vendor
.PHONY: build install test testacc fmt fmtcheck tools vendor
.PHONY: build install test testacc fmt fmtcheck tools vendor
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ require (
github.com/bflad/tfproviderlint v0.5.0 // indirect
github.com/golangci/golangci-lint v1.19.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1
github.com/hashicorp/terraform v0.12.9
github.com/hashicorp/terraform v0.12.9 // indirect
github.com/hashicorp/terraform-plugin-sdk v1.1.1
github.com/nlopes/slack v0.6.0
github.com/nlopes/slack v0.6.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/slack-go/slack v0.8.1
)
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/go-toolsmith/astcast v1.0.0 h1:JojxlmI6STnFVG9yOImLeGREv8W2ocNUM+iOhR6jE7g=
github.com/go-toolsmith/astcast v1.0.0/go.mod h1:mt2OdQTeAQcY4DQgPSArJjHCcOwlX+Wl/kwN+LbLGQ4=
github.com/go-toolsmith/astcopy v1.0.0 h1:OMgl1b1MEpjFQ1m5ztEO06rz5CUd3oBv9RF7+DyvdG8=
Expand Down Expand Up @@ -196,6 +197,8 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORR
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3 h1:JVnpOZS+qxli+rgVl98ILOXVNbW+kb5wcxeGx8ShUIw=
github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
Expand Down Expand Up @@ -380,6 +383,8 @@ github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
Expand Down Expand Up @@ -414,6 +419,8 @@ github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOms
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/slack-go/slack v0.8.1 h1:NqGXuzni8Is3EJWmsuMuBiCCPbWOlBgTKPvdlwS3Huk=
github.com/slack-go/slack v0.8.1/go.mod h1:FGqNzJBmxIsZURAxh2a8D21AnOVvvXZvGligs4npPUM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down
2 changes: 1 addition & 1 deletion slack/data_source_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package slack
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
slackapi "github.com/nlopes/slack"
slackapi "github.com/slack-go/slack"
)

func dataSourceUser() *schema.Resource {
Expand Down
7 changes: 4 additions & 3 deletions slack/data_source_user_with_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package slack
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
slackapi "github.com/nlopes/slack"
slackapi "github.com/slack-go/slack"
)

func dataSourceUserWithEmail() *schema.Resource {
Expand Down Expand Up @@ -31,9 +31,10 @@ func dataSourceUserWithEmail() *schema.Resource {
}

func dataSourceUserWithEmailRead(d *schema.ResourceData, meta interface{}) error {
user, err := meta.(*slackapi.Client).GetUserByEmail(d.Get("email").(string))
userEmail := d.Get("email").(string)
user, err := meta.(*slackapi.Client).GetUserByEmail(userEmail)
if err != nil {
return fmt.Errorf("faild to get user: %s", err.Error())
return fmt.Errorf("faild to get user(%s): %s", userEmail, err.Error())
}
if err = setUserInfo(d, user); err != nil {
return fmt.Errorf("faild to set user info:%s", err.Error())
Expand Down
3 changes: 2 additions & 1 deletion slack/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/logging"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
slackapi "github.com/nlopes/slack"
slackapi "github.com/slack-go/slack"
)

//Provider is the root of terraform provider plugin
Expand All @@ -23,6 +23,7 @@ func Provider() terraform.ResourceProvider {
ResourcesMap: map[string]*schema.Resource{
"slack_channel": resourceChannel(),
"slack_channel_invite": resourceChannelInvite(),
"slack_send_message": resourceSendMessage(),
},
DataSourcesMap: map[string]*schema.Resource{
"slack_user": dataSourceUser(),
Expand Down
22 changes: 15 additions & 7 deletions slack/resource_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package slack

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
slackapi "github.com/nlopes/slack"
slackapi "github.com/slack-go/slack"
)

func resourceChannel() *schema.Resource {
Expand All @@ -21,22 +22,29 @@ func resourceChannel() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"private": {
Type: schema.TypeBool,
Default: false,
Optional: true,
},
},
}
}

func resourceChannelCreate(d *schema.ResourceData, meta interface{}) error {
channel, err := meta.(*slackapi.Client).CreateChannel(d.Get("name").(string))
isPrivate := d.Get("private").(bool)
channelName := d.Get("name").(string)
channel, err := meta.(*slackapi.Client).CreateConversation(channelName, isPrivate)
if err != nil {
return fmt.Errorf("failed to create channel: %s", err.Error())
return fmt.Errorf("failed to create channel(%s): %s", channelName, err.Error())
}
d.SetId(channel.ID)

return resourceChannelRead(d, meta)
}

func resourceChannelRead(d *schema.ResourceData, meta interface{}) error {
channel, err := meta.(*slackapi.Client).GetChannelInfo(d.Id())
channel, err := meta.(*slackapi.Client).GetConversationInfo(d.Id(), false)
if err != nil {
return fmt.Errorf("failed to read channel: %s", err.Error())
}
Expand All @@ -49,15 +57,15 @@ func resourceChannelRead(d *schema.ResourceData, meta interface{}) error {
}

func resourceChannelUpdate(d *schema.ResourceData, meta interface{}) error {
if _, err := meta.(*slackapi.Client).RenameChannel(d.Id(), d.Get("name").(string)); err != nil {
return fmt.Errorf("faild to update channel: %s", err.Error())
if _, err := meta.(*slackapi.Client).RenameConversation(d.Id(), d.Get("name").(string)); err != nil {
return fmt.Errorf("failed to update channel: %s", err.Error())
}

return resourceChannelRead(d, meta)
}

func resourceChannelDelete(d *schema.ResourceData, meta interface{}) error {
if err := meta.(*slackapi.Client).ArchiveChannel(d.Id()); err != nil {
if err := meta.(*slackapi.Client).ArchiveConversation(d.Id()); err != nil {
return fmt.Errorf("failed to archive channel: %s", err.Error())
}
return nil
Expand Down
9 changes: 5 additions & 4 deletions slack/resource_channel_invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package slack

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
slack "github.com/nlopes/slack"
slack "github.com/slack-go/slack"
)

func resourceChannelInvite() *schema.Resource {
Expand Down Expand Up @@ -32,7 +33,7 @@ func resourceChannelInvite() *schema.Resource {

func resourceChannelInviteCreate(d *schema.ResourceData, meta interface{}) error {
channelID, userID := getUserAndChannelID(d)
_, err := meta.(*slack.Client).InviteUserToChannel(channelID, userID)
_, err := meta.(*slack.Client).InviteUsersToConversation(channelID, userID)
if err != nil {
return fmt.Errorf("faild to invite user to channel:%s", err.Error())
}
Expand All @@ -41,7 +42,7 @@ func resourceChannelInviteCreate(d *schema.ResourceData, meta interface{}) error

func resourceChannelInviteRead(d *schema.ResourceData, meta interface{}) error {
channelID, userID := getUserAndChannelID(d)
channel, err := meta.(*slack.Client).GetChannelInfo(channelID)
channel, err := meta.(*slack.Client).GetConversationInfo(channelID, false)
if err != nil {
return fmt.Errorf("failed to read channel:%s", err.Error())
}
Expand All @@ -63,7 +64,7 @@ func resourceChannelInviteUpdate(d *schema.ResourceData, meta interface{}) error

func resourceChannelInviteDelete(d *schema.ResourceData, meta interface{}) error {
channelID, userID := getUserAndChannelID(d)
err := meta.(*slack.Client).KickUserFromChannel(channelID, userID)
err := meta.(*slack.Client).KickUserFromConversation(channelID, userID)
if err != nil {
return fmt.Errorf("failed to kick user to channel:%s", err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions slack/resource_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"testing"

slackapi "github.com/nlopes/slack"
slackapi "github.com/slack-go/slack"
)

func TestAccSlackChannel_Basic(t *testing.T) {
Expand Down Expand Up @@ -54,7 +54,7 @@ func testAccCheckChannelDestroy(s *terraform.State) error {
continue
}
config := testAccProvider.Meta().(*slackapi.Client)
channel, err := config.GetChannelInfo(rs.Primary.ID)
channel, err := config.GetConversationInfo(rs.Primary.ID, false)
if err != nil {
return err
}
Expand Down
56 changes: 56 additions & 0 deletions slack/resource_send_message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package slack

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"

slackapi "github.com/slack-go/slack"
)

func resourceSendMessage() *schema.Resource {
return &schema.Resource{
Create: resourceSendMessageCreate,
Read: resourceChannelRead,
Update: resourceChannelUpdate,
Delete: resourceChannelDelete,
Schema: map[string]*schema.Schema{
"channel_id": {
Type: schema.TypeString,
Required: true,
},
"text": {
Type: schema.TypeString,
Required: true,
},
"timestamp": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func resourceSendMessageCreate(d *schema.ResourceData, meta interface{}) error {
// https://github.com/nlopes/slack/blob/v0.6.0/chat.go#L283
channel, timestamp, _, err := meta.(*slackapi.Client).SendMessage(
d.Get("channel_id").(string), slackapi.MsgOptionText(d.Get("text").(string), false),
)
if err != nil {
return fmt.Errorf("failed to send message: %s", err.Error())
}
d.SetId(fmt.Sprintf("%s:%s", channel, timestamp))
d.Set("timestamp", timestamp)

return resourceSendMessageRead(d, meta)
}

func resourceSendMessageRead(d *schema.ResourceData, meta interface{}) error {
return nil
}
func resourceSendMessageUpdate(d *schema.ResourceData, meta interface{}) error {
return nil
}
func resourceSendMessageDelete(d *schema.ResourceData, meta interface{}) error {
return nil
}
2 changes: 1 addition & 1 deletion slack/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package slack

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
slackapi "github.com/nlopes/slack"
slackapi "github.com/slack-go/slack"
)

func setUserInfo(d *schema.ResourceData, user *slackapi.User) error {
Expand Down
19 changes: 0 additions & 19 deletions vendor/github.com/gorilla/websocket/.travis.yml

This file was deleted.

12 changes: 6 additions & 6 deletions vendor/github.com/gorilla/websocket/README.md

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

4 changes: 2 additions & 2 deletions vendor/github.com/gorilla/websocket/client.go

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

Loading

0 comments on commit 27de1eb

Please sign in to comment.