MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / getNginxParamsFromStaticFile

Function getNginxParamsFromStaticFile

agent/app/service/nginx_utils.go:198–239  ·  view source on GitHub ↗
(scope dto.NginxKey, newParams []dto.NginxParam)

Source from the content-addressed store, hash-verified

196}
197
198func getNginxParamsFromStaticFile(scope dto.NginxKey, newParams []dto.NginxParam) []dto.NginxParam {
199 var (
200 newConfig = &components.Config{}
201 err error
202 )
203
204 updateScope := "in"
205 switch scope {
206 case dto.SSL:
207 newConfig, err = parser.NewStringParser(string(nginx_conf.SSL)).Parse()
208 case dto.CACHE:
209 newConfig, err = parser.NewStringParser(string(nginx_conf.Cache)).Parse()
210 case dto.ProxyCache:
211 newConfig, err = parser.NewStringParser(string(nginx_conf.ProxyCache)).Parse()
212 }
213 if err != nil {
214 return nil
215 }
216 for _, dir := range newConfig.GetDirectives() {
217 addParam := dto.NginxParam{
218 Name: dir.GetName(),
219 Params: dir.GetParameters(),
220 UpdateScope: updateScope,
221 }
222 isExist := false
223 for _, newParam := range newParams {
224 if newParam.Name == dir.GetName() {
225 if components.IsRepeatKey(newParam.Name) {
226 if len(newParam.Params) > 0 && newParam.Params[0] == dir.GetParameters()[0] {
227 isExist = true
228 }
229 } else {
230 isExist = true
231 }
232 }
233 }
234 if !isExist {
235 newParams = append(newParams, addParam)
236 }
237 }
238 return newParams
239}
240
241func opNginx(containerName, operate string) error {
242 cmdMgr := cmd.NewCommandMgr(cmd.WithTimeout(20 * time.Second))

Callers 3

applySSLFunction · 0.85
OpWebsiteHTTPSMethod · 0.85

Calls 4

ParseMethod · 0.80
GetDirectivesMethod · 0.65
GetNameMethod · 0.65
GetParametersMethod · 0.65

Tested by

no test coverage detected