Skip to content

Commit

Permalink
Go clients test
Browse files Browse the repository at this point in the history
  • Loading branch information
shubh-ranade committed Feb 29, 2024
1 parent df213db commit 751739c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.26.0 (40646f47)
creationTimestamp: null
kompose.version: 1.32.0 (HEAD)
labels:
io.kompose.service: consumer
name: consumer-chang
namespace: pkc-devcc97qpm5
name: consumer-shubhankar
namespace: pkc-devc19rzw5
spec:
replicas: 1
selector:
Expand All @@ -19,26 +18,26 @@ spec:
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.26.0 (40646f47)
creationTimestamp: null
kompose.version: 1.32.0 (HEAD)
labels:
io.kompose.network/docker-spire-kafka-consumer-example-default: "true"
io.kompose.service: consumer
spec:
containers:
- env:
- name: BOOTSTRAP_SERVERS
value: pkc-devcc97qpm5.us-west-2.aws.devel.cpdev.cloud:9092
value: pkc-devc19rzw5.us-west-2.aws.devel.cpdev.cloud:9092
- name: LKC
value: lkc-devcczwjmmd
value: lkc-devc3mk0gw
- name: PRINCIPAL
value: sub
- name: SOCKET_PATH
value: unix:/opt/spire/sockets/workload_api.sock
- name: TOPIC
value: kafka-spire-native
image: 755363985185.dkr.ecr.us-west-2.amazonaws.com/docker/dev/cc-base:kafka-consumer-spire-chang
value: kafka-spire-test
image: 519856050701.dkr.ecr.us-west-2.amazonaws.com/docker/dev/confluentinc/cc-base:kafka-consumer-spire-shubhankar
imagePullPolicy: Always
name: consumer-chang
name: consumer-shubhankar
resources: {}
volumeMounts:
- mountPath: /opt/spire/sockets
Expand Down
19 changes: 12 additions & 7 deletions examples/docker_spire_kafka_consumer_example/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ package main
import (
"context"
"fmt"
"github.com/confluentinc/confluent-kafka-go/v2/kafka"
"github.com/spiffe/go-spiffe/v2/svid/jwtsvid"
"github.com/spiffe/go-spiffe/v2/workloadapi"
"os"
"os/signal"
"syscall"
"time"

"github.com/confluentinc/confluent-kafka-go/v2/kafka"
"github.com/spiffe/go-spiffe/v2/svid/jwtsvid"
"github.com/spiffe/go-spiffe/v2/workloadapi"
)

