Skip to content

Commit

Permalink
refactor: update identity to v2.0.0-beta.2
Browse files Browse the repository at this point in the history
beta.2 uses pointers for empty struct fields, enabling a smaller output
when marshaling to JSON. The New*Identity functions need to be updated
to use the pointers correctly, and example output needs to be updated to
demonstrate the smaller JSON output.
  • Loading branch information
subpop committed Jan 25, 2024
1 parent 8376468 commit fc54fa8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ FLAGS

```
$ xrhidgen user -email [email protected]
{"identity":{"org_id":"45841","internal":{"org_id":"45841"},"user":{"username":"backbencher","email":"[email protected]","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}
{"identity":{"account_number":"71384","org_id":"72467","internal":{"org_id":"72467"},"user":{"username":"rockabilly","email":"[email protected]","first_name":"Sawyer","last_name":"Ferry","is_active":true,"is_org_admin":true,"is_internal":false,"locale":"ee","user_id":"insurgence"},"type":"User","auth_type":"cert-auth"},"entitlements":null}
```

```
$ xrhidgen system | base64 -w0
eyJpZGVudGl0eSI6eyJvcmdfaWQiOiIyMTcwMyIsImludGVybmFsIjp7Im9yZ19pZCI6IjIxNzAzIn0sInVzZXIiOnsidXNlcm5hbWUiOiIiLCJlbWFpbCI6IiIsImZpcnN0X25hbWUiOiIiLCJsYXN0X25hbWUiOiIiLCJpc19hY3RpdmUiOmZhbHNlLCJpc19vcmdfYWRtaW4iOmZhbHNlLCJpc19pbnRlcm5hbCI6ZmFsc2UsImxvY2FsZSI6IiIsInVzZXJfaWQiOiIifSwic3lzdGVtIjp7ImNuIjoiRyIsImNlcnRfdHlwZSI6ImNvbnN1bWVyIiwiY2x1c3Rlcl9pZCI6IkhKbyJ9LCJhc3NvY2lhdGUiOnsiUm9sZSI6bnVsbCwiZW1haWwiOiIiLCJnaXZlbk5hbWUiOiIiLCJyaGF0VVVJRCI6IiIsInN1cm5hbWUiOiIifSwieDUwOSI6eyJzdWJqZWN0X2RuIjoiIiwiaXNzdWVyX2RuIjoiIn0sInNlcnZpY2VfYWNjb3VudCI6eyJjbGllbnRfaWQiOiIiLCJ1c2VybmFtZSI6IiJ9LCJ0eXBlIjoiU3lzdGVtIiwiYXV0aF90eXBlIjoiYmFzaWMtYXV0aCJ9LCJlbnRpdGxlbWVudHMiOm51bGx9Cg==
eyJpZGVudGl0eSI6eyJvcmdfaWQiOiI2NjY1MSIsImludGVybmFsIjp7Im9yZ19pZCI6IjY2NjUxIn0sInN5c3RlbSI6eyJjbiI6ImFFcEdUZSIsImNlcnRfdHlwZSI6ImNvbnN1bWVyIiwiY2x1c3Rlcl9pZCI6ImlUNksifSwidHlwZSI6IlN5c3RlbSIsImF1dGhfdHlwZSI6ImNlcnQtYXV0aCJ9LCJlbnRpdGxlbWVudHMiOm51bGx9Cg==
```

