-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
424 changed files
with
14,379 additions
and
5,992 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package api | ||
|
||
// Authorization contains authorization configuration. | ||
type Authorization struct { | ||
AdminList map[string]struct{} | ||
Enabled bool | ||
AllowedContactTypes map[string]struct{} | ||
} | ||
|
||
// IsEnabled returns true if auth is enabled and false otherwise. | ||
func (auth *Authorization) IsEnabled() bool { | ||
return auth.Enabled | ||
} | ||
|
||
// IsAdmin checks whether given user is considered an administrator. | ||
func (auth *Authorization) IsAdmin(login string) bool { | ||
if !auth.IsEnabled() { | ||
return false | ||
} | ||
_, ok := auth.AdminList[login] | ||
return ok | ||
} | ||
|
||
// The Role is an enumeration that represents the scope of user's permissions. | ||
type Role string | ||
|
||
var ( | ||
RoleUndefined Role = "" | ||
RoleUser Role = "user" | ||
RoleAdmin Role = "admin" | ||
) | ||
|
||
// Returns the role of the given user. | ||
func (auth *Authorization) GetRole(login string) Role { | ||
if !auth.IsEnabled() { | ||
return RoleUndefined | ||
} | ||
if auth.IsAdmin(login) { | ||
return RoleAdmin | ||
} | ||
return RoleUser | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,62 @@ | ||
package api | ||
|
||
import "time" | ||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/moira-alert/moira" | ||
) | ||
|
||
// WebContact is container for web ui contact validation. | ||
type WebContact struct { | ||
ContactType string `json:"type" example:"webhook"` | ||
ContactLabel string `json:"label" example:"Webhook"` | ||
LogoURI string `json:"logo_uri,omitempty" example:"discord-logo.svg"` | ||
ValidationRegex string `json:"validation,omitempty" example:"^(http|https):\\/\\/.*(moira.ru)(:[0-9]{2,5})?\\/"` | ||
Placeholder string `json:"placeholder,omitempty" example:"https://moira.ru/webhooks"` | ||
Help string `json:"help,omitempty" example:"### Domains whitelist:\n - moira.ru\n"` | ||
} | ||
|
||
// FeatureFlags is struct to manage feature flags. | ||
type FeatureFlags struct { | ||
IsPlottingDefaultOn bool `json:"isPlottingDefaultOn" example:"false"` | ||
IsPlottingAvailable bool `json:"isPlottingAvailable" example:"true"` | ||
IsSubscriptionToAllTagsAvailable bool `json:"isSubscriptionToAllTagsAvailable" example:"false"` | ||
IsReadonlyEnabled bool `json:"isReadonlyEnabled" example:"false"` | ||
} | ||
|
||
// Sentry - config for sentry settings. | ||
type Sentry struct { | ||
DSN string `json:"dsn,omitempty" example:"https://[email protected]"` | ||
Platform string `json:"platform,omitempty" example:"dev"` | ||
} | ||
|
||
// Config for api configuration variables. | ||
type Config struct { | ||
EnableCORS bool | ||
Listen string | ||
GraphiteLocalMetricTTL time.Duration | ||
GraphiteRemoteMetricTTL time.Duration | ||
PrometheusRemoteMetricTTL time.Duration | ||
EnableCORS bool | ||
Listen string | ||
MetricsTTL map[moira.ClusterKey]time.Duration | ||
Flags FeatureFlags | ||
Authorization Authorization | ||
} | ||
|
||
// WebConfig is container for web ui configuration parameters. | ||
type WebConfig struct { | ||
SupportEmail string `json:"supportEmail,omitempty"` | ||
RemoteAllowed bool `json:"remoteAllowed"` | ||
Contacts []WebContact `json:"contacts"` | ||
FeatureFlags FeatureFlags `json:"featureFlags"` | ||
SupportEmail string `json:"supportEmail,omitempty" example:"[email protected]"` | ||
RemoteAllowed bool `json:"remoteAllowed" example:"true"` | ||
MetricSourceClusters []MetricSourceCluster `json:"metric_source_clusters"` | ||
Contacts []WebContact `json:"contacts"` | ||
FeatureFlags FeatureFlags `json:"featureFlags"` | ||
Sentry Sentry `json:"sentry"` | ||
} | ||
|
||
// WebContact is container for web ui contact validation. | ||
type WebContact struct { | ||
ContactType string `json:"type"` | ||
ContactLabel string `json:"label"` | ||
ValidationRegex string `json:"validation,omitempty"` | ||
Placeholder string `json:"placeholder,omitempty"` | ||
Help string `json:"help,omitempty"` | ||
// MetricSourceCluster contains data about supported metric source cluster. | ||
type MetricSourceCluster struct { | ||
TriggerSource moira.TriggerSource `json:"trigger_source" example:"graphite_remote"` | ||
ClusterId moira.ClusterId `json:"cluster_id" example:"default"` | ||
ClusterName string `json:"cluster_name" example:"Graphite Remote Prod"` | ||
} | ||
|
||
// FeatureFlags is struct to manage feature flags. | ||
type FeatureFlags struct { | ||
IsPlottingDefaultOn bool `json:"isPlottingDefaultOn"` | ||
IsPlottingAvailable bool `json:"isPlottingAvailable"` | ||
IsSubscriptionToAllTagsAvailable bool `json:"isSubscriptionToAllTagsAvailable"` | ||
func (WebConfig) Render(w http.ResponseWriter, r *http.Request) error { | ||
return nil | ||
} |
Oops, something went wrong.