// handleJWTTokenRefreshEvent retrieves JWT from the SPIFFE workload API and
Expand Down Expand Up @@ -100,10 +101,14 @@ func main() {
fmt.Fprintf(os.Stderr, "bootstrapServers is: %s\n", bootstrapServers)

config := kafka.ConfigMap{
"bootstrap.servers": bootstrapServers,
"security.protocol": "SASL_SSL",
"sasl.mechanisms": "OAUTHBEARER",
"sasl.oauthbearer.config": principal,
"bootstrap.servers": bootstrapServers,
"security.protocol": "SASL_SSL",
// "sasl.login.callback.handler.class": "io.confluent.kafka.clients.plugins.auth.oauth.SpireJwtLoginCallbackHandler",
"sasl.mechanisms": "OAUTHBEARER",
"sasl.oauthbearer.token.spire.agent.endpoint": socketPath,
"sasl.jaas.config": "org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required logicalCluster=" + lkc,
"sasl.oauthbearer.config": principal,
"group.id": "foo",
}

c, err := kafka.NewConsumer(&config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ services:
context: .
dockerfile: Dockerfile
environment:
- BOOTSTRAP_SERVERS=pkc-devcc97qpm5.us-west-2.aws.devel.cpdev.cloud:9092
- TOPIC=kafka-spire-native
- BOOTSTRAP_SERVERS=pkc-devc19rzw5.us-west-2.aws.devel.cpdev.cloud:9092
- TOPIC=kafka-spire-test
- PRINCIPAL=sub
- SOCKET_PATH=unix:/opt/spire/sockets/workload_api.sock
- LKC=lkc-devcczwnq87
- LKC=lkc-devc3mk0gw
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ services:
context: .
dockerfile: Dockerfile
environment:
- BOOTSTRAP_SERVERS=pkc-devcc97qpm5.us-west-2.aws.devel.cpdev.cloud:9092
- TOPIC=kafka-spire-native
- BOOTSTRAP_SERVERS=pkc-devc19rzw5.us-west-2.aws.devel.cpdev.cloud:9092
- TOPIC=kafka-spire-test
- PRINCIPAL=sub
- SOCKET_PATH=unix:/opt/spire/sockets/workload_api.sock
- LKC=lkc-devcczwnq87
- LKC=lkc-devc3mk0gw
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.26.0 (40646f47)
creationTimestamp: null
kompose.version: 1.32.0 (HEAD)
labels:
io.kompose.service: producer
name: producer-chang
namespace: pkc-devcc97qpm5
name: producer-shubhankar
namespace: pkc-devc19rzw5
spec:
replicas: 1
selector:
Expand All @@ -19,26 +18,26 @@ spec:
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.26.0 (40646f47)
creationTimestamp: null
kompose.version: 1.32.0 (HEAD)
labels:
io.kompose.network/docker-spire-kafka-producer-example-default: "true"
io.kompose.service: producer
spec:
containers:
- env:
- name: BOOTSTRAP_SERVERS
value: pkc-devcc97qpm5.us-west-2.aws.devel.cpdev.cloud:9092
value: pkc-devc19rzw5.us-west-2.aws.devel.cpdev.cloud:9092
- name: LKC
value: lkc-devcczwjmmd
value: lkc-devc3mk0gw
- name: PRINCIPAL
value: sub
- name: SOCKET_PATH
value: unix:/opt/spire/sockets/workload_api.sock
- name: TOPIC
value: kafka-spire-native
image: 755363985185.dkr.ecr.us-west-2.amazonaws.com/docker/dev/cc-base:kafka-producer-spire-chang
value: kafka-spire-test
image: 519856050701.dkr.ecr.us-west-2.amazonaws.com/docker/dev/confluentinc/cc-base:kafka-producer-spire-shubhankar
imagePullPolicy: Always
name: producer-chang
name: producer-shubhankar
resources: {}
volumeMounts:
- mountPath: /opt/spire/sockets
Expand Down
16 changes: 10 additions & 6 deletions examples/docker_spire_kafka_producer_example/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ package main
import (
"context"
"fmt"
"github.com/spiffe/go-spiffe/v2/svid/jwtsvid"
"github.com/spiffe/go-spiffe/v2/workloadapi"
"os"
"os/signal"
"syscall"
"time"

"github.com/spiffe/go-spiffe/v2/svid/jwtsvid"
"github.com/spiffe/go-spiffe/v2/workloadapi"

"github.com/confluentinc/confluent-kafka-go/v2/kafka"
)

Expand Down Expand Up @@ -102,10 +103,13 @@ func main() {
// You'll probably need to modify this configuration to
// match your environment.
config := kafka.ConfigMap{
"bootstrap.servers": bootstrapServers,
"security.protocol": "SASL_SSL",
"sasl.mechanisms": "OAUTHBEARER",
"sasl.oauthbearer.config": principal,
"bootstrap.servers": bootstrapServers,
"security.protocol": "SASL_SSL",
// "sasl.login.callback.handler.class": "io.confluent.kafka.clients.plugins.auth.oauth.SpireJwtLoginCallbackHandler",
"sasl.mechanisms": "OAUTHBEARER",
"sasl.oauthbearer.token.spire.agent.endpoint": socketPath,
"sasl.jaas.config": "org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required logicalCluster=" + lkc,
"sasl.oauthbearer.config": principal,
}

p, err := kafka.NewProducer(&config)
Expand Down

0 comments on commit 751739c

Please sign in to comment.