From 19bd7e1f2c8636c08c22da0ea4d2cbf60bb11ca9 Mon Sep 17 00:00:00 2001
From: Link Dupont
Date: Thu, 18 Jan 2024 12:44:36 -0500
Subject: [PATCH 1/4] refactor: update to platform-go-middlwares/v2
Update to use platform-go-middlewares/v2 API.
---
associate.go | 2 +-
associate_test.go | 2 +-
go.mod | 2 +-
go.sum | 54 ++++++++---------------------------------------
identity.go | 2 +-
identity_test.go | 2 +-
internal.go | 2 +-
internal_test.go | 2 +-
system.go | 2 +-
system_test.go | 2 +-
user.go | 2 +-
user_test.go | 2 +-
x509.go | 2 +-
x509_test.go | 2 +-
14 files changed, 22 insertions(+), 58 deletions(-)
diff --git a/associate.go b/associate.go
index af91660..4ec6f8e 100644
--- a/associate.go
+++ b/associate.go
@@ -2,7 +2,7 @@ package xrhidgen
import (
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
)
// Associate holds values to be used as input when generating an associate
diff --git a/associate_test.go b/associate_test.go
index b845628..689cf6b 100644
--- a/associate_test.go
+++ b/associate_test.go
@@ -6,7 +6,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
"go.openly.dev/pointy"
)
diff --git a/go.mod b/go.mod
index 83bf922..4721552 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/peterbourgon/ff/v3 v3.4.0
github.com/pioz/faker v1.7.3
- github.com/redhatinsights/platform-go-middlewares v0.20.0
+ github.com/redhatinsights/platform-go-middlewares/v2 v2.0.0-20240118174021-7836c2be5281
github.com/sgreben/flagvar v1.10.1
go.openly.dev/pointy v1.3.0
)
diff --git a/go.sum b/go.sum
index ba273b1..0fcbfd1 100644
--- a/go.sum
+++ b/go.sum
@@ -1,68 +1,32 @@
-github.com/aws/aws-sdk-go v1.38.51/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
-github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
-github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
+github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
-github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
-github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
-github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
-github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
-github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
-github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
-github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
-github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
-github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
-github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
+github.com/nxadm/tail v1.4.11 h1:8feyoE3OzPrcshW5/MJ4sGESc5cqmGkGCWlco4l0bqY=
+github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
+github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/peterbourgon/ff/v3 v3.4.0 h1:QBvM/rizZM1cB0p0lGMdmR7HxZeI/ZrBWB4DqLkMUBc=
github.com/peterbourgon/ff/v3 v3.4.0/go.mod h1:zjJVUhx+twciwfDl0zBcFzl4dW8axCRyXE/eKY9RztQ=
github.com/pioz/faker v1.7.3 h1:Tez8Emuq0UN+/d6mo3a9m/9ZZ/zdfJk0c5RtRatrceM=
github.com/pioz/faker v1.7.3/go.mod h1:xSpay5w/oz1a6+ww0M3vfpe40pSIykeUPeWEc3TvVlc=
-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/redhatinsights/platform-go-middlewares v0.20.0 h1:qwK9ArGYRlORsZ56PXXLJrGvzTsMe3bk2lR+WN5aIjM=
-github.com/redhatinsights/platform-go-middlewares v0.20.0/go.mod h1:i5gVDZJ/quCQhs5AW5CwkRPXlz1HfDBvyNtXHnlXZfM=
+github.com/redhatinsights/platform-go-middlewares/v2 v2.0.0-20240118174021-7836c2be5281 h1:L20lFlHbO92CNOH+xNM3U+TnSQfnSPIZdUjgIhtCIl0=
+github.com/redhatinsights/platform-go-middlewares/v2 v2.0.0-20240118174021-7836c2be5281/go.mod h1:GI4AFQc+iHCvHGbbuY1roOY7KXKDqWbldRemReHk7Pk=
github.com/sgreben/flagvar v1.10.1 h1:ukN3zqVj9T9U7CiKG6owmejxswJYMbAg9Mxkhi1B4tw=
github.com/sgreben/flagvar v1.10.1/go.mod h1:AxDmbFDIxZ4dHj2zg8LxuJn5CSwSS28iY/Wy56e+nhI=
-github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
go.openly.dev/pointy v1.3.0 h1:keht3ObkbDNdY8PWPwB7Kcqk+MAlNStk5kXZTxukE68=
go.openly.dev/pointy v1.3.0/go.mod h1:rccSKiQDQ2QkNfSVT2KG8Budnfhf3At8IWxy/3ElYes=
-go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
-go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
-go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
-golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
-golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
-golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
-golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
-golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
-golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
-golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
+golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
+golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
-gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
-gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
-gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
diff --git a/identity.go b/identity.go
index 10f41ef..1def4a8 100644
--- a/identity.go
+++ b/identity.go
@@ -2,7 +2,7 @@ package xrhidgen
import (
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
)
// Identity holds values to be used as input when generating a main identity
diff --git a/identity_test.go b/identity_test.go
index e8df133..d84f121 100644
--- a/identity_test.go
+++ b/identity_test.go
@@ -6,7 +6,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
"go.openly.dev/pointy"
)
diff --git a/internal.go b/internal.go
index 2f7cbd7..a0e87e3 100644
--- a/internal.go
+++ b/internal.go
@@ -2,7 +2,7 @@ package xrhidgen
import (
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
)
// Internal holds values to be used as input when generating an internal
diff --git a/internal_test.go b/internal_test.go
index a44a041..ac43631 100644
--- a/internal_test.go
+++ b/internal_test.go
@@ -6,7 +6,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
"go.openly.dev/pointy"
)
diff --git a/system.go b/system.go
index a8d2294..a6b4b00 100644
--- a/system.go
+++ b/system.go
@@ -2,7 +2,7 @@ package xrhidgen
import (
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
)
// System holds values to be used as input when generating a system identity
diff --git a/system_test.go b/system_test.go
index 6913f6f..b81e225 100644
--- a/system_test.go
+++ b/system_test.go
@@ -6,7 +6,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
"go.openly.dev/pointy"
)
diff --git a/user.go b/user.go
index 0360b73..30aecc3 100644
--- a/user.go
+++ b/user.go
@@ -2,7 +2,7 @@ package xrhidgen
import (
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
)
// User holds values to be used as input when generating a user identity record.
diff --git a/user_test.go b/user_test.go
index cc5c02b..88b369c 100644
--- a/user_test.go
+++ b/user_test.go
@@ -6,7 +6,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
"go.openly.dev/pointy"
)
diff --git a/x509.go b/x509.go
index 8873c3b..70fd21a 100644
--- a/x509.go
+++ b/x509.go
@@ -2,7 +2,7 @@ package xrhidgen
import (
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
)
// X509 holds values to be used as input when generating an x509 identity
diff --git a/x509_test.go b/x509_test.go
index a7190ea..5eb3087 100644
--- a/x509_test.go
+++ b/x509_test.go
@@ -6,7 +6,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
- "github.com/redhatinsights/platform-go-middlewares/identity"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
"go.openly.dev/pointy"
)
From 40e96bcfaa5bcc165d933d0a8a2c30f1fc2e3ab2 Mon Sep 17 00:00:00 2001
From: Link Dupont
Date: Thu, 18 Jan 2024 13:01:08 -0500
Subject: [PATCH 2/4] feat: Support generating service_account records
Add support for generating ServiceAccount type identity records.
---
example_test.go | 24 ++++++++++---
identity.go | 21 ++++++++++++
service_account.go | 33 ++++++++++++++++++
service_account_test.go | 76 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 149 insertions(+), 5 deletions(-)
create mode 100644 service_account.go
create mode 100644 service_account_test.go
diff --git a/example_test.go b/example_test.go
index 17d7494..a74f30b 100644
--- a/example_test.go
+++ b/example_test.go
@@ -18,7 +18,7 @@ func ExampleAssociate() {
panic(err)
}
fmt.Println(string(data))
- //Output: {"identity":{"employee_account_number":"02299","org_id":"41123","internal":{"org_id":""},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{},"associate":{"Role":null,"email":"winnifredwinning@shred.org","givenName":"Cameron","rhatUUID":"00e3c758-1d7d-4ecd-98a2-997157e2d05c","surname":"Swift"},"x509":{"subject_dn":"","issuer_dn":""},"type":"Associate","auth_type":"basic-auth"}}
+ //Output: {"identity":{"employee_account_number":"02299","org_id":"41123","internal":{"org_id":""},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{},"associate":{"Role":null,"email":"winnifredwinning@shred.org","givenName":"Cameron","rhatUUID":"00e3c758-1d7d-4ecd-98a2-997157e2d05c","surname":"Swift"},"x509":{"subject_dn":"","issuer_dn":""},"service_account":{"client_id":"","username":""},"type":"Associate","auth_type":"basic-auth"},"entitlements":null}
}
func ExampleInternal() {
@@ -32,7 +32,7 @@ func ExampleInternal() {
panic(err)
}
fmt.Println(string(data))
- //Output: {"identity":{"org_id":"03797","internal":{"org_id":"08321","auth_time":-2978345600000000000},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"type":"Internal","auth_type":"basic-auth"}}
+ //Output: {"identity":{"org_id":"03797","internal":{"org_id":"08321","auth_time":-2978345600000000000},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"service_account":{"client_id":"","username":""},"type":"Internal","auth_type":"basic-auth"},"entitlements":null}
}
func ExampleSystem() {
@@ -46,7 +46,7 @@ func ExampleSystem() {
panic(err)
}
fmt.Println(string(data))
- //Output: {"identity":{"account_number":"16398","org_id":"57572","internal":{"org_id":"57572"},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{"cn":"It6P","cert_type":"consumer","cluster_id":"x8LdjPo"},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"type":"System","auth_type":"basic-auth"}}
+ //Output: {"identity":{"account_number":"16398","org_id":"57572","internal":{"org_id":"57572"},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{"cn":"It6P","cert_type":"consumer","cluster_id":"x8LdjPo"},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"service_account":{"client_id":"","username":""},"type":"System","auth_type":"basic-auth"},"entitlements":null}
}
func ExampleUser() {
@@ -60,7 +60,7 @@ func ExampleUser() {
panic(err)
}
fmt.Println(string(data))
- //Output: {"identity":{"org_id":"23807","internal":{"org_id":"23807"},"user":{"username":"tycoon","email":"fransen@crump.biz","first_name":"Frankie","last_name":"Collins","is_active":false,"is_org_admin":false,"is_internal":true,"locale":"pi","user_id":"backset"},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"type":"User","auth_type":"cert-auth"}}
+ //Output: {"identity":{"org_id":"23807","internal":{"org_id":"23807"},"user":{"username":"tycoon","email":"fransen@crump.biz","first_name":"Frankie","last_name":"Collins","is_active":false,"is_org_admin":false,"is_internal":true,"locale":"pi","user_id":"backset"},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"service_account":{"client_id":"","username":""},"type":"User","auth_type":"cert-auth"},"entitlements":null}
}
func ExampleX509() {
@@ -74,5 +74,19 @@ func ExampleX509() {
panic(err)
}
fmt.Println(string(data))
- //Output: {"identity":{"org_id":"23807","internal":{"org_id":""},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"2","issuer_dn":"3sfSj"},"type":"X509","auth_type":"cert-auth"}}
+ //Output: {"identity":{"org_id":"23807","internal":{"org_id":""},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"2","issuer_dn":"3sfSj"},"service_account":{"client_id":"","username":""},"type":"X509","auth_type":"cert-auth"},"entitlements":null}
+}
+
+func ExampleServiceAccount() {
+ xrhidgen.SetSeed(103)
+ id, err := xrhidgen.NewServiceAccountIdentity(xrhidgen.Identity{}, xrhidgen.ServiceAccount{})
+ if err != nil {
+ panic(err)
+ }
+ data, err := json.Marshal(id)
+ if err != nil {
+ panic(err)
+ }
+ fmt.Println(string(data))
+ //Output: {"identity":{"org_id":"23807","internal":{"org_id":""},"user":{"username":"","email":"","first_name":"","last_name":"","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"","user_id":""},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"service_account":{"client_id":"2","username":"crump"},"type":"ServiceAccount","auth_type":"cert-auth"},"entitlements":null}
}
diff --git a/identity.go b/identity.go
index 1def4a8..d130fc9 100644
--- a/identity.go
+++ b/identity.go
@@ -165,3 +165,24 @@ func NewUserIdentity(identityTemplate Identity, userTemplate User) (*identity.XR
return id, nil
}
+
+// NewServiceAccountIdentity will build and return a fully populated
+// ServiceAccount identity record, using any values that are present in
+// identityTemplate and serviceAccountTemplate.
+func NewServiceAccountIdentity(identityTemplate Identity, serviceAccountTemplate ServiceAccount) (*identity.XRHID, error) {
+ id, err := NewIdentity(identityTemplate)
+ if err != nil {
+ return nil, err
+ }
+
+ serviceAccount, err := NewServiceAccount(serviceAccountTemplate)
+ if err != nil {
+ return nil, err
+ }
+
+ id.Identity.ServiceAccount = *serviceAccount
+
+ id.Identity.Type = "ServiceAccount"
+
+ return id, nil
+}
diff --git a/service_account.go b/service_account.go
new file mode 100644
index 0000000..c05cdfe
--- /dev/null
+++ b/service_account.go
@@ -0,0 +1,33 @@
+package xrhidgen
+
+import (
+ "github.com/pioz/faker"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
+)
+
+// ServiceAccount holds values to be used as input when generating a service
+// account identity record.
+type ServiceAccount struct {
+ ClientID *string
+ Username *string
+}
+
+// NewServiceAccount will build and return a fully populated ServiceAccount data
+// structure, using any values that are present in template.
+func NewServiceAccount(template ServiceAccount) (*identity.ServiceAccount, error) {
+ var id identity.ServiceAccount
+
+ if template.ClientID != nil {
+ id.ClientId = *template.ClientID
+ } else {
+ id.ClientId = faker.String()
+ }
+
+ if template.Username != nil {
+ id.Username = *template.Username
+ } else {
+ id.Username = faker.Username()
+ }
+
+ return &id, nil
+}
diff --git a/service_account_test.go b/service_account_test.go
new file mode 100644
index 0000000..93a6278
--- /dev/null
+++ b/service_account_test.go
@@ -0,0 +1,76 @@
+package xrhidgen
+
+import (
+ "testing"
+
+ "github.com/google/go-cmp/cmp"
+ "github.com/google/go-cmp/cmp/cmpopts"
+ "github.com/pioz/faker"
+ "github.com/redhatinsights/platform-go-middlewares/v2/identity"
+ "go.openly.dev/pointy"
+)
+
+func TestNewServiceAccount(t *testing.T) {
+ type Tests struct {
+ description string
+ seed int64
+ input ServiceAccount
+ want *identity.ServiceAccount
+ wantError error
+ }
+ tests := []Tests{
+ {
+ description: "empty template",
+ seed: 100,
+ input: ServiceAccount{},
+ want: &identity.ServiceAccount{
+ ClientId: "gimwu7Re",
+ Username: "boltrope",
+ },
+ },
+ {
+ description: "partial template",
+ seed: 100,
+ input: ServiceAccount{
+ ClientID: pointy.String("12345"),
+ },
+ want: &identity.ServiceAccount{
+ ClientId: "12345",
+ Username: "ammon",
+ },
+ },
+ {
+ description: "full template",
+ seed: 100,
+ input: ServiceAccount{
+ ClientID: pointy.String("12345"),
+ Username: pointy.String("jsmith"),
+ },
+ want: &identity.ServiceAccount{
+ ClientId: "12345",
+ Username: "jsmith",
+ },
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.description, func(t *testing.T) {
+ faker.SetSeed(test.seed)
+
+ got, err := NewServiceAccount(test.input)
+
+ if test.wantError != nil {
+ if !cmp.Equal(err, test.wantError, cmpopts.EquateErrors()) {
+ t.Errorf("%#v != %#v", err, test.wantError)
+ }
+ } else {
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !cmp.Equal(got, test.want) {
+ t.Errorf("%v", cmp.Diff(got, test.want))
+ }
+ }
+ })
+ }
+}
From 565ec9057dd0c51ae936d69650d72b2c1d8c4a9a Mon Sep 17 00:00:00 2001
From: Link Dupont
Date: Thu, 18 Jan 2024 13:54:33 -0500
Subject: [PATCH 3/4] feat: add service-account subcommand
xrhidgen can now generate service-account records using the
'service-account' subcommand.
---
cmd/xrhidgen/main.go | 42 +++++++++++++-------------
cmd/xrhidgen/service_account.go | 53 +++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 20 deletions(-)
create mode 100644 cmd/xrhidgen/service_account.go
diff --git a/cmd/xrhidgen/main.go b/cmd/xrhidgen/main.go
index a731ff8..2f69c72 100644
--- a/cmd/xrhidgen/main.go
+++ b/cmd/xrhidgen/main.go
@@ -1,25 +1,26 @@
// xrhidgen generates X-Rh-Identity records.
//
-// Usage:
-// xrhidgen [flags]
-
-// xrhidgen can be used to generate JSON records suitable for passing in to
-// the X-Rh-Identity header. Each subcommand will generate a record of the
-// specified type. Any flag set will be inserted instead of a random value.
-// All remaining fields will be filled with a suitably random value.
-
-// SUBCOMMANDS
-// user generate a user identity JSON record
-// internal generate an internal identity JSON record
-// system generate a system identity JSON record
-// associate generate an associate identity JSON record
-
-// FLAGS
-// -account-number ... set the identity.account_number field (string)
-// -auth-type ... set the identity.authtype field (string)
-// -employe-account-number ... set the identity.employee_account_number field (string)
-// -org-id ... set the identity.org_id field (string)
-// -type ... set the identity.type field (string)
+// USAGE
+// xrhidgen [flags]
+//
+// xrhidgen can be used to generate JSON records suitable for passing in to
+// the X-Rh-Identity header. Each subcommand will generate a record of the
+// specified type. Any flag set will be inserted instead of a random value.
+// All remaining fields will be filled with a suitably random value.
+//
+// SUBCOMMANDS
+// user generate a user identity JSON record
+// internal generate an internal identity JSON record
+// system generate a system identity JSON record
+// associate generate an associate identity JSON record
+// service-account generate a service account identity JSON record
+//
+// FLAGS
+// -account-number value set the identity.account_number field (string)
+// -auth-type value set the identity.authtype field (string)
+// -employe-account-number value set the identity.employee_account_number field (string)
+// -org-id value set the identity.org_id field (string)
+// -type value set the identity.type field (string)
package main
import (
@@ -61,6 +62,7 @@ func main() {
internalCommand,
systemCommand,
associateCommand,
+ serviceAccountCommand,
},
Exec: func(context.Context, []string) error {
return flag.ErrHelp
diff --git a/cmd/xrhidgen/service_account.go b/cmd/xrhidgen/service_account.go
new file mode 100644
index 0000000..73246f4
--- /dev/null
+++ b/cmd/xrhidgen/service_account.go
@@ -0,0 +1,53 @@
+package main
+
+import (
+ "context"
+ "encoding/json"
+ "flag"
+ "fmt"
+
+ "github.com/peterbourgon/ff/v3/ffcli"
+ "github.com/subpop/xrhidgen"
+)
+
+var serviceAccountFlags struct {
+ clientID StringFlag
+ username StringFlag
+}
+
+func NewServiceAccountFlagSet(name string, errorHandling flag.ErrorHandling) *flag.FlagSet {
+ fs := flag.NewFlagSet(name, errorHandling)
+
+ fs.Var(&serviceAccountFlags.clientID, "client-id", "set the identity.service_account.client_id field (string)")
+ fs.Var(&serviceAccountFlags.username, "username", "set the identity.service_account.username field (string)")
+
+ return fs
+}
+
+var serviceAccountCommand = &ffcli.Command{
+ Name: "service-account",
+ ShortUsage: "service-account [flags]",
+ ShortHelp: "generate a service account identity JSON record",
+ LongHelp: WordWrap("Generate a service account identity record, populating fields with values provided by the matching flag. Any omitted flags will have their corresponding fields populated with a suitable random value.", 72),
+ FlagSet: NewServiceAccountFlagSet("service-account", flag.ExitOnError),
+ Exec: func(ctx context.Context, args []string) error {
+ serviceAccount := xrhidgen.ServiceAccount{
+ ClientID: serviceAccountFlags.clientID.Value,
+ Username: serviceAccountFlags.username.Value,
+ }
+
+ id, err := xrhidgen.NewServiceAccountIdentity(mainIdentity(), serviceAccount)
+ if err != nil {
+ return err
+ }
+
+ data, err := json.Marshal(id)
+ if err != nil {
+ return fmt.Errorf("cannot marshal data: %w", err)
+ }
+
+ fmt.Println(string(data))
+
+ return nil
+ },
+}
From 6a996dcdb2d9cb8f92702ef6e278fc4c3b0681ec Mon Sep 17 00:00:00 2001
From: Link Dupont
Date: Thu, 18 Jan 2024 13:58:53 -0500
Subject: [PATCH 4/4] docs: update examples
Update the example output in README to match the new JSON produced by
platform-go-middleware/identity.
---
README.md | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index a6a7476..70efb05 100644
--- a/README.md
+++ b/README.md
@@ -26,29 +26,30 @@ specified type. Any flag set will be inserted instead of a random value.
All remaining fields will be filled with a suitably random value.
SUBCOMMANDS
- user generate a user identity JSON record
- internal generate an internal identity JSON record
- system generate a system identity JSON record
- associate generate an associate identity JSON record
+ user generate a user identity JSON record
+ internal generate an internal identity JSON record
+ system generate a system identity JSON record
+ associate generate an associate identity JSON record
+ service-account generate a service account identity JSON record
FLAGS
- -account-number ... set the identity.account_number field (string)
- -auth-type ... set the identity.authtype field (string)
- -employe-account-number ... set the identity.employee_account_number field (string)
- -org-id ... set the identity.org_id field (string)
- -type ... set the identity.type field (string)
+ -account-number value set the identity.account_number field (string)
+ -auth-type value set the identity.authtype field (string)
+ -employe-account-number value set the identity.employee_account_number field (string)
+ -org-id value set the identity.org_id field (string)
+ -type value set the identity.type field (string)
```
### Examples
```
$ xrhidgen user -email someuser@redhat.com
-{"identity":{"account_number":"16349","auth_type":"cert","employee_account_number":"06900","internal":{"org_id":"51818"},"org_id":"51818","type":"User","user":{"email":"someuser@redhat.com","first_name":"Quinn","is_active":true,"is_internal":true,"is_org_admin":true,"last_name":"Runolfsdottir","locale":"se","user_id":"taps","username":"dunstable"}}}
+{"identity":{"org_id":"45841","internal":{"org_id":"45841"},"user":{"username":"backbencher","email":"someuser@redhat.com","first_name":"Cira","last_name":"Roob","is_active":false,"is_org_admin":true,"is_internal":false,"locale":"li","user_id":"nicole"},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"service_account":{"client_id":"","username":""},"type":"User","auth_type":"cert-auth"},"entitlements":null}
```
```
$ xrhidgen system | base64 -w0
-eyJpZGVudGl0eSI6eyJhY2NvdW50X251bWJlciI6IjQ0NDY4OCIsImVtcGxveWVlX2FjY291bnRfbnVtYmVyIjoiIiwib3JnX2lkIjoiODEzNTIiLCJzeXN0ZW0iOnsiY2VydF90eXBlIjoiIiwiY2x1c3Rlcl9pZCI6ImNjWWJhTllCIiwiY24iOiJhYzRlM2RmYy1kOGU3LTQwODUtYjg3YS0zMTcyZjU1M2I3M2UifSwidHlwZSI6IiJ9fQo=
+eyJpZGVudGl0eSI6eyJvcmdfaWQiOiIyMTcwMyIsImludGVybmFsIjp7Im9yZ19pZCI6IjIxNzAzIn0sInVzZXIiOnsidXNlcm5hbWUiOiIiLCJlbWFpbCI6IiIsImZpcnN0X25hbWUiOiIiLCJsYXN0X25hbWUiOiIiLCJpc19hY3RpdmUiOmZhbHNlLCJpc19vcmdfYWRtaW4iOmZhbHNlLCJpc19pbnRlcm5hbCI6ZmFsc2UsImxvY2FsZSI6IiIsInVzZXJfaWQiOiIifSwic3lzdGVtIjp7ImNuIjoiRyIsImNlcnRfdHlwZSI6ImNvbnN1bWVyIiwiY2x1c3Rlcl9pZCI6IkhKbyJ9LCJhc3NvY2lhdGUiOnsiUm9sZSI6bnVsbCwiZW1haWwiOiIiLCJnaXZlbk5hbWUiOiIiLCJyaGF0VVVJRCI6IiIsInN1cm5hbWUiOiIifSwieDUwOSI6eyJzdWJqZWN0X2RuIjoiIiwiaXNzdWVyX2RuIjoiIn0sInNlcnZpY2VfYWNjb3VudCI6eyJjbGllbnRfaWQiOiIiLCJ1c2VybmFtZSI6IiJ9LCJ0eXBlIjoiU3lzdGVtIiwiYXV0aF90eXBlIjoiYmFzaWMtYXV0aCJ9LCJlbnRpdGxlbWVudHMiOm51bGx9Cg==
```
```
@@ -60,7 +61,7 @@ used to initialize the generator to a deterministic state.
```
$ SEED=100 xrhidgen user
-{"identity":{"auth_type":"basic","employee_account_number":"02299","internal":{"org_id":"41123"},"org_id":"41123","type":"User","user":{"email":"winnifredwinning@shred.org","first_name":"Cameron","is_active":false,"is_internal":false,"is_org_admin":false,"last_name":"Stehr","locale":"fi","user_id":"meredeth","username":"skeptic"}}}
+{"identity":{"employee_account_number":"02299","org_id":"41123","internal":{"org_id":"41123"},"user":{"username":"skeptic","email":"winnifredwinning@shred.org","first_name":"Cameron","last_name":"Stehr","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"fi","user_id":"meredeth"},"system":{},"associate":{"Role":null,"email":"","givenName":"","rhatUUID":"","surname":""},"x509":{"subject_dn":"","issuer_dn":""},"service_account":{"client_id":"","username":""},"type":"User","auth_type":"basic-auth"},"entitlements":null}
```
## Go package