```
Expand All @@ -61,7 +61,7 @@ used to initialize the generator to a deterministic state.

```
$ SEED=100 xrhidgen user
{"identity":{"employee_account_number":"02299","org_id":"41123","internal":{"org_id":"41123"},"user":{"username":"skeptic","email":"[email protected]","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}
{"identity":{"employee_account_number":"02299","org_id":"41123","internal":{"org_id":"41123"},"user":{"username":"skeptic","email":"[email protected]","first_name":"Cameron","last_name":"Stehr","is_active":false,"is_org_admin":false,"is_internal":false,"locale":"fi","user_id":"meredeth"},"type":"User","auth_type":"basic-auth"},"entitlements":null}
```

## Go package
Expand Down
12 changes: 6 additions & 6 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":"[email protected]","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}
//Output: {"identity":{"employee_account_number":"02299","org_id":"41123","internal":{"org_id":""},"associate":{"Role":null,"email":"[email protected]","givenName":"Cameron","rhatUUID":"00e3c758-1d7d-4ecd-98a2-997157e2d05c","surname":"Swift"},"type":"Associate","auth_type":"basic-auth"},"entitlements":null}
}

func ExampleInternal() {
Expand All @@ -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":""},"service_account":{"client_id":"","username":""},"type":"Internal","auth_type":"basic-auth"},"entitlements":null}
//Output: {"identity":{"org_id":"03797","internal":{"org_id":"08321","auth_time":-2978345600000000000},"type":"Internal","auth_type":"basic-auth"},"entitlements":null}
}

func ExampleSystem() {
Expand All @@ -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":""},"service_account":{"client_id":"","username":""},"type":"System","auth_type":"basic-auth"},"entitlements":null}
//Output: {"identity":{"account_number":"16398","org_id":"57572","internal":{"org_id":"57572"},"system":{"cn":"It6P","cert_type":"consumer","cluster_id":"x8LdjPo"},"type":"System","auth_type":"basic-auth"},"entitlements":null}
}

func ExampleUser() {
Expand All @@ -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":"[email protected]","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}
//Output: {"identity":{"org_id":"23807","internal":{"org_id":"23807"},"user":{"username":"tycoon","email":"[email protected]","first_name":"Frankie","last_name":"Collins","is_active":false,"is_org_admin":false,"is_internal":true,"locale":"pi","user_id":"backset"},"type":"User","auth_type":"cert-auth"},"entitlements":null}
}

func ExampleX509() {
Expand All @@ -74,7 +74,7 @@ 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"},"service_account":{"client_id":"","username":""},"type":"X509","auth_type":"cert-auth"},"entitlements":null}
//Output: {"identity":{"org_id":"23807","internal":{"org_id":""},"x509":{"subject_dn":"2","issuer_dn":"3sfSj"},"type":"X509","auth_type":"cert-auth"},"entitlements":null}
}

func ExampleServiceAccount() {
Expand All @@ -88,5 +88,5 @@ func ExampleServiceAccount() {
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}
//Output: {"identity":{"org_id":"23807","internal":{"org_id":""},"service_account":{"client_id":"2","username":"crump"},"type":"ServiceAccount","auth_type":"cert-auth"},"entitlements":null}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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/v2 v2.0.0-20240118174021-7836c2be5281
github.com/redhatinsights/platform-go-middlewares/v2 v2.0.0-beta.2
github.com/sgreben/flagvar v1.10.1
go.openly.dev/pointy v1.3.0
)
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
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/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
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=
Expand All @@ -16,6 +17,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
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/redhatinsights/platform-go-middlewares/v2 v2.0.0-beta.2 h1:pEDiKYqxEoZT6Mx7B57rYqIgmYyly0f8JfzfY38b9T4=
github.com/redhatinsights/platform-go-middlewares/v2 v2.0.0-beta.2/go.mod h1:Ipl1kmvhZSpgRoe7MyJNK+VAvGG1cIqn535TuId5npw=
github.com/sgreben/flagvar v1.10.1 h1:ukN3zqVj9T9U7CiKG6owmejxswJYMbAg9Mxkhi1B4tw=
github.com/sgreben/flagvar v1.10.1/go.mod h1:AxDmbFDIxZ4dHj2zg8LxuJn5CSwSS28iY/Wy56e+nhI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
10 changes: 5 additions & 5 deletions identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewAssociateIdentity(identityTemplate Identity, associateTemplate Associate
return nil, err
}

id.Identity.Associate = *associate
id.Identity.Associate = associate

id.Identity.Type = "Associate"

Expand Down Expand Up @@ -113,7 +113,7 @@ func NewSystemIdentity(identityTemplate Identity, systemTemplate System) (*ident
return nil, err
}

id.Identity.System = *system
id.Identity.System = system

id.Identity.Type = "System"
id.Identity.Internal = identity.Internal{
Expand All @@ -136,7 +136,7 @@ func NewX509Identity(identityTemplate Identity, x509Template X509) (*identity.XR
return nil, err
}

id.Identity.X509 = *x509
id.Identity.X509 = x509

id.Identity.Type = "X509"

Expand All @@ -156,7 +156,7 @@ func NewUserIdentity(identityTemplate Identity, userTemplate User) (*identity.XR
return nil, err
}

id.Identity.User = *user
id.Identity.User = user

id.Identity.Type = "User"
id.Identity.Internal = identity.Internal{
Expand All @@ -180,7 +180,7 @@ func NewServiceAccountIdentity(identityTemplate Identity, serviceAccountTemplate
return nil, err
}

id.Identity.ServiceAccount = *serviceAccount
id.Identity.ServiceAccount = serviceAccount

id.Identity.Type = "ServiceAccount"

Expand Down
12 changes: 0 additions & 12 deletions identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ func TestNewIdentity(t *testing.T) {
want: &identity.XRHID{
Identity: identity.Identity{
AccountNumber: "",
Associate: identity.Associate{},
AuthType: "basic-auth",
EmployeeAccountNumber: "02299",
Internal: identity.Internal{},
OrgID: "41123",
System: identity.System{},
Type: "50cQB",
User: identity.User{},
X509: identity.X509{},
},
},
},
Expand All @@ -47,15 +43,11 @@ func TestNewIdentity(t *testing.T) {
want: &identity.XRHID{
Identity: identity.Identity{
AccountNumber: "1234",
Associate: identity.Associate{},
AuthType: "cert-auth",
EmployeeAccountNumber: "00229",
Internal: identity.Internal{},
OrgID: "94112",
System: identity.System{},
Type: "M5",
User: identity.User{},
X509: identity.X509{},
},
},
},
Expand All @@ -72,15 +64,11 @@ func TestNewIdentity(t *testing.T) {
want: &identity.XRHID{
Identity: identity.Identity{
AccountNumber: "10001",
Associate: identity.Associate{},
AuthType: "basic-auth",
EmployeeAccountNumber: "112233",
Internal: identity.Internal{},
OrgID: "111111",
System: identity.System{},
Type: "universal",
User: identity.User{},
X509: identity.X509{},
},
},
},
Expand Down

0 comments on commit fc54fa8

Please sign in to comment.