From 528d3047770f3e4a4dd44acd465ecd27e930f7ce Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Tue, 7 Sep 2021 15:25:57 -0400 Subject: [PATCH 01/40] Added Secure value to Cfg struct. --- lib/go-atscfg/atscfg.go | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/go-atscfg/atscfg.go b/lib/go-atscfg/atscfg.go index 7c76df6326..45168f41b5 100644 --- a/lib/go-atscfg/atscfg.go +++ b/lib/go-atscfg/atscfg.go @@ -104,6 +104,7 @@ type Cfg struct { Text string ContentType string LineComment string + Secure bool Warnings []string } From eccbd96dc9db8c6ff71b7442b9f89d5a8d7d4e55 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Tue, 7 Sep 2021 15:28:44 -0400 Subject: [PATCH 02/40] Added Secure value --- lib/go-atscfg/astatsdotconfig.go | 1 + lib/go-atscfg/atsdotrules.go | 1 + lib/go-atscfg/bgfetchdotconfig.go | 1 + lib/go-atscfg/cachedotconfig.go | 1 + lib/go-atscfg/chkconfig.go | 1 + lib/go-atscfg/dropqstringdotconfig.go | 1 + lib/go-atscfg/facts.go | 1 + lib/go-atscfg/headerrewritedotconfig.go | 2 ++ lib/go-atscfg/hostingdotconfig.go | 1 + lib/go-atscfg/ipallowdotconfig.go | 1 + lib/go-atscfg/ipallowdotyaml.go | 1 + lib/go-atscfg/loggingdotconfig.go | 1 + lib/go-atscfg/loggingdotyaml.go | 1 + lib/go-atscfg/logsdotxml.go | 1 + lib/go-atscfg/packages.go | 1 + lib/go-atscfg/parentdotconfig.go | 1 + lib/go-atscfg/plugindotconfig.go | 1 + lib/go-atscfg/recordsdotconfig.go | 1 + lib/go-atscfg/regexremapdotconfig.go | 1 + lib/go-atscfg/regexrevalidatedotconfig.go | 1 + lib/go-atscfg/remapdotconfig.go | 1 + lib/go-atscfg/servercachedotconfig.go | 1 + lib/go-atscfg/serverunknown.go | 1 + lib/go-atscfg/setdscpdotconfig.go | 1 + lib/go-atscfg/snidotyaml.go | 1 + lib/go-atscfg/sslmulticertdotconfig.go | 1 + lib/go-atscfg/sslservernamedotyaml.go | 1 + lib/go-atscfg/storagedotconfig.go | 1 + lib/go-atscfg/sysctldotconf.go | 1 + lib/go-atscfg/urisigningconfig.go | 1 + lib/go-atscfg/urlsigconfig.go | 1 + lib/go-atscfg/volumedotconfig.go | 1 + 32 files changed, 33 insertions(+) diff --git a/lib/go-atscfg/astatsdotconfig.go b/lib/go-atscfg/astatsdotconfig.go index 9dc09c7f5c..b03d970f6f 100644 --- a/lib/go-atscfg/astatsdotconfig.go +++ b/lib/go-atscfg/astatsdotconfig.go @@ -65,6 +65,7 @@ func MakeAStatsDotConfig( Text: txt, ContentType: ContentTypeAstatsDotConfig, LineComment: LineCommentAstatsDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/atsdotrules.go b/lib/go-atscfg/atsdotrules.go index ea80de4fe1..faa216d1bf 100644 --- a/lib/go-atscfg/atsdotrules.go +++ b/lib/go-atscfg/atsdotrules.go @@ -77,6 +77,7 @@ func MakeATSDotRules( Text: text, ContentType: ContentTypeATSDotRules, LineComment: LineCommentATSDotRules, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/bgfetchdotconfig.go b/lib/go-atscfg/bgfetchdotconfig.go index 0caa5b69ff..f01bef2faf 100644 --- a/lib/go-atscfg/bgfetchdotconfig.go +++ b/lib/go-atscfg/bgfetchdotconfig.go @@ -50,6 +50,7 @@ func MakeBGFetchDotConfig( Text: text, ContentType: ContentTypeBGFetchDotConfig, LineComment: LineCommentBGFetchDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/cachedotconfig.go b/lib/go-atscfg/cachedotconfig.go index a98da6775b..46f0b22617 100644 --- a/lib/go-atscfg/cachedotconfig.go +++ b/lib/go-atscfg/cachedotconfig.go @@ -160,6 +160,7 @@ func makeCacheDotConfigEdge( Text: text, ContentType: ContentTypeCacheDotConfig, LineComment: LineCommentCacheDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/chkconfig.go b/lib/go-atscfg/chkconfig.go index 67ba959e94..7730ccdc20 100644 --- a/lib/go-atscfg/chkconfig.go +++ b/lib/go-atscfg/chkconfig.go @@ -64,6 +64,7 @@ func MakeChkconfig( Text: string(bts), ContentType: ContentTypeChkconfig, LineComment: LineCommentChkconfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/dropqstringdotconfig.go b/lib/go-atscfg/dropqstringdotconfig.go index c8d8d9c84b..61af5a9113 100644 --- a/lib/go-atscfg/dropqstringdotconfig.go +++ b/lib/go-atscfg/dropqstringdotconfig.go @@ -73,6 +73,7 @@ func MakeDropQStringDotConfig( Text: text, ContentType: ContentTypeDropQStringDotConfig, LineComment: LineCommentDropQStringDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/facts.go b/lib/go-atscfg/facts.go index 750e23a64f..92f3e1db5b 100644 --- a/lib/go-atscfg/facts.go +++ b/lib/go-atscfg/facts.go @@ -51,6 +51,7 @@ func Make12MFacts( Text: txt, ContentType: ContentType12MFacts, LineComment: LineComment12MFacts, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/headerrewritedotconfig.go b/lib/go-atscfg/headerrewritedotconfig.go index c7f41723ca..7185e43598 100644 --- a/lib/go-atscfg/headerrewritedotconfig.go +++ b/lib/go-atscfg/headerrewritedotconfig.go @@ -136,6 +136,7 @@ func MakeHeaderRewriteDotConfig( Text: "", ContentType: ContentTypeHeaderRewriteDotConfig, LineComment: LineCommentHeaderRewriteDotConfig, + Secure: false, Warnings: warnings, }, nil } @@ -199,6 +200,7 @@ func MakeHeaderRewriteDotConfig( Text: text, ContentType: ContentTypeHeaderRewriteDotConfig, LineComment: LineCommentHeaderRewriteDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/hostingdotconfig.go b/lib/go-atscfg/hostingdotconfig.go index d81b9cdc0e..f9590b1fb2 100644 --- a/lib/go-atscfg/hostingdotconfig.go +++ b/lib/go-atscfg/hostingdotconfig.go @@ -216,6 +216,7 @@ func MakeHostingDotConfig( Text: text, ContentType: ContentTypeHostingDotConfig, LineComment: LineCommentHostingDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/ipallowdotconfig.go b/lib/go-atscfg/ipallowdotconfig.go index ab45f6e68e..4279fd8f93 100644 --- a/lib/go-atscfg/ipallowdotconfig.go +++ b/lib/go-atscfg/ipallowdotconfig.go @@ -330,6 +330,7 @@ func MakeIPAllowDotConfig( Text: text, ContentType: ContentTypeHostingDotConfig, LineComment: LineCommentHostingDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/ipallowdotyaml.go b/lib/go-atscfg/ipallowdotyaml.go index e2b7663125..d3d12d9c84 100644 --- a/lib/go-atscfg/ipallowdotyaml.go +++ b/lib/go-atscfg/ipallowdotyaml.go @@ -343,6 +343,7 @@ ip_allow:` Text: text, ContentType: ContentTypeHostingDotConfig, LineComment: LineCommentHostingDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/loggingdotconfig.go b/lib/go-atscfg/loggingdotconfig.go index 24878c9cac..17ff7b5c69 100644 --- a/lib/go-atscfg/loggingdotconfig.go +++ b/lib/go-atscfg/loggingdotconfig.go @@ -147,6 +147,7 @@ func MakeLoggingDotConfig( Text: text, ContentType: ContentTypeLoggingDotConfig, LineComment: LineCommentLoggingDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/loggingdotyaml.go b/lib/go-atscfg/loggingdotyaml.go index aa05a8a972..d383f5ecb5 100644 --- a/lib/go-atscfg/loggingdotyaml.go +++ b/lib/go-atscfg/loggingdotyaml.go @@ -163,6 +163,7 @@ func MakeLoggingDotYAML( Text: text, ContentType: ContentTypeLoggingDotYAML, LineComment: LineCommentLoggingDotYAML, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/logsdotxml.go b/lib/go-atscfg/logsdotxml.go index a493821987..ff22e15271 100644 --- a/lib/go-atscfg/logsdotxml.go +++ b/lib/go-atscfg/logsdotxml.go @@ -118,6 +118,7 @@ func MakeLogsXMLDotConfig( Text: text, ContentType: ContentTypeLogsDotXML, LineComment: LineCommentLogsDotXML, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/packages.go b/lib/go-atscfg/packages.go index c6e4b29622..fb9ce80919 100644 --- a/lib/go-atscfg/packages.go +++ b/lib/go-atscfg/packages.go @@ -66,6 +66,7 @@ func MakePackages( Text: string(bts), ContentType: ContentTypePackages, LineComment: LineCommentPackages, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/parentdotconfig.go b/lib/go-atscfg/parentdotconfig.go index 9fe657b292..2837d80830 100644 --- a/lib/go-atscfg/parentdotconfig.go +++ b/lib/go-atscfg/parentdotconfig.go @@ -463,6 +463,7 @@ func MakeParentDotConfig( Text: text, ContentType: ContentTypeParentDotConfig, LineComment: LineCommentParentDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/plugindotconfig.go b/lib/go-atscfg/plugindotconfig.go index 1d2d43d2f3..003e13c565 100644 --- a/lib/go-atscfg/plugindotconfig.go +++ b/lib/go-atscfg/plugindotconfig.go @@ -63,6 +63,7 @@ func MakePluginDotConfig( Text: txt, ContentType: ContentTypePluginDotConfig, LineComment: LineCommentPluginDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/recordsdotconfig.go b/lib/go-atscfg/recordsdotconfig.go index 0e708029ff..2318449775 100644 --- a/lib/go-atscfg/recordsdotconfig.go +++ b/lib/go-atscfg/recordsdotconfig.go @@ -88,6 +88,7 @@ func MakeRecordsDotConfig( Text: txt, ContentType: ContentTypeRecordsDotConfig, LineComment: LineCommentRecordsDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/regexremapdotconfig.go b/lib/go-atscfg/regexremapdotconfig.go index bb21cc742e..8889ab430a 100644 --- a/lib/go-atscfg/regexremapdotconfig.go +++ b/lib/go-atscfg/regexremapdotconfig.go @@ -93,6 +93,7 @@ func MakeRegexRemapDotConfig( Text: text, ContentType: ContentTypeRegexRemapDotConfig, LineComment: LineCommentRegexRemapDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/regexrevalidatedotconfig.go b/lib/go-atscfg/regexrevalidatedotconfig.go index f20d78bdeb..82c035f2fa 100644 --- a/lib/go-atscfg/regexrevalidatedotconfig.go +++ b/lib/go-atscfg/regexrevalidatedotconfig.go @@ -122,6 +122,7 @@ func MakeRegexRevalidateDotConfig( Text: txt, ContentType: ContentTypeRegexRevalidateDotConfig, LineComment: LineCommentRegexRevalidateDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/remapdotconfig.go b/lib/go-atscfg/remapdotconfig.go index 7803dcf54e..b24aff76b6 100644 --- a/lib/go-atscfg/remapdotconfig.go +++ b/lib/go-atscfg/remapdotconfig.go @@ -112,6 +112,7 @@ func MakeRemapDotConfig( Text: txt, ContentType: ContentTypeRemapDotConfig, LineComment: LineCommentRemapDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/servercachedotconfig.go b/lib/go-atscfg/servercachedotconfig.go index 0bfad5bc56..65cfe8c39c 100644 --- a/lib/go-atscfg/servercachedotconfig.go +++ b/lib/go-atscfg/servercachedotconfig.go @@ -87,6 +87,7 @@ func makeCacheDotConfigMid( Text: text, ContentType: ContentTypeCacheDotConfig, LineComment: LineCommentCacheDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/serverunknown.go b/lib/go-atscfg/serverunknown.go index 810044e9a5..ffd65d2663 100644 --- a/lib/go-atscfg/serverunknown.go +++ b/lib/go-atscfg/serverunknown.go @@ -86,6 +86,7 @@ func MakeServerUnknown( Text: txt, ContentType: ContentTypeServerUnknownConfig, LineComment: lineComment, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/setdscpdotconfig.go b/lib/go-atscfg/setdscpdotconfig.go index 1de930cbb8..858d25b9af 100644 --- a/lib/go-atscfg/setdscpdotconfig.go +++ b/lib/go-atscfg/setdscpdotconfig.go @@ -68,6 +68,7 @@ func MakeSetDSCPDotConfig( Text: text, ContentType: ContentTypeSetDSCPDotConfig, LineComment: LineCommentSetDSCPDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/snidotyaml.go b/lib/go-atscfg/snidotyaml.go index 3fdd504d94..8d9329f16f 100644 --- a/lib/go-atscfg/snidotyaml.go +++ b/lib/go-atscfg/snidotyaml.go @@ -127,6 +127,7 @@ func MakeSNIDotYAML( Text: txt, ContentType: ContentTypeSNIDotYAML, LineComment: LineCommentSNIDotYAML, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/sslmulticertdotconfig.go b/lib/go-atscfg/sslmulticertdotconfig.go index 4c5ffa157f..a48e430a18 100644 --- a/lib/go-atscfg/sslmulticertdotconfig.go +++ b/lib/go-atscfg/sslmulticertdotconfig.go @@ -72,6 +72,7 @@ func MakeSSLMultiCertDotConfig( Text: txt, ContentType: ContentTypeSSLMultiCertDotConfig, LineComment: LineCommentSSLMultiCertDotConfig, + Secure: true, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/sslservernamedotyaml.go b/lib/go-atscfg/sslservernamedotyaml.go index 06d76cf33f..0cd534d639 100644 --- a/lib/go-atscfg/sslservernamedotyaml.go +++ b/lib/go-atscfg/sslservernamedotyaml.go @@ -181,6 +181,7 @@ func MakeSSLServerNameYAML( Text: txt, ContentType: ContentTypeSSLServerNameYAML, LineComment: LineCommentSSLServerNameYAML, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/storagedotconfig.go b/lib/go-atscfg/storagedotconfig.go index 642e6609ab..e657332d51 100644 --- a/lib/go-atscfg/storagedotconfig.go +++ b/lib/go-atscfg/storagedotconfig.go @@ -98,6 +98,7 @@ func MakeStorageDotConfig( Text: text, ContentType: ContentTypeStorageDotConfig, LineComment: LineCommentStorageDotConfig, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/sysctldotconf.go b/lib/go-atscfg/sysctldotconf.go index bb2e765f45..fa36f61bd9 100644 --- a/lib/go-atscfg/sysctldotconf.go +++ b/lib/go-atscfg/sysctldotconf.go @@ -63,6 +63,7 @@ func MakeSysCtlDotConf( Text: txt, ContentType: ContentTypeSysctlDotConf, LineComment: LineCommentSysctlDotConf, + Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/urisigningconfig.go b/lib/go-atscfg/urisigningconfig.go index 600ef75b57..3566b0f5e4 100644 --- a/lib/go-atscfg/urisigningconfig.go +++ b/lib/go-atscfg/urisigningconfig.go @@ -57,6 +57,7 @@ func MakeURISigningConfig( Text: string(uriSigningKeyBts), ContentType: ContentTypeURISigningDotConfig, LineComment: LineCommentURISigningDotConfig, + Secure: true, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/urlsigconfig.go b/lib/go-atscfg/urlsigconfig.go index 22bb4c7995..35a2b91d21 100644 --- a/lib/go-atscfg/urlsigconfig.go +++ b/lib/go-atscfg/urlsigconfig.go @@ -93,6 +93,7 @@ func MakeURLSigConfig( Text: text, ContentType: ContentTypeURLSig, LineComment: LineCommentURLSig, + Secure: true, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/volumedotconfig.go b/lib/go-atscfg/volumedotconfig.go index ef58139f4c..de3fa20a77 100644 --- a/lib/go-atscfg/volumedotconfig.go +++ b/lib/go-atscfg/volumedotconfig.go @@ -84,6 +84,7 @@ func MakeVolumeDotConfig( Text: hdr + text, ContentType: ContentTypeVolumeDotConfig, LineComment: LineCommentVolumeDotConfig, + Secure: false, Warnings: warnings, }, nil } From 79ffea58d9eff7b9e229d364d6767acd975d1c5f Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Tue, 7 Sep 2021 15:40:15 -0400 Subject: [PATCH 03/40] Added Secure value to struct --- cache-config/t3cutil/t3cutil.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cache-config/t3cutil/t3cutil.go b/cache-config/t3cutil/t3cutil.go index 4cbe85ccab..4938684896 100644 --- a/cache-config/t3cutil/t3cutil.go +++ b/cache-config/t3cutil/t3cutil.go @@ -37,6 +37,7 @@ type ATSConfigFile struct { Path string `json:"path"` ContentType string `json:"content_type"` LineComment string `json:"line_comment"` + Secure bool `json:"secure"` Text string `json:"text"` } From 1802127bb45e8945d5d7bbdee63f5aa52131716b Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Tue, 7 Sep 2021 15:41:06 -0400 Subject: [PATCH 04/40] Added test to set file mode. --- cache-config/t3c-apply/torequest/torequest.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go index 7763fbbf92..aefedc8ad3 100644 --- a/cache-config/t3c-apply/torequest/torequest.go +++ b/cache-config/t3c-apply/torequest/torequest.go @@ -632,7 +632,11 @@ func (r *TrafficOpsReq) GetConfigFileList() error { } r.configFiles = map[string]*ConfigFile{} + mode := os.FileMode(0644) for _, file := range allFiles { + if file.Secure { + mode = 0600 + } r.configFiles[file.Name] = &ConfigFile{ Name: file.Name, Path: filepath.Join(file.Path, file.Name), @@ -640,7 +644,7 @@ func (r *TrafficOpsReq) GetConfigFileList() error { Body: []byte(file.Text), Uid: atsUid, Gid: atsGid, - Perm: 0644, + Perm: mode, } } return nil From bb1967915715a619c0972487ce6bd17909ee0e04 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Tue, 7 Sep 2021 16:20:55 -0400 Subject: [PATCH 05/40] Added secure fields to unit test. --- cache-config/t3c-generate/cfgfile/cfgfile_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cache-config/t3c-generate/cfgfile/cfgfile_test.go b/cache-config/t3c-generate/cfgfile/cfgfile_test.go index 991501ac70..2ecf4c9f1c 100644 --- a/cache-config/t3c-generate/cfgfile/cfgfile_test.go +++ b/cache-config/t3c-generate/cfgfile/cfgfile_test.go @@ -40,12 +40,14 @@ func TestWriteConfigs(t *testing.T) { Name: "config0.txt", Path: "/my/config0/location", Text: "config0", + Secure: false, ContentType: "text/plain", }, { Name: "config1.txt", Path: "/my/config1/location", Text: "config2,foo", + Secure: false, ContentType: "text/csv", }, } @@ -56,18 +58,18 @@ func TestWriteConfigs(t *testing.T) { actual := buf.String() - expected0 := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","text":"config0"},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","text":"config2,foo"}]` + expected0 := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","secure":false,"text":"config0"},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","secure":false,"text":"config2,foo"}]` if !strings.Contains(actual, expected0) { t.Errorf("WriteConfigs expected '%v' actual '%v'", expected0, actual) } - expected1 := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","text":"config0"},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","text":"config2,foo"}]` + expected1 := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","secure":false,"text":"config0"},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","secure":false,"text":"config2,foo"}]` if !strings.Contains(actual, expected1) { t.Errorf("WriteConfigs expected config1 '%v' actual '%v'", expected1, actual) } - expectedPrefix := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","text":"config0"},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","text":"config2,foo"}]` + expectedPrefix := `[{"name":"config0.txt","path":"/my/config0/location","content_type":"text/plain","line_comment":"","secure":false,"text":"config0"},{"name":"config1.txt","path":"/my/config1/location","content_type":"text/csv","line_comment":"","secure":false,"text":"config2,foo"}]` if !strings.HasPrefix(actual, expectedPrefix) { t.Errorf("WriteConfigs expected prefix '%v' actual '%v'", expectedPrefix, actual) } From ab0ce100c01d46d8c226b305ed99e45f833810b7 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Wed, 8 Sep 2021 12:54:20 -0400 Subject: [PATCH 06/40] output permission. --- cache-config/t3c-apply/torequest/torequest.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go index aefedc8ad3..a6423f636d 100644 --- a/cache-config/t3c-apply/torequest/torequest.go +++ b/cache-config/t3c-apply/torequest/torequest.go @@ -784,6 +784,7 @@ func (r *TrafficOpsReq) ProcessConfigFiles() (UpdateStatus, error) { for _, cfg := range r.configFiles { // add service metadata + log.Infof("File mode is: %d", cfg.Perm) if strings.Contains(cfg.Path, "/opt/trafficserver/") || strings.Contains(cfg.Dir, "udev") { cfg.Service = "trafficserver" if !r.Cfg.InstallPackages && !r.IsPackageInstalled("trafficserver") { From 914e610bb9ddbc62ff0ea3849d10d64a91dde881 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Wed, 8 Sep 2021 13:54:24 -0400 Subject: [PATCH 07/40] moved file mode info log and print the correct way. --- cache-config/t3c-apply/torequest/torequest.go | 3 +- vendor/modules.txt | 36 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go index a6423f636d..a792497157 100644 --- a/cache-config/t3c-apply/torequest/torequest.go +++ b/cache-config/t3c-apply/torequest/torequest.go @@ -230,7 +230,7 @@ func (r *TrafficOpsReq) checkConfigFile(cfg *ConfigFile, filesAdding []string) e return errors.New("unable to process udev rules in '" + cfg.Name + "': " + err.Error()) } } - + log.Infof("File mode is: %o", cfg.Perm) log.Infof("======== End processing config file: %s for service: %s ========\n", cfg.Name, cfg.Service) return nil } @@ -784,7 +784,6 @@ func (r *TrafficOpsReq) ProcessConfigFiles() (UpdateStatus, error) { for _, cfg := range r.configFiles { // add service metadata - log.Infof("File mode is: %d", cfg.Perm) if strings.Contains(cfg.Path, "/opt/trafficserver/") || strings.Contains(cfg.Dir, "udev") { cfg.Service = "trafficserver" if !r.Cfg.InstallPackages && !r.IsPackageInstalled("trafficserver") { diff --git a/vendor/modules.txt b/vendor/modules.txt index 86d53406fd..5bd4275edd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -67,7 +67,7 @@ github.com/go-ozzo/ozzo-validation/is ## explicit github.com/gofrs/flock # github.com/golang-migrate/migrate/v4 v4.14.1 -## explicit; go 1.13 +## explicit github.com/golang-migrate/migrate/v4 github.com/golang-migrate/migrate/v4/database github.com/golang-migrate/migrate/v4/database/postgres @@ -76,7 +76,7 @@ github.com/golang-migrate/migrate/v4/source github.com/golang-migrate/migrate/v4/source/file github.com/golang-migrate/migrate/v4/source/httpfs # github.com/golang/protobuf v1.4.3 -## explicit; go 1.9 +## explicit github.com/golang/protobuf/proto # github.com/google/uuid v1.1.2 ## explicit @@ -85,7 +85,7 @@ github.com/google/uuid ## explicit github.com/hashicorp/errwrap # github.com/hashicorp/go-multierror v1.1.0 -## explicit; go 1.14 +## explicit github.com/hashicorp/go-multierror # github.com/hydrogen18/stoppableListener v0.0.0-20151210151943-dadc9ccc400c ## explicit @@ -106,7 +106,7 @@ github.com/json-iterator/go ## explicit github.com/kelseyhightower/envconfig # github.com/kylelemons/godebug v1.1.1-0.20201107061927-e693023230a4 -## explicit; go 1.11 +## explicit github.com/kylelemons/godebug/diff # github.com/lestrrat-go/jwx v0.9.1-0.20190702045520-e35178ac2b1f ## explicit @@ -121,12 +121,12 @@ github.com/lestrrat/go-jwx/internal/emap github.com/lestrrat/go-jwx/jwa github.com/lestrrat/go-jwx/jwk # github.com/lib/pq v1.8.0 -## explicit; go 1.13 +## explicit github.com/lib/pq github.com/lib/pq/oid github.com/lib/pq/scram # github.com/mattn/go-sqlite3 v1.14.5 -## explicit; go 1.10 +## explicit # github.com/miekg/dns v1.0.6-0.20180406150955-01d59357d468 ## explicit github.com/miekg/dns @@ -137,14 +137,14 @@ github.com/modern-go/concurrent ## explicit github.com/modern-go/reflect2 # github.com/nxadm/tail v1.4.4 -## explicit; go 1.13 +## explicit github.com/nxadm/tail github.com/nxadm/tail/ratelimiter github.com/nxadm/tail/util github.com/nxadm/tail/watch github.com/nxadm/tail/winfile # github.com/onsi/ginkgo v1.14.2 -## explicit; go 1.13 +## explicit github.com/onsi/ginkgo github.com/onsi/ginkgo/config github.com/onsi/ginkgo/internal/codelocation @@ -165,7 +165,7 @@ github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty github.com/onsi/ginkgo/types # github.com/onsi/gomega v1.10.3 -## explicit; go 1.14 +## explicit github.com/onsi/gomega github.com/onsi/gomega/format github.com/onsi/gomega/internal/assertion @@ -179,25 +179,25 @@ github.com/onsi/gomega/matchers/support/goraph/node github.com/onsi/gomega/matchers/support/goraph/util github.com/onsi/gomega/types # github.com/pborman/getopt/v2 v2.1.0 -## explicit; go 1.13 +## explicit github.com/pborman/getopt/v2 # github.com/pkg/errors v0.9.1 ## explicit github.com/pkg/errors # github.com/stretchr/testify v1.6.1 -## explicit; go 1.13 +## explicit # go.etcd.io/bbolt v1.3.5 -## explicit; go 1.12 +## explicit go.etcd.io/bbolt # golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e -## explicit; go 1.17 +## explicit golang.org/x/crypto/ed25519 golang.org/x/crypto/ed25519/internal/edwards25519 golang.org/x/crypto/ocsp golang.org/x/crypto/pbkdf2 golang.org/x/crypto/scrypt # golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d -## explicit; go 1.17 +## explicit golang.org/x/net/bpf golang.org/x/net/html golang.org/x/net/html/atom @@ -212,12 +212,12 @@ golang.org/x/net/ipv4 golang.org/x/net/ipv6 golang.org/x/net/publicsuffix # golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 -## explicit; go 1.17 +## explicit golang.org/x/sys/internal/unsafeheader golang.org/x/sys/unix golang.org/x/sys/windows # golang.org/x/text v0.3.7 -## explicit; go 1.17 +## explicit golang.org/x/text/encoding golang.org/x/text/encoding/charmap golang.org/x/text/encoding/htmlindex @@ -239,11 +239,11 @@ golang.org/x/text/transform golang.org/x/text/unicode/bidi golang.org/x/text/unicode/norm # golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 -## explicit; go 1.11 +## explicit golang.org/x/xerrors golang.org/x/xerrors/internal # google.golang.org/protobuf v1.25.0 -## explicit; go 1.9 +## explicit google.golang.org/protobuf/encoding/prototext google.golang.org/protobuf/encoding/protowire google.golang.org/protobuf/internal/descfmt From c6f260b2c4b9afd9d7118ba942eff4e9409d5327 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 10 Sep 2021 14:03:02 -0400 Subject: [PATCH 08/40] Added secure variable. --- cache-config/t3c-generate/cfgfile/all.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache-config/t3c-generate/cfgfile/all.go b/cache-config/t3c-generate/cfgfile/all.go index c1df2a7842..c8a6f4658b 100644 --- a/cache-config/t3c-generate/cfgfile/all.go +++ b/cache-config/t3c-generate/cfgfile/all.go @@ -58,14 +58,14 @@ func GetAllConfigs( if cfg.RevalOnly && fi.Name != atscfg.RegexRevalidateFileName { continue } - txt, contentType, lineComment, err := GetConfigFile(toData, fi, hdrCommentTxt, cfg) + txt, contentType, secure, lineComment, err := GetConfigFile(toData, fi, hdrCommentTxt, cfg) if err != nil { return nil, errors.New("getting config file '" + fi.Name + "': " + err.Error()) } if fi.Name == atscfg.SSLMultiCertConfigFileName { hasSSLMultiCertConfig = true } - configs = append(configs, t3cutil.ATSConfigFile{Name: fi.Name, Path: fi.Path, Text: txt, ContentType: contentType, LineComment: lineComment}) + configs = append(configs, t3cutil.ATSConfigFile{Name: fi.Name, Path: fi.Path, Text: txt, Secure: secure, ContentType: contentType, LineComment: lineComment}) } if hasSSLMultiCertConfig { From 817f2a4943d0079a9e4d13a146afda311ecea316 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 10 Sep 2021 14:04:21 -0400 Subject: [PATCH 09/40] Added secure variable. --- cache-config/t3c-generate/cfgfile/routing.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cache-config/t3c-generate/cfgfile/routing.go b/cache-config/t3c-generate/cfgfile/routing.go index 49e4c3b316..0e34832ab6 100644 --- a/cache-config/t3c-generate/cfgfile/routing.go +++ b/cache-config/t3c-generate/cfgfile/routing.go @@ -32,7 +32,7 @@ import ( // # DO NOT EDIT - Generated for odol-atsec-sea-22 by Traffic Ops (https://trafficops.comcast.net/) on Mon Oct 26 16:22:19 UTC 2020 // GetConfigFile returns the text of the generated config file, the MIME Content Type of the config file, and any error. -func GetConfigFile(toData *t3cutil.ConfigData, fileInfo atscfg.CfgMeta, hdrCommentTxt string, thiscfg config.Cfg) (string, string, string, error) { +func GetConfigFile(toData *t3cutil.ConfigData, fileInfo atscfg.CfgMeta, hdrCommentTxt string, thiscfg config.Cfg) (string, string, bool, string, error) { start := time.Now() defer func() { log.Infof("GetConfigFile %v took %v\n", fileInfo.Name, time.Since(start).Round(time.Millisecond)) @@ -44,9 +44,9 @@ func GetConfigFile(toData *t3cutil.ConfigData, fileInfo atscfg.CfgMeta, hdrComme logWarnings("getting config file '"+fileInfo.Name+"': ", cfg.Warnings) if err != nil { - return "", "", "", err + return "", "", false, "", err } - return cfg.Text, cfg.ContentType, cfg.LineComment, nil + return cfg.Text, cfg.ContentType, cfg.Secure, cfg.LineComment, nil } type ConfigFileFunc func(toData *t3cutil.ConfigData, fileName string, hdrCommentTxt string, cfg config.Cfg) (atscfg.Cfg, error) From 7ad3f39aea0ee65f6bc34c2188a7d1aa552d3350 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 10 Sep 2021 14:41:54 -0400 Subject: [PATCH 10/40] ioutil.WriteFile was writing file with 0644 permissions changed to use cfg.Perm variable. --- cache-config/t3c-apply/torequest/torequest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go index a792497157..927b129836 100644 --- a/cache-config/t3c-apply/torequest/torequest.go +++ b/cache-config/t3c-apply/torequest/torequest.go @@ -477,7 +477,7 @@ func (r *TrafficOpsReq) replaceCfgFile(cfg *ConfigFile) error { // If we just wrote to the real location and the app or OS or anything crashed, // we'd end up with malformed files. - if _, err := util.WriteFileWithOwner(tmpFileName, cfg.Body, &cfg.Uid, &cfg.Gid, 0644); err != nil { + if _, err := util.WriteFileWithOwner(tmpFileName, cfg.Body, &cfg.Uid, &cfg.Gid, cfg.Perm); err != nil { return errors.New("Failed to write temp config file '" + tmpFileName + "': " + err.Error()) } From 88d9922eca63a9123d885022bdcbef803d327aa2 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Mon, 13 Sep 2021 11:48:16 -0400 Subject: [PATCH 11/40] Changed openfile from octal to perm variable. --- cache-config/t3c-apply/util/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache-config/t3c-apply/util/util.go b/cache-config/t3c-apply/util/util.go index 9974cf1475..7f8c36d7c5 100644 --- a/cache-config/t3c-apply/util/util.go +++ b/cache-config/t3c-apply/util/util.go @@ -200,7 +200,7 @@ func ServiceStart(service string, cmd string) (bool, error) { } func WriteFileWithOwner(fn string, data []byte, uid *int, gid *int, perm os.FileMode) (int, error) { - fd, err := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + fd, err := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm) if err != nil { return 0, errors.New("unable to open '" + fn + "' for writing: " + err.Error()) } From 0e10c115a0445c770126b711b7b4a91d195c2930 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Mon, 13 Sep 2021 13:06:09 -0400 Subject: [PATCH 12/40] Fixed error in test for secure file. --- cache-config/t3c-apply/torequest/torequest.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go index 927b129836..f2ad22c399 100644 --- a/cache-config/t3c-apply/torequest/torequest.go +++ b/cache-config/t3c-apply/torequest/torequest.go @@ -470,7 +470,7 @@ func (r *TrafficOpsReq) replaceCfgFile(cfg *ConfigFile) error { } tmpFileName := cfg.Path + configFileTempSuffix - log.Infof("Writing temp file '%s'\n", tmpFileName) + log.Infof("Writing temp file '%s' with file mode: %o \n", tmpFileName, cfg.Perm) // write a new file, then move to the real location // because moving is atomic but writing is not. @@ -632,11 +632,14 @@ func (r *TrafficOpsReq) GetConfigFileList() error { } r.configFiles = map[string]*ConfigFile{} - mode := os.FileMode(0644) + var mode os.FileMode for _, file := range allFiles { if file.Secure { mode = 0600 + } else { + mode = 0644 } + r.configFiles[file.Name] = &ConfigFile{ Name: file.Name, Path: filepath.Join(file.Path, file.Name), From 9c39c2a245e7461b25d8c0903768468c9c464a82 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Mon, 13 Sep 2021 13:06:46 -0400 Subject: [PATCH 13/40] added secure variable for cert and key file generation. --- cache-config/t3c-generate/cfgfile/sslkeys.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cache-config/t3c-generate/cfgfile/sslkeys.go b/cache-config/t3c-generate/cfgfile/sslkeys.go index 46ef9b398f..478b38f93f 100644 --- a/cache-config/t3c-generate/cfgfile/sslkeys.go +++ b/cache-config/t3c-generate/cfgfile/sslkeys.go @@ -65,12 +65,14 @@ func GetSSLCertsAndKeyFiles(toData *t3cutil.ConfigData) ([]t3cutil.ATSConfigFile keyFile.Name = keyName keyFile.Path = "/opt/trafficserver/etc/trafficserver/ssl/" // TODO read config, don't hard code keyFile.Text = string(key) + keyFile.Secure = true configs = append(configs, keyFile) certFile := t3cutil.ATSConfigFile{} certFile.Name = certName certFile.Path = "/opt/trafficserver/etc/trafficserver/ssl/" // TODO read config, don't hard code certFile.Text = string(cert) + certFile.Secure = true configs = append(configs, certFile) } From 40cf9a090c5716ecfd72f554fac8ca33ce541141 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Wed, 15 Sep 2021 15:12:56 -0400 Subject: [PATCH 14/40] changed Comments filter to use provided line comment character and added func to compare file permissions. --- cache-config/t3cutil/t3cutil.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cache-config/t3cutil/t3cutil.go b/cache-config/t3cutil/t3cutil.go index 4938684896..ad0aecce53 100644 --- a/cache-config/t3cutil/t3cutil.go +++ b/cache-config/t3cutil/t3cutil.go @@ -53,17 +53,17 @@ func (fs ATSConfigFiles) Less(i, j int) bool { } func (fs ATSConfigFiles) Swap(i, j int) { fs[i], fs[j] = fs[j], fs[i] } -// commentsFilter is used to remove comment +// CommentsFilter is used to remove comment // lines from config files while making // comparisons. -func CommentsFilter(body []string) []string { +func CommentsFilter(body []string, lineComment string) []string { var newlines []string newlines = make([]string, 0) for ii := range body { line := body[ii] - if strings.HasPrefix(line, "#") { + if strings.HasPrefix(line, lineComment) { continue } newlines = append(newlines, line) @@ -72,6 +72,18 @@ func CommentsFilter(body []string) []string { return newlines } +// PermCk will compare file permissions against existing file and octal permission provided. +func PermCk(path string, perm int) bool { + file, err := os.Stat(path) + if err != nil { + fmt.Println("Error opening file ", path) + } + if file.Mode() != os.FileMode(perm) { + return true + } + return false +} + // NewLineFilter removes carriage returns // from config files while making comparisons. func NewLineFilter(str string) string { From 71181f61a7a1a8f486e97c884aa21a5c0a05a288 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Wed, 15 Sep 2021 15:14:06 -0400 Subject: [PATCH 15/40] Updated to compare file permissions. --- cache-config/t3c-diff/t3c-diff.go | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/cache-config/t3c-diff/t3c-diff.go b/cache-config/t3c-diff/t3c-diff.go index 0686a581cf..1a0481d6aa 100644 --- a/cache-config/t3c-diff/t3c-diff.go +++ b/cache-config/t3c-diff/t3c-diff.go @@ -34,7 +34,12 @@ import ( func main() { help := getopt.BoolLong("help", 'h', "Print usage info and exit") + lineComment := getopt.StringLong("line_comment", 'l', "#", "Comment symbol") + mode := getopt.IntLong("mode", 'm', 0644, "file mode default is 644") + fa := getopt.StringLong("file_a", 'a', "", "first diff file") + fb := getopt.StringLong("file_b", 'b', "", "second diff file") getopt.ParseV2() + if *help { fmt.Println(usageStr) os.Exit(0) @@ -45,8 +50,8 @@ func main() { os.Exit(3) } - fileNameA := strings.TrimSpace(os.Args[1]) - fileNameB := strings.TrimSpace(os.Args[2]) + fileNameA := strings.TrimSpace(*fa) + fileNameB := strings.TrimSpace(*fb) if len(fileNameA) == 0 || len(fileNameB) == 0 { fmt.Println(usageStr) @@ -66,13 +71,13 @@ func main() { fileALines := strings.Split(string(fileA), "\n") fileALines = t3cutil.UnencodeFilter(fileALines) - fileALines = t3cutil.CommentsFilter(fileALines) + fileALines = t3cutil.CommentsFilter(fileALines, *lineComment) fileA = strings.Join(fileALines, "\n") fileA = t3cutil.NewLineFilter(fileA) fileBLines := strings.Split(string(fileB), "\n") fileBLines = t3cutil.UnencodeFilter(fileBLines) - fileBLines = t3cutil.CommentsFilter(fileBLines) + fileBLines = t3cutil.CommentsFilter(fileBLines, *lineComment) fileB = strings.Join(fileBLines, "\n") fileB = t3cutil.NewLineFilter(fileB) @@ -87,12 +92,24 @@ func main() { if fileAExisted != fileBExisted { os.Exit(1) } + switch { + case fileNameA != "stdin": + if t3cutil.PermCk(fileNameA, *mode) { + fmt.Println("File permissions differ") + os.Exit(1) + } + case fileNameB != "stdin": + if t3cutil.PermCk(fileNameB, *mode) { + fmt.Println("File permissions differ") + os.Exit(1) + } + } os.Exit(0) } const usageStr = `usage: t3c-diff [--help] - + -a -b -l -m Either file may be 'stdin', in which case that file is read from stdin. Either file may not exist. @@ -100,6 +117,9 @@ Either file may not exist. Prints the diff to stdout, and returns the exit code 0 if there was no diff, 1 if there was a diff. If one file exists but the other doesn't, it will always be a diff. +Mode is file permissions in octal format, default is 0644. +Line comment is a character that signals the line is a comment, default is # + Note this means there may be no diff text printed to stdout but still exit 1 indicating a diff if the file being created or deleted is semantically empty.` From dff12b35e016eba418bd261aae281171b9bcc590 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Wed, 15 Sep 2021 15:31:45 -0400 Subject: [PATCH 16/40] added file mode to diff func --- cache-config/t3c-apply/torequest/cmd.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cache-config/t3c-apply/torequest/cmd.go b/cache-config/t3c-apply/torequest/cmd.go index 6d5e1dcbfb..2affacc12d 100644 --- a/cache-config/t3c-apply/torequest/cmd.go +++ b/cache-config/t3c-apply/torequest/cmd.go @@ -257,8 +257,9 @@ func sendUpdate(cfg config.Cfg, updateStatus bool, revalStatus bool) error { // diff calls t3c-diff to diff the given new file and the file on disk. Returns whether they're different. // Logs the difference. // If the file on disk doesn't exist, returns true and logs the entire file as a diff. -func diff(cfg config.Cfg, newFile []byte, fileLocation string) (bool, error) { - stdOut, stdErr, code := t3cutil.DoInput(newFile, `t3c-diff`, `stdin`, fileLocation) +func diff(cfg config.Cfg, newFile []byte, fileLocation string, perm os.FileMode) (bool, error) { + mode := fmt.Sprintf("%o", perm) + stdOut, stdErr, code := t3cutil.DoInput(newFile, `t3c-diff`, ` -a stdin -b `, fileLocation, `-m `, mode) if code > 1 { return false, fmt.Errorf("t3c-diff returned error code %v stdout '%v' stderr '%v'", code, string(stdOut), string(stdErr)) } From 764b286d0cd084c00578b6fe5773aa4c2659822f Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Wed, 15 Sep 2021 15:32:00 -0400 Subject: [PATCH 17/40] added file mode to diff func call. --- cache-config/t3c-apply/torequest/torequest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go index f2ad22c399..ab4d91838f 100644 --- a/cache-config/t3c-apply/torequest/torequest.go +++ b/cache-config/t3c-apply/torequest/torequest.go @@ -217,7 +217,7 @@ func (r *TrafficOpsReq) checkConfigFile(cfg *ConfigFile, filesAdding []string) e log.Infoln("Successfully verified plugins used by '" + cfg.Name + "'") } - changeNeeded, err := diff(r.Cfg, cfg.Body, cfg.Path) + changeNeeded, err := diff(r.Cfg, cfg.Body, cfg.Path, cfg.Perm) if err != nil { return errors.New("getting diff: " + err.Error()) } From 47820c8d598d0515981a07668066edeb61ed4a9a Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Wed, 15 Sep 2021 15:55:55 -0400 Subject: [PATCH 18/40] fixed typo --- cache-config/t3c-apply/torequest/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache-config/t3c-apply/torequest/cmd.go b/cache-config/t3c-apply/torequest/cmd.go index 2affacc12d..c67c91160a 100644 --- a/cache-config/t3c-apply/torequest/cmd.go +++ b/cache-config/t3c-apply/torequest/cmd.go @@ -259,7 +259,7 @@ func sendUpdate(cfg config.Cfg, updateStatus bool, revalStatus bool) error { // If the file on disk doesn't exist, returns true and logs the entire file as a diff. func diff(cfg config.Cfg, newFile []byte, fileLocation string, perm os.FileMode) (bool, error) { mode := fmt.Sprintf("%o", perm) - stdOut, stdErr, code := t3cutil.DoInput(newFile, `t3c-diff`, ` -a stdin -b `, fileLocation, `-m `, mode) + stdOut, stdErr, code := t3cutil.DoInput(newFile, `t3c-diff`, ` -a stdin -b `, fileLocation, ` -m `, mode) if code > 1 { return false, fmt.Errorf("t3c-diff returned error code %v stdout '%v' stderr '%v'", code, string(stdOut), string(stdErr)) } From 15bbdd4f2f85553f9cf9fb97949ac5df4b80d226 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Wed, 15 Sep 2021 17:15:19 -0400 Subject: [PATCH 19/40] fixed args for diff func --- cache-config/t3c-apply/torequest/cmd.go | 11 ++++++++--- cache-config/t3c-diff/t3c-diff.go | 10 +++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cache-config/t3c-apply/torequest/cmd.go b/cache-config/t3c-apply/torequest/cmd.go index c67c91160a..9200a608d0 100644 --- a/cache-config/t3c-apply/torequest/cmd.go +++ b/cache-config/t3c-apply/torequest/cmd.go @@ -258,8 +258,13 @@ func sendUpdate(cfg config.Cfg, updateStatus bool, revalStatus bool) error { // Logs the difference. // If the file on disk doesn't exist, returns true and logs the entire file as a diff. func diff(cfg config.Cfg, newFile []byte, fileLocation string, perm os.FileMode) (bool, error) { - mode := fmt.Sprintf("%o", perm) - stdOut, stdErr, code := t3cutil.DoInput(newFile, `t3c-diff`, ` -a stdin -b `, fileLocation, ` -m `, mode) + args := []string{ + "--file-a=stdin", + "--file-b=" + fileLocation, + "--file-mode=" + fmt.Sprintf("%o", perm), + } + + stdOut, stdErr, code := t3cutil.DoInput(newFile, `t3c-diff`, args...) if code > 1 { return false, fmt.Errorf("t3c-diff returned error code %v stdout '%v' stderr '%v'", code, string(stdOut), string(stdErr)) } @@ -268,7 +273,7 @@ func diff(cfg config.Cfg, newFile []byte, fileLocation string, perm os.FileMode) } if code == 0 { - log.Infof("All lines match TrOps for config file: %s\n", fileLocation) + log.Infof("All lines and file permissions match TrOps for config file: %s\n", fileLocation) return false, nil // 0 is only returned if there's no diff } // code 1 means a diff, difference text will be on stdout diff --git a/cache-config/t3c-diff/t3c-diff.go b/cache-config/t3c-diff/t3c-diff.go index 1a0481d6aa..5252c9538b 100644 --- a/cache-config/t3c-diff/t3c-diff.go +++ b/cache-config/t3c-diff/t3c-diff.go @@ -35,9 +35,9 @@ import ( func main() { help := getopt.BoolLong("help", 'h', "Print usage info and exit") lineComment := getopt.StringLong("line_comment", 'l', "#", "Comment symbol") - mode := getopt.IntLong("mode", 'm', 0644, "file mode default is 644") - fa := getopt.StringLong("file_a", 'a', "", "first diff file") - fb := getopt.StringLong("file_b", 'b', "", "second diff file") + mode := getopt.IntLong("file-mode", 'm', 0644, "file mode default is 644") + fa := getopt.StringLong("file-a", 'a', "", "first diff file") + fb := getopt.StringLong("file-b", 'b', "", "second diff file") getopt.ParseV2() if *help { @@ -95,12 +95,12 @@ func main() { switch { case fileNameA != "stdin": if t3cutil.PermCk(fileNameA, *mode) { - fmt.Println("File permissions differ") + fmt.Println("File permissions are incorrect, should be ", *mode) os.Exit(1) } case fileNameB != "stdin": if t3cutil.PermCk(fileNameB, *mode) { - fmt.Println("File permissions differ") + fmt.Println("File permissions are incorrect, should be ", *mode) os.Exit(1) } } From e7435cd0d594dd76701f9a69a7c65c142590ab6d Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Thu, 16 Sep 2021 00:41:44 -0400 Subject: [PATCH 20/40] issue --- vendor/modules.txt | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/vendor/modules.txt b/vendor/modules.txt index 5bd4275edd..86d53406fd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -67,7 +67,7 @@ github.com/go-ozzo/ozzo-validation/is ## explicit github.com/gofrs/flock # github.com/golang-migrate/migrate/v4 v4.14.1 -## explicit +## explicit; go 1.13 github.com/golang-migrate/migrate/v4 github.com/golang-migrate/migrate/v4/database github.com/golang-migrate/migrate/v4/database/postgres @@ -76,7 +76,7 @@ github.com/golang-migrate/migrate/v4/source github.com/golang-migrate/migrate/v4/source/file github.com/golang-migrate/migrate/v4/source/httpfs # github.com/golang/protobuf v1.4.3 -## explicit +## explicit; go 1.9 github.com/golang/protobuf/proto # github.com/google/uuid v1.1.2 ## explicit @@ -85,7 +85,7 @@ github.com/google/uuid ## explicit github.com/hashicorp/errwrap # github.com/hashicorp/go-multierror v1.1.0 -## explicit +## explicit; go 1.14 github.com/hashicorp/go-multierror # github.com/hydrogen18/stoppableListener v0.0.0-20151210151943-dadc9ccc400c ## explicit @@ -106,7 +106,7 @@ github.com/json-iterator/go ## explicit github.com/kelseyhightower/envconfig # github.com/kylelemons/godebug v1.1.1-0.20201107061927-e693023230a4 -## explicit +## explicit; go 1.11 github.com/kylelemons/godebug/diff # github.com/lestrrat-go/jwx v0.9.1-0.20190702045520-e35178ac2b1f ## explicit @@ -121,12 +121,12 @@ github.com/lestrrat/go-jwx/internal/emap github.com/lestrrat/go-jwx/jwa github.com/lestrrat/go-jwx/jwk # github.com/lib/pq v1.8.0 -## explicit +## explicit; go 1.13 github.com/lib/pq github.com/lib/pq/oid github.com/lib/pq/scram # github.com/mattn/go-sqlite3 v1.14.5 -## explicit +## explicit; go 1.10 # github.com/miekg/dns v1.0.6-0.20180406150955-01d59357d468 ## explicit github.com/miekg/dns @@ -137,14 +137,14 @@ github.com/modern-go/concurrent ## explicit github.com/modern-go/reflect2 # github.com/nxadm/tail v1.4.4 -## explicit +## explicit; go 1.13 github.com/nxadm/tail github.com/nxadm/tail/ratelimiter github.com/nxadm/tail/util github.com/nxadm/tail/watch github.com/nxadm/tail/winfile # github.com/onsi/ginkgo v1.14.2 -## explicit +## explicit; go 1.13 github.com/onsi/ginkgo github.com/onsi/ginkgo/config github.com/onsi/ginkgo/internal/codelocation @@ -165,7 +165,7 @@ github.com/onsi/ginkgo/reporters/stenographer/support/go-colorable github.com/onsi/ginkgo/reporters/stenographer/support/go-isatty github.com/onsi/ginkgo/types # github.com/onsi/gomega v1.10.3 -## explicit +## explicit; go 1.14 github.com/onsi/gomega github.com/onsi/gomega/format github.com/onsi/gomega/internal/assertion @@ -179,25 +179,25 @@ github.com/onsi/gomega/matchers/support/goraph/node github.com/onsi/gomega/matchers/support/goraph/util github.com/onsi/gomega/types # github.com/pborman/getopt/v2 v2.1.0 -## explicit +## explicit; go 1.13 github.com/pborman/getopt/v2 # github.com/pkg/errors v0.9.1 ## explicit github.com/pkg/errors # github.com/stretchr/testify v1.6.1 -## explicit +## explicit; go 1.13 # go.etcd.io/bbolt v1.3.5 -## explicit +## explicit; go 1.12 go.etcd.io/bbolt # golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e -## explicit +## explicit; go 1.17 golang.org/x/crypto/ed25519 golang.org/x/crypto/ed25519/internal/edwards25519 golang.org/x/crypto/ocsp golang.org/x/crypto/pbkdf2 golang.org/x/crypto/scrypt # golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d -## explicit +## explicit; go 1.17 golang.org/x/net/bpf golang.org/x/net/html golang.org/x/net/html/atom @@ -212,12 +212,12 @@ golang.org/x/net/ipv4 golang.org/x/net/ipv6 golang.org/x/net/publicsuffix # golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 -## explicit +## explicit; go 1.17 golang.org/x/sys/internal/unsafeheader golang.org/x/sys/unix golang.org/x/sys/windows # golang.org/x/text v0.3.7 -## explicit +## explicit; go 1.17 golang.org/x/text/encoding golang.org/x/text/encoding/charmap golang.org/x/text/encoding/htmlindex @@ -239,11 +239,11 @@ golang.org/x/text/transform golang.org/x/text/unicode/bidi golang.org/x/text/unicode/norm # golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 -## explicit +## explicit; go 1.11 golang.org/x/xerrors golang.org/x/xerrors/internal # google.golang.org/protobuf v1.25.0 -## explicit +## explicit; go 1.9 google.golang.org/protobuf/encoding/prototext google.golang.org/protobuf/encoding/protowire google.golang.org/protobuf/internal/descfmt From 78593b590f752e942381bf5d8fb8c6a705958d49 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Thu, 16 Sep 2021 01:24:28 -0400 Subject: [PATCH 21/40] Removed Secure: false, not needed. --- lib/go-atscfg/astatsdotconfig.go | 1 - lib/go-atscfg/atsdotrules.go | 1 - lib/go-atscfg/bgfetchdotconfig.go | 1 - lib/go-atscfg/cachedotconfig.go | 1 - lib/go-atscfg/chkconfig.go | 1 - lib/go-atscfg/dropqstringdotconfig.go | 1 - lib/go-atscfg/facts.go | 1 - lib/go-atscfg/headerrewritedotconfig.go | 2 -- lib/go-atscfg/hostingdotconfig.go | 1 - lib/go-atscfg/ipallowdotconfig.go | 1 - lib/go-atscfg/ipallowdotyaml.go | 1 - lib/go-atscfg/loggingdotconfig.go | 1 - lib/go-atscfg/loggingdotyaml.go | 1 - lib/go-atscfg/logsdotxml.go | 1 - lib/go-atscfg/packages.go | 1 - lib/go-atscfg/parentdotconfig.go | 1 - lib/go-atscfg/plugindotconfig.go | 1 - lib/go-atscfg/recordsdotconfig.go | 1 - lib/go-atscfg/regexremapdotconfig.go | 1 - lib/go-atscfg/regexrevalidatedotconfig.go | 1 - lib/go-atscfg/remapdotconfig.go | 1 - lib/go-atscfg/servercachedotconfig.go | 1 - lib/go-atscfg/serverunknown.go | 1 - lib/go-atscfg/setdscpdotconfig.go | 1 - lib/go-atscfg/snidotyaml.go | 1 - lib/go-atscfg/sslservernamedotyaml.go | 1 - lib/go-atscfg/storagedotconfig.go | 1 - lib/go-atscfg/sysctldotconf.go | 1 - lib/go-atscfg/volumedotconfig.go | 1 - 29 files changed, 30 deletions(-) diff --git a/lib/go-atscfg/astatsdotconfig.go b/lib/go-atscfg/astatsdotconfig.go index b03d970f6f..9dc09c7f5c 100644 --- a/lib/go-atscfg/astatsdotconfig.go +++ b/lib/go-atscfg/astatsdotconfig.go @@ -65,7 +65,6 @@ func MakeAStatsDotConfig( Text: txt, ContentType: ContentTypeAstatsDotConfig, LineComment: LineCommentAstatsDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/atsdotrules.go b/lib/go-atscfg/atsdotrules.go index faa216d1bf..ea80de4fe1 100644 --- a/lib/go-atscfg/atsdotrules.go +++ b/lib/go-atscfg/atsdotrules.go @@ -77,7 +77,6 @@ func MakeATSDotRules( Text: text, ContentType: ContentTypeATSDotRules, LineComment: LineCommentATSDotRules, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/bgfetchdotconfig.go b/lib/go-atscfg/bgfetchdotconfig.go index f01bef2faf..0caa5b69ff 100644 --- a/lib/go-atscfg/bgfetchdotconfig.go +++ b/lib/go-atscfg/bgfetchdotconfig.go @@ -50,7 +50,6 @@ func MakeBGFetchDotConfig( Text: text, ContentType: ContentTypeBGFetchDotConfig, LineComment: LineCommentBGFetchDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/cachedotconfig.go b/lib/go-atscfg/cachedotconfig.go index 46f0b22617..a98da6775b 100644 --- a/lib/go-atscfg/cachedotconfig.go +++ b/lib/go-atscfg/cachedotconfig.go @@ -160,7 +160,6 @@ func makeCacheDotConfigEdge( Text: text, ContentType: ContentTypeCacheDotConfig, LineComment: LineCommentCacheDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/chkconfig.go b/lib/go-atscfg/chkconfig.go index 7730ccdc20..67ba959e94 100644 --- a/lib/go-atscfg/chkconfig.go +++ b/lib/go-atscfg/chkconfig.go @@ -64,7 +64,6 @@ func MakeChkconfig( Text: string(bts), ContentType: ContentTypeChkconfig, LineComment: LineCommentChkconfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/dropqstringdotconfig.go b/lib/go-atscfg/dropqstringdotconfig.go index 61af5a9113..c8d8d9c84b 100644 --- a/lib/go-atscfg/dropqstringdotconfig.go +++ b/lib/go-atscfg/dropqstringdotconfig.go @@ -73,7 +73,6 @@ func MakeDropQStringDotConfig( Text: text, ContentType: ContentTypeDropQStringDotConfig, LineComment: LineCommentDropQStringDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/facts.go b/lib/go-atscfg/facts.go index 92f3e1db5b..750e23a64f 100644 --- a/lib/go-atscfg/facts.go +++ b/lib/go-atscfg/facts.go @@ -51,7 +51,6 @@ func Make12MFacts( Text: txt, ContentType: ContentType12MFacts, LineComment: LineComment12MFacts, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/headerrewritedotconfig.go b/lib/go-atscfg/headerrewritedotconfig.go index 7185e43598..c7f41723ca 100644 --- a/lib/go-atscfg/headerrewritedotconfig.go +++ b/lib/go-atscfg/headerrewritedotconfig.go @@ -136,7 +136,6 @@ func MakeHeaderRewriteDotConfig( Text: "", ContentType: ContentTypeHeaderRewriteDotConfig, LineComment: LineCommentHeaderRewriteDotConfig, - Secure: false, Warnings: warnings, }, nil } @@ -200,7 +199,6 @@ func MakeHeaderRewriteDotConfig( Text: text, ContentType: ContentTypeHeaderRewriteDotConfig, LineComment: LineCommentHeaderRewriteDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/hostingdotconfig.go b/lib/go-atscfg/hostingdotconfig.go index e383618d5f..611d93d037 100644 --- a/lib/go-atscfg/hostingdotconfig.go +++ b/lib/go-atscfg/hostingdotconfig.go @@ -222,7 +222,6 @@ func MakeHostingDotConfig( Text: text, ContentType: ContentTypeHostingDotConfig, LineComment: LineCommentHostingDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/ipallowdotconfig.go b/lib/go-atscfg/ipallowdotconfig.go index 4279fd8f93..ab45f6e68e 100644 --- a/lib/go-atscfg/ipallowdotconfig.go +++ b/lib/go-atscfg/ipallowdotconfig.go @@ -330,7 +330,6 @@ func MakeIPAllowDotConfig( Text: text, ContentType: ContentTypeHostingDotConfig, LineComment: LineCommentHostingDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/ipallowdotyaml.go b/lib/go-atscfg/ipallowdotyaml.go index d3d12d9c84..e2b7663125 100644 --- a/lib/go-atscfg/ipallowdotyaml.go +++ b/lib/go-atscfg/ipallowdotyaml.go @@ -343,7 +343,6 @@ ip_allow:` Text: text, ContentType: ContentTypeHostingDotConfig, LineComment: LineCommentHostingDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/loggingdotconfig.go b/lib/go-atscfg/loggingdotconfig.go index 17ff7b5c69..24878c9cac 100644 --- a/lib/go-atscfg/loggingdotconfig.go +++ b/lib/go-atscfg/loggingdotconfig.go @@ -147,7 +147,6 @@ func MakeLoggingDotConfig( Text: text, ContentType: ContentTypeLoggingDotConfig, LineComment: LineCommentLoggingDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/loggingdotyaml.go b/lib/go-atscfg/loggingdotyaml.go index d383f5ecb5..aa05a8a972 100644 --- a/lib/go-atscfg/loggingdotyaml.go +++ b/lib/go-atscfg/loggingdotyaml.go @@ -163,7 +163,6 @@ func MakeLoggingDotYAML( Text: text, ContentType: ContentTypeLoggingDotYAML, LineComment: LineCommentLoggingDotYAML, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/logsdotxml.go b/lib/go-atscfg/logsdotxml.go index ff22e15271..a493821987 100644 --- a/lib/go-atscfg/logsdotxml.go +++ b/lib/go-atscfg/logsdotxml.go @@ -118,7 +118,6 @@ func MakeLogsXMLDotConfig( Text: text, ContentType: ContentTypeLogsDotXML, LineComment: LineCommentLogsDotXML, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/packages.go b/lib/go-atscfg/packages.go index fb9ce80919..c6e4b29622 100644 --- a/lib/go-atscfg/packages.go +++ b/lib/go-atscfg/packages.go @@ -66,7 +66,6 @@ func MakePackages( Text: string(bts), ContentType: ContentTypePackages, LineComment: LineCommentPackages, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/parentdotconfig.go b/lib/go-atscfg/parentdotconfig.go index 2837d80830..9fe657b292 100644 --- a/lib/go-atscfg/parentdotconfig.go +++ b/lib/go-atscfg/parentdotconfig.go @@ -463,7 +463,6 @@ func MakeParentDotConfig( Text: text, ContentType: ContentTypeParentDotConfig, LineComment: LineCommentParentDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/plugindotconfig.go b/lib/go-atscfg/plugindotconfig.go index 003e13c565..1d2d43d2f3 100644 --- a/lib/go-atscfg/plugindotconfig.go +++ b/lib/go-atscfg/plugindotconfig.go @@ -63,7 +63,6 @@ func MakePluginDotConfig( Text: txt, ContentType: ContentTypePluginDotConfig, LineComment: LineCommentPluginDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/recordsdotconfig.go b/lib/go-atscfg/recordsdotconfig.go index 2318449775..0e708029ff 100644 --- a/lib/go-atscfg/recordsdotconfig.go +++ b/lib/go-atscfg/recordsdotconfig.go @@ -88,7 +88,6 @@ func MakeRecordsDotConfig( Text: txt, ContentType: ContentTypeRecordsDotConfig, LineComment: LineCommentRecordsDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/regexremapdotconfig.go b/lib/go-atscfg/regexremapdotconfig.go index 8889ab430a..bb21cc742e 100644 --- a/lib/go-atscfg/regexremapdotconfig.go +++ b/lib/go-atscfg/regexremapdotconfig.go @@ -93,7 +93,6 @@ func MakeRegexRemapDotConfig( Text: text, ContentType: ContentTypeRegexRemapDotConfig, LineComment: LineCommentRegexRemapDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/regexrevalidatedotconfig.go b/lib/go-atscfg/regexrevalidatedotconfig.go index 82c035f2fa..f20d78bdeb 100644 --- a/lib/go-atscfg/regexrevalidatedotconfig.go +++ b/lib/go-atscfg/regexrevalidatedotconfig.go @@ -122,7 +122,6 @@ func MakeRegexRevalidateDotConfig( Text: txt, ContentType: ContentTypeRegexRevalidateDotConfig, LineComment: LineCommentRegexRevalidateDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/remapdotconfig.go b/lib/go-atscfg/remapdotconfig.go index b24aff76b6..7803dcf54e 100644 --- a/lib/go-atscfg/remapdotconfig.go +++ b/lib/go-atscfg/remapdotconfig.go @@ -112,7 +112,6 @@ func MakeRemapDotConfig( Text: txt, ContentType: ContentTypeRemapDotConfig, LineComment: LineCommentRemapDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/servercachedotconfig.go b/lib/go-atscfg/servercachedotconfig.go index 65cfe8c39c..0bfad5bc56 100644 --- a/lib/go-atscfg/servercachedotconfig.go +++ b/lib/go-atscfg/servercachedotconfig.go @@ -87,7 +87,6 @@ func makeCacheDotConfigMid( Text: text, ContentType: ContentTypeCacheDotConfig, LineComment: LineCommentCacheDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/serverunknown.go b/lib/go-atscfg/serverunknown.go index ffd65d2663..810044e9a5 100644 --- a/lib/go-atscfg/serverunknown.go +++ b/lib/go-atscfg/serverunknown.go @@ -86,7 +86,6 @@ func MakeServerUnknown( Text: txt, ContentType: ContentTypeServerUnknownConfig, LineComment: lineComment, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/setdscpdotconfig.go b/lib/go-atscfg/setdscpdotconfig.go index 858d25b9af..1de930cbb8 100644 --- a/lib/go-atscfg/setdscpdotconfig.go +++ b/lib/go-atscfg/setdscpdotconfig.go @@ -68,7 +68,6 @@ func MakeSetDSCPDotConfig( Text: text, ContentType: ContentTypeSetDSCPDotConfig, LineComment: LineCommentSetDSCPDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/snidotyaml.go b/lib/go-atscfg/snidotyaml.go index 8d9329f16f..3fdd504d94 100644 --- a/lib/go-atscfg/snidotyaml.go +++ b/lib/go-atscfg/snidotyaml.go @@ -127,7 +127,6 @@ func MakeSNIDotYAML( Text: txt, ContentType: ContentTypeSNIDotYAML, LineComment: LineCommentSNIDotYAML, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/sslservernamedotyaml.go b/lib/go-atscfg/sslservernamedotyaml.go index 0cd534d639..06d76cf33f 100644 --- a/lib/go-atscfg/sslservernamedotyaml.go +++ b/lib/go-atscfg/sslservernamedotyaml.go @@ -181,7 +181,6 @@ func MakeSSLServerNameYAML( Text: txt, ContentType: ContentTypeSSLServerNameYAML, LineComment: LineCommentSSLServerNameYAML, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/storagedotconfig.go b/lib/go-atscfg/storagedotconfig.go index e657332d51..642e6609ab 100644 --- a/lib/go-atscfg/storagedotconfig.go +++ b/lib/go-atscfg/storagedotconfig.go @@ -98,7 +98,6 @@ func MakeStorageDotConfig( Text: text, ContentType: ContentTypeStorageDotConfig, LineComment: LineCommentStorageDotConfig, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/sysctldotconf.go b/lib/go-atscfg/sysctldotconf.go index fa36f61bd9..bb2e765f45 100644 --- a/lib/go-atscfg/sysctldotconf.go +++ b/lib/go-atscfg/sysctldotconf.go @@ -63,7 +63,6 @@ func MakeSysCtlDotConf( Text: txt, ContentType: ContentTypeSysctlDotConf, LineComment: LineCommentSysctlDotConf, - Secure: false, Warnings: warnings, }, nil } diff --git a/lib/go-atscfg/volumedotconfig.go b/lib/go-atscfg/volumedotconfig.go index de3fa20a77..ef58139f4c 100644 --- a/lib/go-atscfg/volumedotconfig.go +++ b/lib/go-atscfg/volumedotconfig.go @@ -84,7 +84,6 @@ func MakeVolumeDotConfig( Text: hdr + text, ContentType: ContentTypeVolumeDotConfig, LineComment: LineCommentVolumeDotConfig, - Secure: false, Warnings: warnings, }, nil } From 932949629593585825b056f55a32448cc69d1c16 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 17 Sep 2021 16:04:05 -0400 Subject: [PATCH 22/40] changed print format. --- cache-config/t3c-apply/torequest/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache-config/t3c-apply/torequest/cmd.go b/cache-config/t3c-apply/torequest/cmd.go index 9200a608d0..6939382e09 100644 --- a/cache-config/t3c-apply/torequest/cmd.go +++ b/cache-config/t3c-apply/torequest/cmd.go @@ -261,7 +261,7 @@ func diff(cfg config.Cfg, newFile []byte, fileLocation string, perm os.FileMode) args := []string{ "--file-a=stdin", "--file-b=" + fileLocation, - "--file-mode=" + fmt.Sprintf("%o", perm), + "--file-mode=" + fmt.Sprintf("%#o", perm), } stdOut, stdErr, code := t3cutil.DoInput(newFile, `t3c-diff`, args...) From 2aeaa935e667931c4cf714dea8909a865e4996ca Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 17 Sep 2021 16:04:56 -0400 Subject: [PATCH 23/40] removed debugging line. --- cache-config/t3c-apply/torequest/torequest.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go index ab4d91838f..37812cd097 100644 --- a/cache-config/t3c-apply/torequest/torequest.go +++ b/cache-config/t3c-apply/torequest/torequest.go @@ -230,7 +230,6 @@ func (r *TrafficOpsReq) checkConfigFile(cfg *ConfigFile, filesAdding []string) e return errors.New("unable to process udev rules in '" + cfg.Name + "': " + err.Error()) } } - log.Infof("File mode is: %o", cfg.Perm) log.Infof("======== End processing config file: %s for service: %s ========\n", cfg.Name, cfg.Service) return nil } From 823cd742d3da8d8d649c989fff729cfe1894585f Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 17 Sep 2021 16:06:26 -0400 Subject: [PATCH 24/40] changed format to print octal. --- cache-config/t3c-diff/t3c-diff.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache-config/t3c-diff/t3c-diff.go b/cache-config/t3c-diff/t3c-diff.go index 5252c9538b..558043456f 100644 --- a/cache-config/t3c-diff/t3c-diff.go +++ b/cache-config/t3c-diff/t3c-diff.go @@ -95,12 +95,12 @@ func main() { switch { case fileNameA != "stdin": if t3cutil.PermCk(fileNameA, *mode) { - fmt.Println("File permissions are incorrect, should be ", *mode) + fmt.Println("File permissions are incorrect, should be ", fmt.Sprintf("%#o", *mode)) os.Exit(1) } case fileNameB != "stdin": if t3cutil.PermCk(fileNameB, *mode) { - fmt.Println("File permissions are incorrect, should be ", *mode) + fmt.Println("File permissions are incorrect, should be ", fmt.Sprintf("%#o", *mode)) os.Exit(1) } } From a0bb53aa209337e53895bcd154539e20f56f244c Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 17 Sep 2021 16:07:56 -0400 Subject: [PATCH 25/40] Compare was not working correctly fixed. --- cache-config/t3cutil/t3cutil.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cache-config/t3cutil/t3cutil.go b/cache-config/t3cutil/t3cutil.go index ad0aecce53..59dea1f5e9 100644 --- a/cache-config/t3cutil/t3cutil.go +++ b/cache-config/t3cutil/t3cutil.go @@ -74,11 +74,12 @@ func CommentsFilter(body []string, lineComment string) []string { // PermCk will compare file permissions against existing file and octal permission provided. func PermCk(path string, perm int) bool { + mode := os.FileMode(perm) file, err := os.Stat(path) if err != nil { - fmt.Println("Error opening file ", path) + fmt.Println("Error getting file status", path) } - if file.Mode() != os.FileMode(perm) { + if file.Mode() != mode.Perm() { return true } return false From f2468dd48b012782268c3853c0a021519eca7f1b Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Mon, 20 Sep 2021 16:45:58 -0400 Subject: [PATCH 26/40] Changed formatting for log output line 472 --- cache-config/t3c-apply/torequest/torequest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go index 37812cd097..ab3da02e02 100644 --- a/cache-config/t3c-apply/torequest/torequest.go +++ b/cache-config/t3c-apply/torequest/torequest.go @@ -469,7 +469,7 @@ func (r *TrafficOpsReq) replaceCfgFile(cfg *ConfigFile) error { } tmpFileName := cfg.Path + configFileTempSuffix - log.Infof("Writing temp file '%s' with file mode: %o \n", tmpFileName, cfg.Perm) + log.Infof("Writing temp file '%s' with file mode: '%#o' \n", tmpFileName, cfg.Perm) // write a new file, then move to the real location // because moving is atomic but writing is not. From 083d6e74b339cb0d1098b30019272c0e80a4e0b8 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 24 Sep 2021 17:24:44 -0400 Subject: [PATCH 27/40] Changed to take input from stdin. --- .../t3c-check-reload/t3c-check-reload.go | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cache-config/t3c-check-reload/t3c-check-reload.go b/cache-config/t3c-check-reload/t3c-check-reload.go index d73f6b10b2..c93ac2af21 100644 --- a/cache-config/t3c-check-reload/t3c-check-reload.go +++ b/cache-config/t3c-check-reload/t3c-check-reload.go @@ -20,21 +20,21 @@ package main */ import ( + "encoding/json" "fmt" + "github.com/pborman/getopt/v2" "os" "strings" "github.com/apache/trafficcontrol/cache-config/t3cutil" - - "github.com/pborman/getopt/v2" ) func main() { // presumably calculated by by t3c-check-refs // TODO remove? The blueprint says t3c/ORT will no longer install packages - pluginPackagesInstalledStr := getopt.StringLong("plugin-packages-installed", 'p', "", "comma-delimited list of ATS plugin packages which were installed by t3c") + //pluginPackagesInstalledStr := getopt.StringLong("plugin-packages-installed", 'p', "", "comma-delimited list of ATS plugin packages which were installed by t3c") // presumably calculated by t3c-diff - changedConfigFilesStr := getopt.StringLong("changed-config-paths", 'c', "", "comma-delimited list of the full paths of all files changed by t3c") + //changedConfigFilesStr := getopt.StringLong("changed-config-paths", 'c', "", "comma-delimited list of the full paths of all files changed by t3c") help := getopt.BoolLong("help", 'h', "Print usage information and exit") getopt.Parse() @@ -43,7 +43,12 @@ func main() { os.Exit(0) } - changedConfigFiles := strings.Split(*changedConfigFilesStr, ",") + changedCfg := &ChangedCfg{} + if err := json.NewDecoder(os.Stdin).Decode(changedCfg); err != nil { + fmt.Println("Error reading json input", err) + } + + changedConfigFiles := strings.Split(changedCfg.ChangedFiles, ",") changedConfigFiles = StrMap(changedConfigFiles, strings.TrimSpace) changedConfigFiles = StrRemoveIf(changedConfigFiles, StrIsEmpty) @@ -51,7 +56,7 @@ func main() { // Probably not, because whatever told the installer to install them already knew that, // we shouldn't re-calculate it. - pluginPackagesInstalled := strings.Split(*pluginPackagesInstalledStr, ",") + pluginPackagesInstalled := strings.Split(changedCfg.InstalledPlugins, ",") pluginPackagesInstalled = StrMap(pluginPackagesInstalled, strings.TrimSpace) pluginPackagesInstalled = StrRemoveIf(pluginPackagesInstalled, StrIsEmpty) @@ -99,6 +104,11 @@ func main() { ExitNothing() } +type ChangedCfg struct { + ChangedFiles string `json:"changed_files"` + InstalledPlugins string `json:"installed_plugins"` +} + // ExitRestart returns the "needs restart" message and exits. func ExitRestart() { fmt.Fprintf(os.Stdout, t3cutil.ServiceNeedsRestart.String()+"\n") From ce5079a05db735400f4f67001277437a9cb267f6 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 24 Sep 2021 17:26:00 -0400 Subject: [PATCH 28/40] Removed cfg.Name from append. cfg.Path has the filename. --- cache-config/t3c-apply/torequest/torequest.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go index ab3da02e02..f0fb9a1e96 100644 --- a/cache-config/t3c-apply/torequest/torequest.go +++ b/cache-config/t3c-apply/torequest/torequest.go @@ -485,7 +485,7 @@ func (r *TrafficOpsReq) replaceCfgFile(cfg *ConfigFile) error { return errors.New("Failed to move temp '" + tmpFileName + "' to real '" + cfg.Path + "': " + err.Error()) } cfg.ChangeApplied = true - r.changedFiles = append(r.changedFiles, filepath.Join(cfg.Path, cfg.Name)) + r.changedFiles = append(r.changedFiles, cfg.Path) r.RemapConfigReload = r.RemapConfigReload || cfg.RemapPluginConfig || From d5384a36d275073b9390220f66dcd965d60fd5af Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 24 Sep 2021 17:28:45 -0400 Subject: [PATCH 29/40] Changed checkReload func to call t3c-check-reload and send data to stdin. --- cache-config/t3c-apply/torequest/cmd.go | 47 ++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/cache-config/t3c-apply/torequest/cmd.go b/cache-config/t3c-apply/torequest/cmd.go index 6939382e09..9659f5b727 100644 --- a/cache-config/t3c-apply/torequest/cmd.go +++ b/cache-config/t3c-apply/torequest/cmd.go @@ -331,10 +331,49 @@ func checkRefs(cfg config.Cfg, cfgFile []byte, filesAdding []string) error { func checkReload(pluginPackagesInstalled []string, changedConfigFiles []string) (t3cutil.ServiceNeeds, error) { log.Infof("t3c-check-reload calling with pluginPackagesInstalled '%v' changedConfigFiles '%v'\n", pluginPackagesInstalled, changedConfigFiles) - stdOut, stdErr, code := t3cutil.Do(`t3c`, `check`, `reload`, - "--plugin-packages-installed="+strings.Join(pluginPackagesInstalled, ","), - "--changed-config-paths="+strings.Join(changedConfigFiles, ","), - ) + changedFiles := []byte(strings.Join(changedConfigFiles, ",")) + installedPlugins := []byte(strings.Join(pluginPackagesInstalled, ",")) + + cmd := exec.Command(`t3c-check-reload`) + outBuf := bytes.Buffer{} + errBuf := bytes.Buffer{} + cmd.Stdout = &outBuf + cmd.Stderr = &errBuf + + stdinPipe, err := cmd.StdinPipe() + if err != nil { + return t3cutil.ServiceNeedsInvalid, errors.New("getting command pipe: " + err.Error()) + } + + if err := cmd.Start(); err != nil { + return t3cutil.ServiceNeedsInvalid, errors.New("starting command: " + err.Error()) + } + + if _, err := stdinPipe.Write([]byte(`{"changed_files":"`)); err != nil { + return t3cutil.ServiceNeedsInvalid, errors.New("writing opening json to input: " + err.Error()) + } else if _, err := stdinPipe.Write(changedFiles); err != nil { + return t3cutil.ServiceNeedsInvalid, errors.New("writing changed files to input: " + err.Error()) + } else if _, err := stdinPipe.Write([]byte(`","installed_plugins":"`)); err != nil { + return t3cutil.ServiceNeedsInvalid, errors.New("writing installed_plugins key to input: " + err.Error()) + } else if _, err := stdinPipe.Write(installedPlugins); err != nil { + return t3cutil.ServiceNeedsInvalid, errors.New("writing plugins to input: " + err.Error()) + } else if _, err := stdinPipe.Write([]byte(`"}`)); err != nil { + return t3cutil.ServiceNeedsInvalid, errors.New("writing closing json input: " + err.Error()) + } else if err := stdinPipe.Close(); err != nil { + return t3cutil.ServiceNeedsInvalid, errors.New("closing stdin writer: " + err.Error()) + } + + code := 0 // if cmd.Wait returns no error, that means the command returned 0 + if err := cmd.Wait(); err != nil { + if exitErr, ok := err.(*exec.ExitError); !ok { + return t3cutil.ServiceNeedsInvalid, errors.New("error running command: " + err.Error()) + } else { + code = exitErr.ExitCode() + } + } + + stdOut := outBuf.Bytes() + stdErr := errBuf.Bytes() if code != 0 { log.Errorf(`t3c-check-reload errors start From 2501bd04a796d1d6af532f3e48a24c937b2237f9 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 24 Sep 2021 21:02:15 -0400 Subject: [PATCH 30/40] updated check-reload-test --- .../ort-tests/t3c-check-reload_test.go | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cache-config/testing/ort-tests/t3c-check-reload_test.go b/cache-config/testing/ort-tests/t3c-check-reload_test.go index ee33a9fd1a..91406c6ea6 100644 --- a/cache-config/testing/ort-tests/t3c-check-reload_test.go +++ b/cache-config/testing/ort-tests/t3c-check-reload_test.go @@ -15,6 +15,8 @@ package orttest */ import ( + "encoding/json" + tc_log "github.com/apache/trafficcontrol/lib/go-log" "strings" "testing" @@ -113,12 +115,26 @@ func TestCheckReload(t *testing.T) { } } +type ChangedCfg struct { + ChangedFiles string `json:"changed_files"` + InstalledPlugins string `json:"installed_plugins"` +} + func t3cCheckReload(changedConfigPaths []string, packagesInstalled []string) (string, int) { + config := ChangedCfg{ + ChangedFiles: strings.Join(changedConfigPaths, ","), + InstalledPlugins: strings.Join(packagesInstalled, ","), + } args := []string{ "check", "reload", - "--changed-config-paths=" + strings.Join(changedConfigPaths, ","), - "--plugin-packages-installed=" + strings.Join(packagesInstalled, ","), + //"--changed-config-paths=" + strings.Join(changedConfigPaths, ","), + //"--plugin-packages-installed=" + strings.Join(packagesInstalled, ","), + } + data, err := json.Marshal(config) + if err != nil { + tc_log.Errorln("error") } - stdOut, _, exitCode := t3cutil.Do("t3c", args...) + stdOut, _, exitCode := t3cutil.DoInput(data, "t3c", args...) + //stdOut, _, exitCode := t3cutil.Do("t3c", args...) return string(stdOut), exitCode } From 16ca6fde958552d69ab96a59673f30c3cbee2520 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Fri, 24 Sep 2021 22:14:23 -0400 Subject: [PATCH 31/40] updated check-reload-test --- .../ort-tests/t3c-check-reload_test.go | 123 ++++++++++-------- 1 file changed, 72 insertions(+), 51 deletions(-) diff --git a/cache-config/testing/ort-tests/t3c-check-reload_test.go b/cache-config/testing/ort-tests/t3c-check-reload_test.go index 91406c6ea6..49c4f337e9 100644 --- a/cache-config/testing/ort-tests/t3c-check-reload_test.go +++ b/cache-config/testing/ort-tests/t3c-check-reload_test.go @@ -16,7 +16,6 @@ package orttest import ( "encoding/json" - tc_log "github.com/apache/trafficcontrol/lib/go-log" "strings" "testing" @@ -24,117 +23,139 @@ import ( ) func TestCheckReload(t *testing.T) { + type ChangedCfg struct { + ChangedFiles string `json:"changed_files"` + InstalledPlugins string `json:"installed_plugins"` + } + type argsResults struct { - configs []string - packages []string + configs ChangedCfg mode string expected string expectedErr bool } + argsExpected := []argsResults{ { - configs: []string{"/etc/trafficserver/remap.config", "/etc/trafficserver/parent.config"}, - packages: nil, + configs: ChangedCfg{ + ChangedFiles: "/etc/trafficserver/remap.config,/etc/trafficserver/parent.config", + InstalledPlugins: "", + }, expected: "reload", }, { - configs: []string{"/etc/trafficserver/anything.foo"}, - packages: nil, + configs: ChangedCfg{ + ChangedFiles: "/etc/trafficserver/anything.foo", + InstalledPlugins: "", + }, expected: "reload", }, { - configs: []string{"/opt/trafficserver/etc/trafficserver/anything.foo"}, - packages: nil, + configs: ChangedCfg{ + ChangedFiles: "/opt/trafficserver/etc/trafficserver/anything.foo", + InstalledPlugins: "", + }, expected: "reload", }, { - configs: []string{"/foo/bar/hdr_rw_foo.config"}, - packages: nil, + configs: ChangedCfg{ + ChangedFiles: "/foo/bar/hdr_rw_foo.config", + InstalledPlugins: "", + }, expected: "reload", }, { - configs: []string{"/foo/bar/uri_signing_dsname.config"}, - packages: nil, + configs: ChangedCfg{ + ChangedFiles: "/foo/bar/uri_signing_dsname.config", + InstalledPlugins: "", + }, expected: "reload", }, { - configs: []string{"/foo/bar/url_sig_dsname.config", "foo"}, - packages: nil, + configs: ChangedCfg{ + ChangedFiles: "/foo/bar/url_sig_dsname.config,foo", + InstalledPlugins: "", + }, expected: "reload", }, { - configs: []string{"plugin.config", "foo"}, - packages: nil, + configs: ChangedCfg{ + ChangedFiles: "plugin.config,foo", + InstalledPlugins: "", + }, expected: "restart", }, { - configs: []string{"/etc/trafficserver/anything.foo"}, - packages: []string{"anything"}, + configs: ChangedCfg{ + ChangedFiles: "/etc/trafficserver/anything.foo", + InstalledPlugins: "anything", + }, expected: "restart", }, { - configs: nil, - packages: []string{"anything"}, + configs: ChangedCfg{ + ChangedFiles: "", + InstalledPlugins: "anything", + }, expected: "restart", }, { - configs: nil, - packages: []string{"anything", "anythingelse"}, + configs: ChangedCfg{ + ChangedFiles: "", + InstalledPlugins: "anything,anythingelse", + }, expected: "restart", }, { - configs: []string{"/foo/bar/ssl_multicert.config"}, - packages: nil, + configs: ChangedCfg{ + ChangedFiles: "/foo/bar/ssl_multicert.config", + InstalledPlugins: "", + }, expected: "reload", }, { - configs: []string{"foo"}, - packages: nil, + configs: ChangedCfg{ + ChangedFiles: "foo", + InstalledPlugins: "", + }, expected: "", }, { - configs: []string{"/foo/bar/baz.config"}, - packages: nil, + configs: ChangedCfg{ + ChangedFiles: "/foo/bar/baz.config", + InstalledPlugins: "", + }, expected: "", }, } for _, ae := range argsExpected { - out, code := t3cCheckReload(ae.configs, ae.packages) + config, err := json.Marshal(ae.configs) + if err != nil { + t.Errorf("Error: %s", err) + } + out, code := t3cCheckReload(config) out = strings.TrimSpace(out) if !ae.expectedErr && code != 0 { - t.Errorf("expected configs %+v packages %+v would not error, actual: code %v output '%v'", ae.configs, ae.packages, code, out) + t.Errorf("expected configs %+v packages %+v would not error, actual: code %v output '%v'", + ae.configs.ChangedFiles, ae.configs.InstalledPlugins, code, out) continue } else if ae.expectedErr && code == 0 { - t.Errorf("expected configs %+v packages %+v would error, actual: no error", ae.configs, ae.packages) + t.Errorf("expected configs %+v packages %+v would error, actual: no error", + ae.configs.ChangedFiles, ae.configs.InstalledPlugins) continue } if out != ae.expected { - t.Errorf("expected configs %+v packages %+v would need '%v', actual: '%v'", ae.configs, ae.packages, ae.expected, out) + t.Errorf("expected configs %+v packages %+v would need '%v', actual: '%v'", + ae.configs.ChangedFiles, ae.configs.InstalledPlugins, ae.expected, out) } } } -type ChangedCfg struct { - ChangedFiles string `json:"changed_files"` - InstalledPlugins string `json:"installed_plugins"` -} - -func t3cCheckReload(changedConfigPaths []string, packagesInstalled []string) (string, int) { - config := ChangedCfg{ - ChangedFiles: strings.Join(changedConfigPaths, ","), - InstalledPlugins: strings.Join(packagesInstalled, ","), - } +func t3cCheckReload(configs []byte) (string, int) { args := []string{ "check", "reload", - //"--changed-config-paths=" + strings.Join(changedConfigPaths, ","), - //"--plugin-packages-installed=" + strings.Join(packagesInstalled, ","), - } - data, err := json.Marshal(config) - if err != nil { - tc_log.Errorln("error") } - stdOut, _, exitCode := t3cutil.DoInput(data, "t3c", args...) - //stdOut, _, exitCode := t3cutil.Do("t3c", args...) + stdOut, _, exitCode := t3cutil.DoInput(configs, "t3c", args...) return string(stdOut), exitCode } From 3c3df56ff561bf99ed6261587936a7b54ed8fdf6 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Sat, 25 Sep 2021 11:33:23 -0400 Subject: [PATCH 32/40] Reordered imports. --- cache-config/t3c-check-reload/t3c-check-reload.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cache-config/t3c-check-reload/t3c-check-reload.go b/cache-config/t3c-check-reload/t3c-check-reload.go index c93ac2af21..2397f66606 100644 --- a/cache-config/t3c-check-reload/t3c-check-reload.go +++ b/cache-config/t3c-check-reload/t3c-check-reload.go @@ -22,11 +22,12 @@ package main import ( "encoding/json" "fmt" - "github.com/pborman/getopt/v2" "os" "strings" "github.com/apache/trafficcontrol/cache-config/t3cutil" + + "github.com/pborman/getopt/v2" ) func main() { From 287e235ffd2b7eac5fe24f90b2d86563f420ee23 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Sat, 25 Sep 2021 11:34:20 -0400 Subject: [PATCH 33/40] line spacing. --- cache-config/t3c-apply/torequest/torequest.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cache-config/t3c-apply/torequest/torequest.go b/cache-config/t3c-apply/torequest/torequest.go index f0fb9a1e96..6debb9d9a1 100644 --- a/cache-config/t3c-apply/torequest/torequest.go +++ b/cache-config/t3c-apply/torequest/torequest.go @@ -230,6 +230,7 @@ func (r *TrafficOpsReq) checkConfigFile(cfg *ConfigFile, filesAdding []string) e return errors.New("unable to process udev rules in '" + cfg.Name + "': " + err.Error()) } } + log.Infof("======== End processing config file: %s for service: %s ========\n", cfg.Name, cfg.Service) return nil } From 55eb00c6773087ff0e2deb4b698d8848e7a980e4 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Tue, 28 Sep 2021 14:32:37 -0400 Subject: [PATCH 34/40] Updated usage information. --- cache-config/t3c-check-reload/t3c-check-reload.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cache-config/t3c-check-reload/t3c-check-reload.go b/cache-config/t3c-check-reload/t3c-check-reload.go index 2397f66606..7be2ec3c28 100644 --- a/cache-config/t3c-check-reload/t3c-check-reload.go +++ b/cache-config/t3c-check-reload/t3c-check-reload.go @@ -33,14 +33,12 @@ import ( func main() { // presumably calculated by by t3c-check-refs // TODO remove? The blueprint says t3c/ORT will no longer install packages - //pluginPackagesInstalledStr := getopt.StringLong("plugin-packages-installed", 'p', "", "comma-delimited list of ATS plugin packages which were installed by t3c") - // presumably calculated by t3c-diff - //changedConfigFilesStr := getopt.StringLong("changed-config-paths", 'c', "", "comma-delimited list of the full paths of all files changed by t3c") + help := getopt.BoolLong("help", 'h', "Print usage information and exit") getopt.Parse() if *help { - getopt.PrintUsage(os.Stdout) + fmt.Println(usageStr()) os.Exit(0) } @@ -152,3 +150,9 @@ func StrRemoveIf(strs []string, fn func(str string) bool) []string { // StrIsEmpty returns whether str == "". Helper function for composing with other functions. func StrIsEmpty(str string) bool { return str == "" } + +func usageStr() string { + return `usage: t3c-check-reload [--help] +Accepts json data from stdin in in the following format: +{"changed_files":"","installed_plugins":""}` +} From 16318e5494141de642e7d3a8f7edf2b8f5bfc865 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Tue, 28 Sep 2021 14:33:24 -0400 Subject: [PATCH 35/40] Updated usage information. --- cache-config/t3c-check-reload/README.md | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/cache-config/t3c-check-reload/README.md b/cache-config/t3c-check-reload/README.md index af69e32bf0..fcce5823c1 100644 --- a/cache-config/t3c-check-reload/README.md +++ b/cache-config/t3c-check-reload/README.md @@ -39,14 +39,15 @@ t3c-check-reload - Traffic Control Cache Configuration reload check tool # SYNOPSIS -t3c-check-reload [-c paths] [-m mode] [-p packages] +t3c-check-reload [\-\-help] # DESCRIPTION -The t3c-check-reload app takes a comma-delimited list of config file paths -being changed, and a comma-delimited a list of plugin packages being installed, +The t3c-check-reload app takes json input from stdin. +A comma-delimited list of config file paths being changed, +a comma-delimited a list of plugin packages being installed, and returns whether a reload or restart of the caching proxy service is necessary. @@ -58,25 +59,14 @@ Possible return values are: '' - no reload or restart is necessary. -# OPTIONS - --c, --changed-config-paths=value +# JSON Format - comma-delimited list of the full paths of all files changed - by t3c + {"changed_files":"","installed_plugins":""} +# OPTIONS -h, --help Print usage information and exit --m, --run-mode=value - - [badass | report | revalidate | syncds] run mode, default is - 'report' [report] - --p, --plugin-packages-installed=value - - comma-delimited list of ATS plugin packages which were - installed by t3c # AUTHORS From d7ed83811c9bda21510bc66a43150808025e361f Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Tue, 28 Sep 2021 14:48:01 -0400 Subject: [PATCH 36/40] Added changelog entry. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cdeb0ccbd..cc78d1446d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Added - [#5674](https://github.com/apache/trafficcontrol/issues/5674) Added new query parameters `cdn` and `maxRevalDurationDays` to the `GET /api/x/jobs` Traffic Ops API to filter by CDN name and within the start_time window defined by the `maxRevalDurationDays` GLOBAL profile parameter, respectively. - [#6034](https://github.com/apache/trafficcontrol/issues/6034) Added new query parameter `cdn` to the `GET /api/x/deliveryserviceserver` Traffic Ops API to filter by CDN name +- [#6032](https://github.com/apache/trafficcontrol/issues/6032) Add t3c setting mode 0600 for secure files ### Fixed - Fixed Traffic Router crs/stats to prevent overflow and to correctly record the time used in averages. From 31f1923076dc51874a012d9228c8b57101c16673 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Tue, 28 Sep 2021 15:11:05 -0400 Subject: [PATCH 37/40] Changed from fmt.Println() to log.Infoln() --- cache-config/t3c-diff/t3c-diff.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cache-config/t3c-diff/t3c-diff.go b/cache-config/t3c-diff/t3c-diff.go index 08f416cb53..43713c07e2 100644 --- a/cache-config/t3c-diff/t3c-diff.go +++ b/cache-config/t3c-diff/t3c-diff.go @@ -21,6 +21,7 @@ package main import ( "errors" + "fmt" "github.com/apache/trafficcontrol/lib/go-log" "io/ioutil" "os" @@ -39,9 +40,9 @@ func main() { fa := getopt.StringLong("file-a", 'a', "", "first diff file") fb := getopt.StringLong("file-b", 'b', "", "second diff file") getopt.ParseV2() - + log.Init(os.Stderr, os.Stderr, os.Stderr, os.Stderr, os.Stderr) - + if *help { log.Errorln(usageStr) os.Exit(0) @@ -97,12 +98,12 @@ func main() { switch { case fileNameA != "stdin": if t3cutil.PermCk(fileNameA, *mode) { - fmt.Println("File permissions are incorrect, should be ", fmt.Sprintf("%#o", *mode)) + log.Infoln("File permissions are incorrect, should be ", fmt.Sprintf("%#o", *mode)) os.Exit(1) } case fileNameB != "stdin": if t3cutil.PermCk(fileNameB, *mode) { - fmt.Println("File permissions are incorrect, should be ", fmt.Sprintf("%#o", *mode)) + log.Infoln("File permissions are incorrect, should be ", fmt.Sprintf("%#o", *mode)) os.Exit(1) } } From e1022b035cda1fa53e0cf89ea9802d2ae7c9955b Mon Sep 17 00:00:00 2001 From: Joe Pappano Date: Mon, 4 Oct 2021 11:58:29 -0400 Subject: [PATCH 38/40] Fixed formatting error. --- cache-config/t3c-apply/torequest/cmd.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache-config/t3c-apply/torequest/cmd.go b/cache-config/t3c-apply/torequest/cmd.go index 82914321bb..112becf020 100644 --- a/cache-config/t3c-apply/torequest/cmd.go +++ b/cache-config/t3c-apply/torequest/cmd.go @@ -263,8 +263,8 @@ func diff(cfg config.Cfg, newFile []byte, fileLocation string, reportOnly bool, "--file-b=" + fileLocation, "--file-mode=" + fmt.Sprintf("%#o", perm), } - diffMsg := "" - + + diffMsg := "" stdOut, stdErr, code := t3cutil.DoInput(newFile, `t3c-diff`, args...) if code > 1 { From e858dd302661e6b472f9be7c0e97813b0f48230d Mon Sep 17 00:00:00 2001 From: Joe Pappano Date: Mon, 4 Oct 2021 12:28:16 -0400 Subject: [PATCH 39/40] Removed extra spacing. --- cache-config/t3c-apply/torequest/cmd.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cache-config/t3c-apply/torequest/cmd.go b/cache-config/t3c-apply/torequest/cmd.go index 112becf020..834297e5c7 100644 --- a/cache-config/t3c-apply/torequest/cmd.go +++ b/cache-config/t3c-apply/torequest/cmd.go @@ -263,10 +263,9 @@ func diff(cfg config.Cfg, newFile []byte, fileLocation string, reportOnly bool, "--file-b=" + fileLocation, "--file-mode=" + fmt.Sprintf("%#o", perm), } - diffMsg := "" + stdOut, stdErr, code := t3cutil.DoInput(newFile, `t3c-diff`, args...) - if code > 1 { return false, fmt.Errorf("t3c-diff returned error code %v stdout '%v' stderr '%v'", code, string(stdOut), string(stdErr)) } From a6febc0dd9b33bf7fd400a252e8e0e66f9822e82 Mon Sep 17 00:00:00 2001 From: jpappa200 Date: Mon, 4 Oct 2021 12:48:31 -0400 Subject: [PATCH 40/40] Moved diffMsg variable. --- cache-config/t3c-apply/torequest/cmd.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cache-config/t3c-apply/torequest/cmd.go b/cache-config/t3c-apply/torequest/cmd.go index 834297e5c7..c9e48046e2 100644 --- a/cache-config/t3c-apply/torequest/cmd.go +++ b/cache-config/t3c-apply/torequest/cmd.go @@ -258,13 +258,13 @@ func sendUpdate(cfg config.Cfg, updateStatus bool, revalStatus bool) error { // Logs the difference. // If the file on disk doesn't exist, returns true and logs the entire file as a diff. func diff(cfg config.Cfg, newFile []byte, fileLocation string, reportOnly bool, perm os.FileMode) (bool, error) { + diffMsg := "" args := []string{ "--file-a=stdin", "--file-b=" + fileLocation, "--file-mode=" + fmt.Sprintf("%#o", perm), } - diffMsg := "" - + stdOut, stdErr, code := t3cutil.DoInput(newFile, `t3c-diff`, args...) if code > 1 { return false, fmt.Errorf("t3c-diff returned error code %v stdout '%v' stderr '%v'", code, string(stdOut), string(stdErr))