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

add PublicViewerConfig utils #377

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/codeready-toolchain/api => github.com/filariow/toolchain-api v0.0.0-20240325174729-ac271dff1ebc
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWH
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/codeready-toolchain/api v0.0.0-20240322110702-5ab3840476e9 h1:Lm7bFLrzfJzrUiRGVqtsSaZMpj+akLiR/fvAFjjE9gM=
github.com/codeready-toolchain/api v0.0.0-20240322110702-5ab3840476e9/go.mod h1:cfNN6YPX4TORvhhZXMSjSPesqAHlB3nD/WAfGe4WLKQ=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down Expand Up @@ -168,6 +166,8 @@ github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwo
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/filariow/toolchain-api v0.0.0-20240325174729-ac271dff1ebc h1:8zXVcHEShpnB7JMdj9S3UJR6DVwxOvkkeJRTJinr3YE=
github.com/filariow/toolchain-api v0.0.0-20240325174729-ac271dff1ebc/go.mod h1:cfNN6YPX4TORvhhZXMSjSPesqAHlB3nD/WAfGe4WLKQ=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down
25 changes: 25 additions & 0 deletions pkg/configuration/publicviewer_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package configuration

import (
toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
)

type PublicViewerConfig struct {
Config toolchainv1alpha1.PublicViewerConfig
}

func (c PublicViewerConfig) Enabled() bool {
return c.Config.Enabled

Check warning on line 12 in pkg/configuration/publicviewer_config.go

View check run for this annotation

Codecov / codecov/patch

pkg/configuration/publicviewer_config.go#L11-L12

Added lines #L11 - L12 were not covered by tests
}

func (c PublicViewerConfig) Username() string {
return c.Config.Username

Check warning on line 16 in pkg/configuration/publicviewer_config.go

View check run for this annotation

Codecov / codecov/patch

pkg/configuration/publicviewer_config.go#L15-L16

Added lines #L15 - L16 were not covered by tests
}

func (c PublicViewerConfig) IsPublicViewer(username string) bool {
if !c.Enabled() {
return false

Check warning on line 21 in pkg/configuration/publicviewer_config.go

View check run for this annotation

Codecov / codecov/patch

pkg/configuration/publicviewer_config.go#L19-L21

Added lines #L19 - L21 were not covered by tests
}

return c.Config.Username == username

Check warning on line 24 in pkg/configuration/publicviewer_config.go

View check run for this annotation

Codecov / codecov/patch

pkg/configuration/publicviewer_config.go#L24

Added line #L24 was not covered by tests
}
Comment on lines +19 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check that c.Config.Username is not empty ? I mean could it happen that we enable the config without setting a username? WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the RegEx validation should prevent this from happening

// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`

Copy link
Contributor Author

@filariow filariow Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, you're right, this can happen. Let me look into that more, great catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this approach could help also here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As pointed out in the comment codeready-toolchain/host-operator#998 (comment) , I would remove the field.

Loading