Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions core/client/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,43 @@
package client

import (
"crypto/tls"

"github.com/Permify/permify-cli/core/config"
permify "github.com/Permify/permify-go/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)

// New initializes a new permify client
func New(endpoint string) (*permify.Client, error) {
// Retrieve credentials from global storage
token := config.CliConfig.Token
certPath := config.CliConfig.CertPath
certKey := config.CliConfig.CertKey

var creds credentials.TransportCredentials
if certPath != "" && certKey != "" {
cert, err := tls.LoadX509KeyPair(certPath, certKey)
if err != nil {
return nil, err
}
creds = credentials.NewTLS(&tls.Config{
Certificates: []tls.Certificate{cert},
})
} else {
creds = insecure.NewCredentials()
}

opts := []grpc.DialOption{grpc.WithTransportCredentials(creds)}

client, err := permify.NewClient(
permify.Config{
Endpoint: endpoint,
Token: token,
},
// Todo: Implement secure call with tls certificate
grpc.WithTransportCredentials(insecure.NewCredentials()),
opts...,
)
return client, err
}
3 changes: 3 additions & 0 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type ProfileConfigs struct {
type CoreConfig struct {
PermifyURL string `yaml:"permify_url"`
Tenant string `yaml:"tenant"`
Token string `yaml:"token"`
CertPath string `yaml:"cert_path"`
CertKey string `yaml:"cert_key"`
SslEnabled bool `yaml:"-"`
}

Expand Down