http

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

* * Copyright 2021 Comcast Cable Communications Management, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	Boundary           = "2xKIxjfJuErFW+hmNCwEoMoY8I+ECM9efrV6EI4efSSW9QjI"
	Linebreak          = '\n'
	MsgpackContentType = "Content-type: application/msgpack\r\n"
)
View Source
const (
	OkResponseTemplate    = `{"status":200,"message":"OK","data":%v}`
	TR181ResponseTemplate = `{"parameters":%v,"version":"%v"}`
)
View Source
const (
	LevelWarn = iota
	LevelInfo
	LevelDebug
	MetricsEnabledDefault      = true
	FactoryResetEnabledDefault = false
)
View Source
const AppName = "webconfig"

Variables

View Source
var (
	FirstLineBoundary    = fmt.Sprintf("--%s\r\n", Boundary)
	LineBoundary         = fmt.Sprintf("\r\n--%s\r\n", Boundary)
	LastLineBoundary     = fmt.Sprintf("\r\n--%s--\r\n", Boundary)
	MultipartContentType = fmt.Sprintf("multipart/mixed; boundary=%s", Boundary)
)
View Source
var (
	PokeBody = []byte(`{"parameters":[{"dataType":0,"name":"Device.X_RDK_WebConfig.ForceSync","value":"root"}]}`)
)

Functions

func Error

func Error(w http.ResponseWriter, r *http.Request, status int, err error)

func GetUrlPattern

func GetUrlPattern(url string) string

func LogError

func LogError(w http.ResponseWriter, r *http.Request, err error)

func NewTlsConfig

func NewTlsConfig(conf *configuration.Config) (*tls.Config, error)

func Validate

func Validate(w http.ResponseWriter, r *http.Request, validateBody bool) (string, string, []byte, log.Fields, error)

func WebMetrics

func WebMetrics(m *AppMetrics, next http.Handler) http.Handler

func WriteContentTypeAndResponse

func WriteContentTypeAndResponse(w http.ResponseWriter, r *http.Request, rbytes []byte, version string, contentType string)

this is used to return default tr-181 payload while the cpe is not in the db

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, r *http.Request, status int, err error)

helper function to write a failure json response into ResponseWriter

func WriteFactoryResetResponse

func WriteFactoryResetResponse(w http.ResponseWriter)

func WriteMultipartResponse

func WriteMultipartResponse(w http.ResponseWriter, r *http.Request, o *MultipartOutput)

func WriteOkResponse

func WriteOkResponse(w http.ResponseWriter, r *http.Request, data interface{})

helper function to wirte a json response into ResponseWriter

func WriteOkResponseByTemplate

func WriteOkResponseByTemplate(w http.ResponseWriter, r *http.Request, dataStr string)

func WriteResponseBytes

func WriteResponseBytes(w http.ResponseWriter, r *http.Request, rbytes []byte, statusCode int, vargs ...string)

func WriteTR181Response

func WriteTR181Response(w http.ResponseWriter, r *http.Request, params string, version string)

Types

type AppMetrics

type AppMetrics struct {
	// contains filtered or unexported fields
}

func NewMetrics

func NewMetrics() *AppMetrics

type CodebigConnector

type CodebigConnector struct {
	*HttpClient
	// contains filtered or unexported fields
}

func NewCodebigConnector

func NewCodebigConnector(conf *configuration.Config, satClientId, satClientSecret string, tlsConfig *tls.Config) *CodebigConnector

func (*CodebigConnector) CodebigHost

func (c *CodebigConnector) CodebigHost() string

func (*CodebigConnector) GetToken

func (c *CodebigConnector) GetToken(fields log.Fields, vargs ...string) (string, error)

func (*CodebigConnector) SetCodebigHost

func (c *CodebigConnector) SetCodebigHost(host string)

type CodebigResponse

type CodebigResponse struct {
	AccessToken  string `json:"access_token"`
	ExpiresIn    int    `json:"expires_in"`
	Scope        string `json:"score"`
	TokenType    string `json:"token_type"`
	ResponseCode int    `json:"responseCode"`
	Description  string `json:"description"`
}

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
}

type HttpClient

type HttpClient struct {
	*http.Client
	// contains filtered or unexported fields
}

func NewHttpClient

func NewHttpClient(conf *configuration.Config, serviceName string, tlsConfig *tls.Config) *HttpClient

