From 0fc1e1963ebabad979fdf28f3b791652afec4ad8 Mon Sep 17 00:00:00 2001 From: arthurus36-alt Date: Wed, 20 May 2026 14:06:28 +0000 Subject: [PATCH] feat: Retrieve and use endpoint, token, and cert configuration --- core/client/grpc.go | 28 ++++++++++++++++++++++++++-- core/config/config.go | 3 +++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/client/grpc.go b/core/client/grpc.go index 11835df..ad26bf9 100644 --- a/core/client/grpc.go +++ b/core/client/grpc.go @@ -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 } diff --git a/core/config/config.go b/core/config/config.go index c9bdebb..b417f54 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -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:"-"` }