mirror of https://github.com/grafana/grafana
AuthN: Use tokens for unified storage server authentication (#95086)
* Extract server code --------- Co-authored-by: Claudiu Dragalina-Paraipan <drclau@users.noreply.github.com>pull/95254/head
parent
9ab064bfc5
commit
b68b69c2b4
@ -0,0 +1,45 @@ |
||||
package grpcutils |
||||
|
||||
import ( |
||||
"fmt" |
||||
|
||||
"github.com/grafana/grafana/pkg/setting" |
||||
) |
||||
|
||||
type Mode string |
||||
|
||||
func (s Mode) IsValid() bool { |
||||
switch s { |
||||
case ModeOnPrem, ModeCloud: |
||||
return true |
||||
} |
||||
return false |
||||
} |
||||
|
||||
const ( |
||||
ModeOnPrem Mode = "on-prem" |
||||
ModeCloud Mode = "cloud" |
||||
) |
||||
|
||||
type GrpcServerConfig struct { |
||||
SigningKeysURL string |
||||
AllowedAudiences []string |
||||
Mode Mode |
||||
LegacyFallback bool |
||||
} |
||||
|
||||
func ReadGrpcServerConfig(cfg *setting.Cfg) (*GrpcServerConfig, error) { |
||||
section := cfg.SectionWithEnvOverrides("grpc_server_authentication") |
||||
|
||||
mode := Mode(section.Key("mode").MustString(string(ModeOnPrem))) |
||||
if !mode.IsValid() { |
||||
return nil, fmt.Errorf("grpc_server_authentication: invalid mode %q", mode) |
||||
} |
||||
|
||||
return &GrpcServerConfig{ |
||||
SigningKeysURL: section.Key("signing_keys_url").MustString(""), |
||||
AllowedAudiences: section.Key("allowed_audiences").Strings(","), |
||||
Mode: mode, |
||||
LegacyFallback: section.Key("legacy_fallback").MustBool(true), |
||||
}, nil |
||||
} |
Loading…
Reference in new issue