Skip to content

Commit

Permalink
feat: support tencentcloud sms component (#1001)
Browse files Browse the repository at this point in the history
Co-authored-by: Marco <[email protected]>
  • Loading branch information
alilestera and zhenjunMa authored Nov 8, 2023
1 parent fe66f40 commit f5a5957
Show file tree
Hide file tree
Showing 17 changed files with 674 additions and 22 deletions.
7 changes: 7 additions & 0 deletions cmd/layotto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strconv"
"time"

"mosn.io/layotto/components/sms"

"mosn.io/layotto/components/cryption"

"mosn.io/layotto/components/email"
Expand All @@ -46,6 +48,7 @@ import (
aliyun_file "mosn.io/layotto/components/file/aliyun"

aliyun_email "mosn.io/layotto/components/email/aliyun"
tencentcloud_sms "mosn.io/layotto/components/sms/tencentcloud"

"github.com/dapr/components-contrib/secretstores"
"github.com/dapr/components-contrib/secretstores/aws/parameterstore"
Expand Down Expand Up @@ -320,6 +323,10 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
runtime.WithEmailServiceFactory(
email.NewFactory("aliyun.email", aliyun_email.NewAliyunEmail),
),
// Sms
runtime.WithSmsServiceFactory(
sms.NewFactory("tencentcloud.sms", tencentcloud_sms.NewSms),
),
// PubSub
runtime.WithPubSubFactory(
pubsub.NewFactory("redis", func() dapr_comp_pubsub.PubSub {
Expand Down
7 changes: 7 additions & 0 deletions cmd/layotto_multiple_api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import (
"strconv"
"time"

"mosn.io/layotto/components/sms"

"mosn.io/layotto/components/cryption"
aliyun_cryption "mosn.io/layotto/components/cryption/aliyun"
aws_cryption "mosn.io/layotto/components/cryption/aws"
tencentcloud_sms "mosn.io/layotto/components/sms/tencentcloud"

"mosn.io/layotto/pkg/grpc/lifecycle"

Expand Down Expand Up @@ -424,6 +427,10 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
cryption.NewFactory("aliyun.kms", aliyun_cryption.NewCryption),
cryption.NewFactory("aws.kms", aws_cryption.NewCryption),
),
// Sms
runtime.WithSmsServiceFactory(
sms.NewFactory("tencentcloud.sms", tencentcloud_sms.NewSms),
),
// Lock
runtime.WithLockFactory(
runtime_lock.NewFactory("redis_cluster", func() lock.LockStore {
Expand Down
7 changes: 7 additions & 0 deletions cmd/layotto_without_xds/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ import (
"strconv"
"time"

"mosn.io/layotto/components/sms"

"mosn.io/layotto/components/cryption"
aliyun_cryption "mosn.io/layotto/components/cryption/aliyun"
aws_cryption "mosn.io/layotto/components/cryption/aws"
tencentcloud_sms "mosn.io/layotto/components/sms/tencentcloud"

"mosn.io/layotto/pkg/grpc/lifecycle"

Expand Down Expand Up @@ -428,6 +431,10 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
cryption.NewFactory("aliyun.kms", aliyun_cryption.NewCryption),
cryption.NewFactory("aws.kms", aws_cryption.NewCryption),
),
// Sms
runtime.WithSmsServiceFactory(
sms.NewFactory("tencentcloud.sms", tencentcloud_sms.NewSms),
),
// Sequencer
runtime.WithSequencerFactory(
runtime_sequencer.NewFactory("etcd", func() sequencer.Store {
Expand Down
2 changes: 2 additions & 0 deletions components/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ require (
github.com/pkg/errors v0.9.1
github.com/qiniu/go-sdk/v7 v7.11.1
github.com/stretchr/testify v1.8.0
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.759
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.759
github.com/tencentyun/cos-go-sdk-v5 v0.7.33
github.com/valyala/fasthttp v1.40.0
go.beyondstorage.io/services/hdfs v0.3.0
Expand Down
4 changes: 4 additions & 0 deletions components/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,11 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69
github.com/supplyon/gremcos v0.1.0/go.mod h1:ZnXsXGVbGCYDFU5GLPX9HZLWfD+ZWkiPo30KUjNoOtw=
github.com/tebeka/strftime v0.1.3/go.mod h1:7wJm3dZlpr4l/oVK0t1HYIc4rMzQ2XJlOMIUJUJH6XQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.194/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.759 h1:flWgFybB3MYWFxwRO4yXbdiPT3SNwjSLuXCXsfs6kN4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.759/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/kms v1.0.194/go.mod h1:yrBKWhChnDqNz1xuXdSbWXG56XawEq0G5j1lg4VwBD4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.759 h1:GrpwnCcbPYewCj/lvyAWEShTprW+5CVWrU+89UyjXcs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms v1.0.759/go.mod h1:PEv4IxnbGqYejMUrUxawrlKHQUiAvgEXHpYP4Rfa538=
github.com/tencentyun/cos-go-sdk-v5 v0.7.33 h1:5jmJU7U/1nf/7ZPDkrUL8KlF1oDUzTHsdtLNY6x0hq4=
github.com/tencentyun/cos-go-sdk-v5 v0.7.33/go.mod h1:4E4+bQ2gBVJcgEC9Cufwylio4mXOct2iu05WjgEBx1o=
github.com/testcontainers/testcontainers-go v0.9.0/go.mod h1:b22BFXhRbg4PJmeMVWh6ftqjyZHgiIl3w274e9r3C2E=
Expand Down
35 changes: 35 additions & 0 deletions components/sms/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2021 Layotto Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sms

import (
"errors"
"fmt"
)

var (
ErrClientNotInit = errors.New("error: client not init")
)

func MissingMethodParam(method, param string) error {
return fmt.Errorf("error: sms `%s` method missing parameter `%s`", method, param)
}

func MissingInitParam(param string) error {
return MissingMethodParam("init", param)
}

func MissingSendSmsParam(param string) error {
return MissingMethodParam("sendSms", param)
}
31 changes: 31 additions & 0 deletions components/sms/meta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2021 Layotto Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sms

// metadata required to init sms client
const (
ClientKey = "accessKeyID"
ClientSecret = "accessKeySecret"
Region = "region"
)

// metadata required to tencentcloud sms request
const (
SdkAppId = "SdkAppId"
)

// metadata contained in sms response
const (
PhoneNumber = "PhoneNumber"
)
18 changes: 2 additions & 16 deletions components/sms/types_generated.go → components/sms/registry.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Code generated by github.com/layotto/protoc-gen-p6 .

// Copyright 2021 Layotto Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,23 +14,11 @@
package sms

import (
fmt "fmt"

info "mosn.io/layotto/components/pkg/info"
ref "mosn.io/layotto/components/ref"
)
"fmt"

const (
serviceName = "sms"
"mosn.io/layotto/components/pkg/info"
)

// Config is the component's configuration
type Config struct {
ref.Config
Type string `json:"type"`
Metadata map[string]string `json:"metadata"`
}

type Registry interface {
Register(fs ...*Factory)
Create(compType string) (SmsService, error)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Code generated by github.com/layotto/protoc-gen-p6 .

// Copyright 2021 Layotto Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,7 +14,11 @@
package sms

import (
context "context"
"context"
)

const (
serviceName = "sms"
)

type SmsService interface {
Expand Down
20 changes: 20 additions & 0 deletions components/sms/tencentcloud/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2021 Layotto Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package tencentcloud

import "mosn.io/layotto/components/sms"

func NewSmsWithClient(client SmsClient) sms.SmsService {
return &Sms{client: client}
}
Loading

0 comments on commit f5a5957

Please sign in to comment.