|
package auth
import (
"fmt"
"net/url"
"strings"
"github.com/rs/zerolog/log"
)
|
RBACConfig holds the configuration for RBAC settings.
|
type RBACConfig struct {
URL string `mapstructure:"url" toml:"url"`
EnforceAuth bool `mapstructure:"enforce" toml:"enforce"`
}
|
constructRBACURL constructs the RBAC URL with the query parameters for checking
access to Advisor OCP resources. It takes an RBACConfig and returns the
constructed base URL, host, and any error encountered.
|
func constructRBACURL ( config * RBACConfig ) ( string , string , error ) {
if ! strings . HasPrefix ( config . URL , "http://" ) && ! strings . HasPrefix ( config . URL , "https://" ) {
config . URL = "https://" + config . URL
}
|
Parse the URL to handle both the Host and the Endpoint correctly
|
baseURL , err := url . Parse ( config . URL )
if err != nil {
return "" , "" , fmt . Errorf ( "invalid host format: %v" , err )
}
|
Add the /access/ endpoint and ocp-advisor parameter
|
baseURL . Path += "/access/"
params := url . Values { }
params . Add ( "application" , "ocp-advisor" )
params . Add ( "limit" , "100" )
uri := fmt . Sprintf ( "%s?%s" , baseURL , params . Encode ( ) )
log . Info ( ) . Str ( "RBAC URL:" , uri ) . Send ( )
return uri , baseURL . Host , nil
}
|