Documentation ¶
Overview ¶
Package server contains implementation of REST API server (HTTPServer) for the Insights results smart proxy service. In current version, the following
Please note that API_PREFIX is part of server configuration (see Configuration). Also please note that JSON format is used to transfer data between server and clients.
Index ¶
- Constants
- func ValidateRequestID(requestID string) (types.RequestID, error)
- type AMSAPIUnavailableError
- type AggregatorServiceUnavailableError
- type AuthenticationError
- type BadBodyContent
- type Configuration
- type ContentServiceUnavailableError
- type HTTPServer
- func (server *HTTPServer) Authentication(next http.Handler, noAuthURLs []string) http.Handler
- func (server *HTTPServer) GetAuthToken(request *http.Request) (*types.Identity, error)
- func (server *HTTPServer) GetCurrentOrgID(request *http.Request) (types.OrgID, error)
- func (server *HTTPServer) GetCurrentOrgIDUserIDFromToken(request *http.Request) (types.OrgID, types.UserID, error)
- func (server *HTTPServer) GetCurrentUserID(request *http.Request) (types.UserID, error)
- func (server *HTTPServer) Initialize() http.Handler
- func (server HTTPServer) SetAMSInfoInReport(clusterID types.ClusterName, report *types.SmartProxyReportV2)
- func (server *HTTPServer) Start() error
- func (server *HTTPServer) Stop(ctx context.Context) error
- type NoBodyError
- type ParamsParsingError
- type ProxyOptions
- type RequestModifier
- type ResponseModifier
- type RouterMissingParamError
- type RouterParsingError
- type UpgradesDataEngServiceUnavailableError
Constants ¶
const ( // JWTAuthTokenHeader reprsents the name of the header used in JWT authorization type // #nosec G101 JWTAuthTokenHeader = "Authorization" // XRHAuthTokenHeader reprsents the name of the header used in XRH authorization type // #nosec G101 XRHAuthTokenHeader = "x-rh-identity" )
const ( // DbgOrganizationsEndpoint returns all organizations. DEBUG only DbgOrganizationsEndpoint = ira_server.OrganizationsEndpoint // DbgDeleteOrganizationsEndpoint deletes all {organizations}(comma separated array). DEBUG only DbgDeleteOrganizationsEndpoint = ira_server.DeleteOrganizationsEndpoint // DbgDeleteClustersEndpoint deletes all {clusters}(comma separated array). DEBUG only DbgDeleteClustersEndpoint = ira_server.DeleteClustersEndpoint // DbgGetVoteOnRuleEndpoint is an endpoint to get vote on rule. DEBUG only DbgGetVoteOnRuleEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/get_vote" )
const ( // MainEndpoint returns status ok MainEndpoint = "" // OldReportEndpoint is made for backwards compatibility// TODO: remove when UI fixes are merged OldReportEndpoint = "report/{org_id}/{cluster}" // ReportEndpoint returns report for provided {cluster} ReportEndpoint = "clusters/{cluster}/report" // ReportMetainfoEndpoint returns (meta)information about report for provided {cluster} ReportMetainfoEndpoint = "clusters/{cluster}/report/info" // ReportForListOfClustersEndpoint returns rule returns reports for provided list of clusters // Reports that are going to be returned are specified by list of cluster IDs that is part of path ReportForListOfClustersEndpoint = "clusters/{cluster_list}/reports" // ReportForListOfClustersPayloadEndpoint returns the latest reports for the given list of clusters // Reports that are going to be returned are specified by list of cluster IDs that is part of request body ReportForListOfClustersPayloadEndpoint = "clusters/reports" // RuleGroupsEndpoint is a simple redirect endpoint to the insights-content-service API specified in configuration RuleGroupsEndpoint = "groups" // RuleContent returns static content for {rule_id} RuleContent = "rules/{rule_id}/content" // RuleIDs returns a list of rule IDs RuleIDs = "rule_ids" // Content returns all the static content available for the user Content = "content" // SingleRuleEndpoint returns single rule with static content for {cluster} and {rule_id} SingleRuleEndpoint = "clusters/{cluster}/rules/{rule_id}/report" // MetricsEndpoint returns prometheus metrics MetricsEndpoint = "metrics" // LikeRuleEndpoint likes rule with {rule_id} for {cluster} using current user(from auth header) LikeRuleEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/like" // DislikeRuleEndpoint dislikes rule with {rule_id} for {cluster} using current user(from auth header) DislikeRuleEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/dislike" // ResetVoteOnRuleEndpoint resets vote on rule with {rule_id} for {cluster} using current user(from auth header) ResetVoteOnRuleEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/reset_vote" // GetVoteOnRuleEndpoint is an endpoint to get vote on rule. DEBUG only GetVoteOnRuleEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/get_vote" // DisableRuleForClusterEndpoint disables a rule for specified cluster DisableRuleForClusterEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/disable" // EnableRuleForClusterEndpoint re-enables a rule for specified cluster EnableRuleForClusterEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/enable" // DisableRuleFeedbackEndpoint accepts a feedback from user when (s)he disables a rule DisableRuleFeedbackEndpoint = "clusters/{cluster}/rules/{rule_id}/error_key/{error_key}/disable_feedback" // OverviewEndpoint returns some overview data for the clusters belonging to the org id OverviewEndpoint = "org_overview" // ClustersForOrganizationEndpoint returns all clusters for {organization} ClustersForOrganizationEndpoint = ira_server.ClustersForOrganizationEndpoint // OrganizationsEndpoint returns all organizations OrganizationsEndpoint = ira_server.OrganizationsEndpoint // DeleteOrganizationsEndpoint deletes all {organizations}(comma separated array). DEBUG only DeleteOrganizationsEndpoint = ira_server.DeleteOrganizationsEndpoint // DeleteClustersEndpoint deletes all {clusters}(comma separated array). DEBUG only DeleteClustersEndpoint = ira_server.DeleteClustersEndpoint // InfoEndpoint returns basic information about content service // version, utils repository version, commit hash etc. InfoEndpoint = "info" )
const ( // ReportEndpointV2 https://issues.redhat.com/browse/CCXDEV-5097 ReportEndpointV2 = "cluster/{cluster}/reports" // ClusterInfoEndpoint provides information about given cluster retrieved from AMS API ClusterInfoEndpoint = "cluster/{cluster}/info" // UpgradeRisksPredictionEndpoint returns the prediction about upgrading // the given cluster. UpgradeRisksPredictionEndpoint = "cluster/{cluster}/upgrade-risks-prediction" // ClustersDetail https://issues.redhat.com/browse/CCXDEV-5088 ClustersDetail = "rule/{rule_selector}/clusters_detail" // RecommendationsListEndpoint lists all recommendations with a number of impacted clusters. RecommendationsListEndpoint = "rule" // ClustersRecommendationsEndpoint returns a list of all clusters, number of impacting rules and number of rules by total risk ClustersRecommendationsEndpoint = "clusters" // RuleContentV2 https://issues.redhat.com/browse/CCXDEV-5094 // additionally group info is added too // https://github.com/RedHatInsights/insights-results-smart-proxy/pull/604 RuleContentV2 = "rule/{rule_id}/content" // RuleContentWithUserData returns same as RuleContentV2, but includes user-specific data RuleContentWithUserData = "rule/{rule_id}" // ContentV2 returns all the static content available for the user ContentV2 = "content" // ListAllRequestIDs should return list of all request IDs detected for // given cluster. In reality the list is refreshing as old request IDs // are forgotten after 24 hours ListAllRequestIDs = "cluster/{cluster}/requests" // StatusOfRequestID should return status of processing one given // request ID StatusOfRequestID = "cluster/{cluster}/request/{request_id}/status" // RuleHitsForRequestID should return simplified results for given // cluster and requestID RuleHitsForRequestID = "cluster/{cluster}/request/{request_id}/report" // AckListEndpoint list acks from this account where the rule is // active. Will return an empty list if this account has no acks. AckListEndpoint = "ack" // AckGetEndpoint read the acknowledgement info about disabled rule. // Acks are created, deleted, and queried by Insights rule ID, not // by their own ack ID. AckGetEndpoint = "ack/{rule_id}" // AckAcknowledgePostEndpoint acknowledges (and therefore hides) a rule // from view in an account. If there's already an acknowledgement of // this rule by this account, then return that. Otherwise, a new ack is // created. AckAcknowledgePostEndpoint = "ack" // AckUpdateEndpoint updates an acknowledgement for a rule, by rule ID. // A new justification can be supplied. The username is taken from the // authenticated request. The updated ack is returned. AckUpdateEndpoint = "ack/{rule_id}" // AckDeleteEndpoint deletes an acknowledgement for a rule, by its rule // ID. If the ack existed, it is deleted and a 204 is returned. // Otherwise, a 404 is returned. AckDeleteEndpoint = "ack/{rule_id}" // Rating endpoint will get/modify the vote for a rule id by the user Rating = "rating" )
const ( // OnlyImpacting flag to only return impacting recommendations on GET /rule/ OnlyImpacting = iota // IncludingImpacting flag to return all recommendations including impacting ones on GET /rule/ IncludingImpacting // ExcludingImpacting flag to return all recommendations excluding impacting ones on GET /rule/ ExcludingImpacting // OkMsg is in status field with HTTP 200 response OkMsg = "ok" // StatusProcessed is a message returned for already processed reports stored in Redis StatusProcessed = "processed" // RequestsForClusterNotFound is a message returned when no request IDs were found for a given clusterID RequestsForClusterNotFound = "Requests for cluster not found" // RequestIDNotFound is returned when the requested request ID was not found in the list of request IDs // for given cluster RequestIDNotFound = "Request ID not found for given org_id and cluster_id" // RedisNotInitializedErrorMessage is an error message written into log when Redis client is not initialized properly RedisNotInitializedErrorMessage = "Redis is not initialized, request can not be finished correctly" )
const ( // OSDEligibleParam parameter OSDEligibleParam = "osd_eligible" // GetDisabledParam parameter GetDisabledParam = "get_disabled" // ImpactingParam parameter used to show/hide recommendations not hitting any clusters ImpactingParam = "impacting" // RuleIDParamName parameter name in the URL RuleIDParamName = "rule_id" // RequestIDParam parameter name in the URL for request IDs RequestIDParam = "request_id" )
const (
// JSONContentType represents the application/json content type
JSONContentType = "application/json; charset=utf-8"
)
const UpgradeRisksPredictionServiceEndpoint = "cluster/{cluster}/upgrade-risks-prediction"
UpgradeRisksPredictionServiceEndpoint endpoint for the upgrade prediction service
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AMSAPIUnavailableError ¶
type AMSAPIUnavailableError struct{}
AMSAPIUnavailableError error is used when AMS API is not available and is the only source of data
func (*AMSAPIUnavailableError) Error ¶
func (*AMSAPIUnavailableError) Error() string
type AggregatorServiceUnavailableError ¶
type AggregatorServiceUnavailableError struct{}
AggregatorServiceUnavailableError error is used when the aggregator service cannot be reached
func (*AggregatorServiceUnavailableError) Error ¶
func (*AggregatorServiceUnavailableError) Error() string
type AuthenticationError ¶
type AuthenticationError struct {
ErrString string
}
AuthenticationError happens during auth problems, for example malformed token
func (*AuthenticationError) Error ¶
func (e *AuthenticationError) Error() string
type BadBodyContent ¶
type BadBodyContent struct{}
BadBodyContent error meaning that client didn't provide a meaningful body content when it's required
func (*BadBodyContent) Error ¶
func (*BadBodyContent) Error() string
type Configuration ¶
type Configuration struct { Address string `mapstructure:"address" toml:"address"` APIdbgPrefix string `mapstructure:"api_dbg_prefix" toml:"api_dbg_prefix"` APIv1Prefix string `mapstructure:"api_v1_prefix" toml:"api_v1_prefix"` APIv2Prefix string `mapstructure:"api_v2_prefix" toml:"api_v2_prefix"` APIv1SpecFile string `mapstructure:"api_v1_spec_file" toml:"api_v1_spec_file"` APIv2SpecFile string `mapstructure:"api_v2_spec_file" toml:"api_v2_spec_file"` Debug bool `mapstructure:"debug" toml:"debug"` Auth bool `mapstructure:"auth" toml:"auth"` AuthType string `mapstructure:"auth_type" toml:"auth_type"` UseHTTPS bool `mapstructure:"use_https" toml:"use_https"` EnableCORS bool `mapstructure:"enable_cors" toml:"enable_cors"` EnableInternalRulesOrganizations bool `mapstructure:"enable_internal_rules_organizations" toml:"enable_internal_rules_organizations"` InternalRulesOrganizations []types.OrgID `mapstructure:"internal_rules_organizations" toml:"internal_rules_organizations"` LogAuthToken bool `mapstructure:"log_auth_token" toml:"log_auth_token"` UseOrgClustersFallback bool `mapstructure:"org_clusters_fallback" toml:"org_clusters_fallback"` }
Configuration represents configuration of REST API HTTP server
type ContentServiceUnavailableError ¶
type ContentServiceUnavailableError struct{}
ContentServiceUnavailableError error is used when the content service cannot be reached
func (*ContentServiceUnavailableError) Error ¶
func (*ContentServiceUnavailableError) Error() string
type HTTPServer ¶
type HTTPServer struct { Config Configuration InfoParams map[string]string ServicesConfig services.Configuration GroupsChannel chan []groups.Group ErrorFoundChannel chan bool ErrorChannel chan error Serv *http.Server // contains filtered or unexported fields }
HTTPServer is an implementation of Server interface
func New ¶
func New(config Configuration, servicesConfig services.Configuration, amsClient amsclient.AMSClient, redis services.RedisInterface, groupsChannel chan []groups.Group, errorFoundChannel chan bool, errorChannel chan error, ) *HTTPServer
New function constructs new implementation of Server interface.
func (*HTTPServer) Authentication ¶
Authentication middleware for checking auth rights
func (*HTTPServer) GetAuthToken ¶
GetAuthToken returns current authentication token
func (*HTTPServer) GetCurrentOrgID ¶
GetCurrentOrgID retrieves the ID of the organization the user belongs to
func (*HTTPServer) GetCurrentOrgIDUserIDFromToken ¶
func (server *HTTPServer) GetCurrentOrgIDUserIDFromToken(request *http.Request) ( types.OrgID, types.UserID, error, )
GetCurrentOrgIDUserIDFromToken retrieves the ID of the organization the user belongs to and the ID of the specific user
func (*HTTPServer) GetCurrentUserID ¶
GetCurrentUserID retrieves current user's id from request
func (*HTTPServer) Initialize ¶
func (server *HTTPServer) Initialize() http.Handler
Initialize method performs the server initialization, including registration of all handlers.
func (HTTPServer) SetAMSInfoInReport ¶
func (server HTTPServer) SetAMSInfoInReport(clusterID types.ClusterName, report *types.SmartProxyReportV2)
SetAMSInfoInReport tries to retrieve the display name and managed status of the cluster using the configured AMS client. If no info is retrieved, it sets the cluster's external ID as display name.
func (*HTTPServer) Start ¶
func (server *HTTPServer) Start() error
Start method starts HTTP or HTTPS server.
type NoBodyError ¶
type NoBodyError struct{}
NoBodyError error meaning that client didn't provide body when it's required
func (*NoBodyError) Error ¶
func (*NoBodyError) Error() string
type ParamsParsingError ¶
type ParamsParsingError struct{}
ParamsParsingError error meaning that the cluster name cannot be handled
func (*ParamsParsingError) Error ¶
func (*ParamsParsingError) Error() string
type ProxyOptions ¶
type ProxyOptions struct { RequestModifiers []RequestModifier ResponseModifiers []ResponseModifier }
ProxyOptions alters behaviour of proxy server for each endpoint. For example, you can set custom request and response modifiers
type RequestModifier ¶
RequestModifier is a type of function which modifies request when proxying
type ResponseModifier ¶
ResponseModifier is a type of function which modifies response when proxying
type RouterMissingParamError ¶
type RouterMissingParamError struct {
ParamName string
}
RouterMissingParamError missing parameter in request
func (*RouterMissingParamError) Error ¶
func (e *RouterMissingParamError) Error() string
type RouterParsingError ¶
RouterParsingError parsing error, for example string when we expected integer
func (*RouterParsingError) Error ¶
func (e *RouterParsingError) Error() string
type UpgradesDataEngServiceUnavailableError ¶
type UpgradesDataEngServiceUnavailableError struct{}
UpgradesDataEngServiceUnavailableError error is used when the ccx-upgrades-data-eng service cannot be reached
func (*UpgradesDataEngServiceUnavailableError) Error ¶
func (*UpgradesDataEngServiceUnavailableError) Error() string