func (*HttpClient) Do

func (c *HttpClient) Do(method string, url string, headers map[string]string, bbytes []byte, baseFields log.Fields, loggerName string, retry int) ([]byte, error, bool)

func (*HttpClient) DoWithRetries

func (c *HttpClient) DoWithRetries(method string, url string, inHeaders map[string]string, bbytes []byte, fields log.Fields, loggerName string) ([]byte, error)

type MultipartOutput

type MultipartOutput struct {
	// contains filtered or unexported fields
}

func NewMultipartOutput

func NewMultipartOutput(mparts []common.Multipart, rootVersion string) *MultipartOutput

func (*MultipartOutput) Mparts

func (o *MultipartOutput) Mparts() []common.Multipart

func (*MultipartOutput) RootVersion

func (o *MultipartOutput) RootVersion() string

type PostTokenBody

type PostTokenBody struct {
	Mac string `json:"mac"`
	Ttl int64  `json:"ttl"`
}

type WebconfigServer

type WebconfigServer struct {
	*http.Server
	db.DatabaseClient
	*security.TokenManager
	*common.ServerConfig
	*WebpaConnector
	*CodebigConnector
	// contains filtered or unexported fields
}

func NewWebconfigServer

func NewWebconfigServer(sc *common.ServerConfig, testOnly bool, dc db.DatabaseClient) *WebconfigServer

testOnly=true ==> running unit test

func (*WebconfigServer) ApiMiddleware

func (s *WebconfigServer) ApiMiddleware(next http.Handler) http.Handler

Token valid enough

func (*WebconfigServer) CpeMiddleware

func (s *WebconfigServer) CpeMiddleware(next http.Handler) http.Handler

Token valid and mac must match

func (*WebconfigServer) CreateTokenHandler

func (s *WebconfigServer) CreateTokenHandler(w http.ResponseWriter, r *http.Request)

func (*WebconfigServer) DeleteDocumentHandler

func (s *WebconfigServer) DeleteDocumentHandler(w http.ResponseWriter, r *http.Request)

func (*WebconfigServer) DeviceApiTokenAuthEnabled

func (s *WebconfigServer) DeviceApiTokenAuthEnabled() bool

func (*WebconfigServer) FactoryResetEnabled

func (s *WebconfigServer) FactoryResetEnabled() bool

func (*WebconfigServer) GetBaseRouter

func (s *WebconfigServer) GetBaseRouter(testOnly bool) *mux.Router

func (*WebconfigServer) GetDocumentHandler

func (s *WebconfigServer) GetDocumentHandler(w http.ResponseWriter, r *http.Request)

func (*WebconfigServer) GetRouter

func (s *WebconfigServer) GetRouter(testOnly bool) *mux.Router

func (*WebconfigServer) GetSupportedGroupsHandler

func (s *WebconfigServer) GetSupportedGroupsHandler(w http.ResponseWriter, r *http.Request)

XPC-10013 the supported doc header in GET /config is parsed and stored as a bitmap

this API returns the bitmap in read friendly json

func (*WebconfigServer) MetricsEnabled

func (s *WebconfigServer) MetricsEnabled() bool

func (*WebconfigServer) MonitorHandler

func (s *WebconfigServer) MonitorHandler(w http.ResponseWriter, r *http.Request)

func (*WebconfigServer) MultipartConfigHandler

func (s *WebconfigServer) MultipartConfigHandler(w http.ResponseWriter, r *http.Request)

func (*WebconfigServer) NoAuthMiddleware

func (s *WebconfigServer) NoAuthMiddleware(next http.Handler) http.Handler

func (*WebconfigServer) NotLoggedHeaders

func (s *WebconfigServer) NotLoggedHeaders() []string

func (*WebconfigServer) NotificationHandler

func (s *WebconfigServer) NotificationHandler(w http.ResponseWriter, r *http.Request)

func (*WebconfigServer) Poke

func (c *WebconfigServer) Poke(cpeMac string, token string, fields log.Fields) (string, error)

func (*WebconfigServer) PokeHandler

func (s *WebconfigServer) PokeHandler(w http.ResponseWriter, r *http.Request)

func (*WebconfigServer) PostDocumentHandler

func (s *WebconfigServer) PostDocumentHandler(w http.ResponseWriter, r *http.Request)

