Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: depends on platform go middleware #2

Closed
Closed
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
2 changes: 1 addition & 1 deletion associate.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package xrhidgen

Check failure on line 1 in associate.go

View workflow job for this annotation

GitHub Actions / Lint code

: # github.com/subpop/xrhidgen [github.com/subpop/xrhidgen.test]

import (
"github.com/pioz/faker"
"github.com/redhatinsights/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

// Associate holds values to be used as input when generating an associate
Expand Down
2 changes: 1 addition & 1 deletion associate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

func TestNewAssociate(t *testing.T) {
Expand Down
16 changes: 9 additions & 7 deletions cmd/xrhidgen/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,27 @@ func (f *BoolFlag) Set(v string) error {

func (f BoolFlag) IsBoolFlag() bool { return true }

type Float64Flag struct {
Value *float64
type Float32Flag struct {
Value *float32
}

func (f Float64Flag) String() string {
func (f Float32Flag) String() string {
if f.Value != nil {
return strconv.FormatFloat(*f.Value, 'G', -1, 64)
return strconv.FormatFloat(float64(*f.Value), 'G', -1, 32)
}
return ""
}

func (f *Float64Flag) Set(v string) error {
func (f *Float32Flag) Set(v string) error {
if f.Value == nil {
f.Value = new(float64)
f.Value = new(float32)
}
var err error
*f.Value, err = strconv.ParseFloat(v, 64)
var value float64
value, err = strconv.ParseFloat(v, 32)
if err != nil {
return err
}
*f.Value = float32(value)
return nil
}
2 changes: 1 addition & 1 deletion cmd/xrhidgen/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

var internalFlags struct {
authType Float64Flag
authType Float32Flag
crossAccess BoolFlag
orgID StringFlag
}
Expand Down
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/module-update-router v0.0.0-20220708181923-3d8d459361dd
github.com/redhatinsights/platform-go-middlewares v0.20.0
github.com/sgreben/flagvar v1.10.1
)

Expand Down
1,466 changes: 12 additions & 1,454 deletions go.sum

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package xrhidgen

import (
"github.com/pioz/faker"
"github.com/redhatinsights/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

// Identity holds values to be used as input when generating a main identity
Expand All @@ -17,14 +17,14 @@ type Identity struct {

// NewIdentity will build and return a partially populated Identity data
// structure, using any values that are present in template.
func NewIdentity(template Identity) (*identity.Identity, error) {
var id identity.Identity
func NewIdentity(template Identity) (*identity.XRHID, error) {
var id identity.XRHID

if template.AccountNumber != nil {
id.Identity.AccountNumber = template.AccountNumber
id.Identity.AccountNumber = *template.AccountNumber
} else {
if faker.Bool() {
id.Identity.AccountNumber = ptrstring(faker.DigitsWithSize(5))
id.Identity.AccountNumber = faker.DigitsWithSize(5)
}
}

Expand All @@ -35,10 +35,10 @@ func NewIdentity(template Identity) (*identity.Identity, error) {
}

if template.EmployeeAccountNumber != nil {
id.Identity.EmployeeAccountNumber = template.EmployeeAccountNumber
id.Identity.EmployeeAccountNumber = *template.EmployeeAccountNumber
} else {
if faker.Bool() {
id.Identity.EmployeeAccountNumber = ptrstring(faker.DigitsWithSize(5))
id.Identity.EmployeeAccountNumber = faker.DigitsWithSize(5)
}
}

Expand All @@ -49,9 +49,9 @@ func NewIdentity(template Identity) (*identity.Identity, error) {
}

if template.Type != nil {
id.Identity.Type = template.Type
id.Identity.Type = *template.Type
} else {
id.Identity.Type = ptrstring(faker.String())
id.Identity.Type = faker.String()
}

return &id, nil
Expand All @@ -60,7 +60,7 @@ func NewIdentity(template Identity) (*identity.Identity, error) {
// NewAssociateIdentity will build and return a fully populated Associate
// identity record, using any values that are present in identityTemplate and
// associateTemplate.
func NewAssociateIdentity(identityTemplate Identity, associateTemplate Associate) (*identity.Identity, error) {
func NewAssociateIdentity(identityTemplate Identity, associateTemplate Associate) (*identity.XRHID, error) {
id, err := NewIdentity(identityTemplate)
if err != nil {
return nil, err
Expand All @@ -71,17 +71,17 @@ func NewAssociateIdentity(identityTemplate Identity, associateTemplate Associate
return nil, err
}

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

id.Identity.Type = ptrstring("Associate")
id.Identity.Type = "Associate"

return id, nil
}

// NewInternalIdentity will build and return a fully populated Internal identity
// record, using any values that are present in identityTemplate and
// internalTemplate.
func NewInternalIdentity(identityTemplate Identity, internalTemplate Internal) (*identity.Identity, error) {
func NewInternalIdentity(identityTemplate Identity, internalTemplate Internal) (*identity.XRHID, error) {
id, err := NewIdentity(identityTemplate)
if err != nil {
return nil, err
Expand All @@ -92,17 +92,17 @@ func NewInternalIdentity(identityTemplate Identity, internalTemplate Internal) (
return nil, err
}

id.Identity.Internal = internal
id.Identity.Internal = *internal

id.Identity.Type = ptrstring("Internal")
id.Identity.Type = "Internal"

return id, nil
}

// NewSystemIdentity will build and return a fully populated System identity
// record, using any values that are present in identityTemplate and
// systemTemplate.
func NewSystemIdentity(identityTemplate Identity, systemTemplate System) (*identity.Identity, error) {
func NewSystemIdentity(identityTemplate Identity, systemTemplate System) (*identity.XRHID, error) {
id, err := NewIdentity(identityTemplate)
if err != nil {
return nil, err
Expand All @@ -113,10 +113,10 @@ func NewSystemIdentity(identityTemplate Identity, systemTemplate System) (*ident
return nil, err
}

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

id.Identity.Type = ptrstring("System")
id.Identity.Internal = &identity.Internal{
id.Identity.Type = "System"
id.Identity.Internal = identity.Internal{
OrgID: id.Identity.OrgID,
}

Expand All @@ -125,7 +125,7 @@ func NewSystemIdentity(identityTemplate Identity, systemTemplate System) (*ident

// NewX509Identity will build and return a fully populated X509 identity record,
// using any values that are present in identityTemplate and x509Template.
func NewX509Identity(identityTemplate Identity, x509Template X509) (*identity.Identity, error) {
func NewX509Identity(identityTemplate Identity, x509Template X509) (*identity.XRHID, error) {
id, err := NewIdentity(identityTemplate)
if err != nil {
return nil, err
Expand All @@ -136,16 +136,16 @@ func NewX509Identity(identityTemplate Identity, x509Template X509) (*identity.Id
return nil, err
}

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

id.Identity.Type = ptrstring("X509")
id.Identity.Type = "X509"

return id, nil
}

// NewUserIdentity will build and return a fully populated User identity record,
// using any values that are present in identityTemplate and userTemplate.
func NewUserIdentity(identityTemplate Identity, userTemplate User) (*identity.Identity, error) {
func NewUserIdentity(identityTemplate Identity, userTemplate User) (*identity.XRHID, error) {
id, err := NewIdentity(identityTemplate)
if err != nil {
return nil, err
Expand All @@ -156,10 +156,10 @@ func NewUserIdentity(identityTemplate Identity, userTemplate User) (*identity.Id
return nil, err
}

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

id.Identity.Type = ptrstring("User")
id.Identity.Internal = &identity.Internal{
id.Identity.Type = "User"
id.Identity.Internal = identity.Internal{
OrgID: id.Identity.OrgID,
}

Expand Down
2 changes: 1 addition & 1 deletion identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
"github.com/redhatinsights/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

func TestNewIdentity(t *testing.T) {
Expand All @@ -22,7 +22,7 @@
seed: 100,
input: Identity{},
want: &identity.Identity{
Identity: struct {

Check failure on line 25 in identity_test.go

View workflow job for this annotation

GitHub Actions / Build (1.18)

unknown field 'Identity' in struct literal of type identity.Identity
AccountNumber *string "json:\"account_number,omitempty\""
Associate *identity.Associate "json:\"associate,omitempty\""
AuthType string "json:\"auth_type,omitempty\""
Expand Down Expand Up @@ -54,7 +54,7 @@
AccountNumber: ptrstring("1234"),
},
want: &identity.Identity{
Identity: struct {

Check failure on line 57 in identity_test.go

View workflow job for this annotation

GitHub Actions / Build (1.18)

unknown field 'Identity' in struct literal of type identity.Identity
AccountNumber *string "json:\"account_number,omitempty\""
Associate *identity.Associate "json:\"associate,omitempty\""
AuthType string "json:\"auth_type,omitempty\""
Expand Down Expand Up @@ -90,7 +90,7 @@
Type: ptrstring("universal"),
},
want: &identity.Identity{
Identity: struct {

Check failure on line 93 in identity_test.go

View workflow job for this annotation

GitHub Actions / Build (1.18)

unknown field 'Identity' in struct literal of type identity.Identity
AccountNumber *string "json:\"account_number,omitempty\""
Associate *identity.Associate "json:\"associate,omitempty\""
AuthType string "json:\"auth_type,omitempty\""
Expand Down
12 changes: 6 additions & 6 deletions internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package xrhidgen

import (
"github.com/pioz/faker"
"github.com/redhatinsights/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

// Internal holds values to be used as input when generating an internal
// identity record.
type Internal struct {
AuthTime *float64
AuthTime *float32
CrossAccess *bool
OrgID *string
}
Expand All @@ -19,15 +19,15 @@ func NewInternal(template Internal) (*identity.Internal, error) {
var id identity.Internal

if template.AuthTime != nil {
id.AuthTime = template.AuthTime
id.AuthTime = *template.AuthTime
} else {
id.AuthTime = ptrfloat64(float64(faker.Duration()))
id.AuthTime = float32(faker.Duration())
}

if template.CrossAccess != nil {
id.CrossAccess = template.CrossAccess
id.CrossAccess = *template.CrossAccess
} else {
id.CrossAccess = ptrbool(faker.Bool())
id.CrossAccess = faker.Bool()
}

if template.OrgID != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pioz/faker"
"github.com/redhatinsights/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

func TestNewInternal(t *testing.T) {
Expand All @@ -22,8 +22,8 @@
seed: 100,
input: Internal{},
want: &identity.Internal{
AuthTime: ptrfloat64(-1.6924639230312625e+18),

Check failure on line 25 in internal_test.go

View workflow job for this annotation

GitHub Actions / Build (1.18)

cannot use ptrfloat64(-1.6924639230312625e+18) (value of type *float64) as type float32 in struct literal
CrossAccess: ptrbool(true),

Check failure on line 26 in internal_test.go

View workflow job for this annotation

GitHub Actions / Build (1.18)

cannot use ptrbool(true) (value of type *bool) as type bool in struct literal
OrgID: "00229",
},
},
Expand All @@ -31,11 +31,11 @@
description: "partial template",
seed: 100,
input: Internal{
AuthTime: ptrfloat64(1.0),

Check failure on line 34 in internal_test.go

View workflow job for this annotation

GitHub Actions / Build (1.18)

cannot use ptrfloat64(1.0) (value of type *float64) as type *float32 in struct literal
},
want: &identity.Internal{
AuthTime: ptrfloat64(1.0),

Check failure on line 37 in internal_test.go

View workflow job for this annotation

GitHub Actions / Build (1.18)

cannot use ptrfloat64(1.0) (value of type *float64) as type float32 in struct literal
CrossAccess: ptrbool(false),

Check failure on line 38 in internal_test.go

View workflow job for this annotation

GitHub Actions / Build (1.18)

cannot use ptrbool(false) (value of type *bool) as type bool in struct literal
OrgID: "80022",
},
},
Expand All @@ -43,12 +43,12 @@
description: "full template",
seed: 100,
input: Internal{
AuthTime: ptrfloat64(2.0),

Check failure on line 46 in internal_test.go

View workflow job for this annotation

GitHub Actions / Build (1.18)

cannot use ptrfloat64(2.0) (value of type *float64) as type *float32 in struct literal
CrossAccess: ptrbool(true),
OrgID: ptrstring("123456"),
},
want: &identity.Internal{
AuthTime: ptrfloat64(2.0),

Check failure on line 51 in internal_test.go

View workflow job for this annotation

GitHub Actions / Build (1.18)

cannot use ptrfloat64(2.0) (value of type *float64) as type float32 in struct literal
CrossAccess: ptrbool(true),
OrgID: "123456",
},
Expand Down
14 changes: 7 additions & 7 deletions system.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package xrhidgen

import (
"github.com/pioz/faker"
"github.com/redhatinsights/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

// System holds values to be used as input when generating a system identity
Expand All @@ -19,21 +19,21 @@ func NewSystem(template System) (*identity.System, error) {
var id identity.System

if template.CertType != nil {
id.CertType = template.CertType
id.CertType = *template.CertType
} else {
id.CertType = ptrstring(faker.Pick("", "consumer", "system"))
id.CertType = faker.Pick("", "consumer", "system")
}

if template.ClusterID != nil {
id.ClusterID = template.ClusterID
id.ClusterId = *template.ClusterID
} else {
id.ClusterID = ptrstring(faker.String())
id.ClusterId = faker.String()
}

if template.CN != nil {
id.CN = *template.CN
id.CommonName = *template.CN
} else {
id.CN = faker.String()
id.CommonName = faker.String()
}

return &id, nil
Expand Down
2 changes: 1 addition & 1 deletion system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

func TestNewSystem(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package xrhidgen

import (
"github.com/pioz/faker"
"github.com/redhatinsights/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

// User holds values to be used as input when generating a user identity record.
Expand Down Expand Up @@ -36,21 +36,21 @@ func NewUser(template User) (*identity.User, error) {
}

if template.IsActive != nil {
id.IsActive = *template.IsActive
id.Active = *template.IsActive
} else {
id.IsActive = faker.Bool()
id.Active = faker.Bool()
}

if template.IsInternal != nil {
id.IsInternal = *template.IsInternal
id.Internal = *template.IsInternal
} else {
id.IsInternal = faker.Bool()
id.Internal = faker.Bool()
}

if template.IsOrgAdmin != nil {
id.IsOrgAdmin = *template.IsOrgAdmin
id.OrgAdmin = *template.IsOrgAdmin
} else {
id.IsOrgAdmin = faker.Bool()
id.OrgAdmin = faker.Bool()
}

if template.LastName != nil {
Expand Down
2 changes: 1 addition & 1 deletion user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

func TestNewUser(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion x509.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package xrhidgen

import (
"github.com/pioz/faker"
"github.com/redhatinsights/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

// X509 holds values to be used as input when generating an x509 identity
Expand Down
2 changes: 1 addition & 1 deletion x509_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/module-update-router/identity"
"github.com/redhatinsights/platform-go-middlewares/identity"
)

func TestNewX509(t *testing.T) {
Expand Down
Loading