func (*WebconfigServer) ServerApiTokenAuthEnabled

func (s *WebconfigServer) ServerApiTokenAuthEnabled() bool

func (*WebconfigServer) ServerConfigHandler

func (s *WebconfigServer) ServerConfigHandler(w http.ResponseWriter, r *http.Request)

func (*WebconfigServer) SetDeviceApiTokenAuthEnabled

func (s *WebconfigServer) SetDeviceApiTokenAuthEnabled(enabled bool)

func (*WebconfigServer) SetFactoryResetEnabled

func (s *WebconfigServer) SetFactoryResetEnabled(enabled bool)

func (*WebconfigServer) SetServerApiTokenAuthEnabled

func (s *WebconfigServer) SetServerApiTokenAuthEnabled(enabled bool)

func (*WebconfigServer) SetTokenApiEnabled

func (s *WebconfigServer) SetTokenApiEnabled(enabled bool)

func (*WebconfigServer) TestingCpeMiddleware

func (s *WebconfigServer) TestingCpeMiddleware(next http.Handler) http.Handler

func (*WebconfigServer) TestingMiddleware

func (s *WebconfigServer) TestingMiddleware(next http.Handler) http.Handler

func (*WebconfigServer) TlsConfig

func (s *WebconfigServer) TlsConfig() *tls.Config

func (*WebconfigServer) TokenApiEnabled

func (s *WebconfigServer) TokenApiEnabled() bool

func (*WebconfigServer) VersionHandler

func (s *WebconfigServer) VersionHandler(w http.ResponseWriter, r *http.Request)

type WebpaConnector

type WebpaConnector struct {
	*HttpClient
	// contains filtered or unexported fields
}

func NewWebpaConnector

func NewWebpaConnector(conf *configuration.Config, tlsConfig *tls.Config) *WebpaConnector

func (*WebpaConnector) Patch

func (c *WebpaConnector) Patch(cpeMac string, token string, bbytes []byte, fields log.Fields) (string, error)

func (*WebpaConnector) SetWebpaHost

func (c *WebpaConnector) SetWebpaHost(host string)

func (*WebpaConnector) WebpaHost

func (c *WebpaConnector) WebpaHost() string

type XpcResponseWriter

type XpcResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewXpcResponseWriter

func NewXpcResponseWriter(w http.ResponseWriter, vargs ...interface{}) *XpcResponseWriter

func (*XpcResponseWriter) Audit

func (w *XpcResponseWriter) Audit() log.Fields

func (*XpcResponseWriter) AuditData

func (w *XpcResponseWriter) AuditData(k string) string

func (*XpcResponseWriter) AuditId

func (w *XpcResponseWriter) AuditId() string

func (*XpcResponseWriter) Body

func (w *XpcResponseWriter) Body() string

func (*XpcResponseWriter) LogDebug

func (xw *XpcResponseWriter) LogDebug(r *http.Request, logger string, message string)

func (*XpcResponseWriter) LogInfo

func (xw *XpcResponseWriter) LogInfo(r *http.Request, logger string, message string)

func (*XpcResponseWriter) LogWarn

func (xw *XpcResponseWriter) LogWarn(r *http.Request, logger string, message string)

func (*XpcResponseWriter) Response

func (w *XpcResponseWriter) Response() string

func (*XpcResponseWriter) SetAuditData

func (w *XpcResponseWriter) SetAuditData(k string, v interface{})

func (*XpcResponseWriter) SetBody

func (w *XpcResponseWriter) SetBody(body string)

func (*XpcResponseWriter) SetBodyObfuscated

func (w *XpcResponseWriter) SetBodyObfuscated(obfuscated bool)

func (*XpcResponseWriter) StartTime

func (w *XpcResponseWriter) StartTime() time.Time

func (*XpcResponseWriter) Status

func (w *XpcResponseWriter) Status() int

get/set

func (*XpcResponseWriter) String

func (w *XpcResponseWriter) String() string

func (*XpcResponseWriter) Token

func (w *XpcResponseWriter) Token() string

func (*XpcResponseWriter) TraceId

func (w *XpcResponseWriter) TraceId() string

func (*XpcResponseWriter) Write

func (w *XpcResponseWriter) Write(b []byte) (int, error)

func (*XpcResponseWriter) WriteHeader

func (w *XpcResponseWriter) WriteHeader(status int)

interface/override

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL