Last active
May 15, 2023 15:57
-
-
Save feniljain/3f3d7c64ab34e20b0a459d991bcd7db1 to your computer and use it in GitHub Desktop.
Fix `view_type` key in preset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "net/url" | |
| "os" | |
| "os/exec" | |
| "path" | |
| ) | |
| func main() { | |
| fmt.Println("starting the script") | |
| urls := []string{ | |
| } | |
| for _, urlStr := range urls { | |
| parsedUrl, err := url.Parse(urlStr) | |
| if err != nil { | |
| panic(err) | |
| } | |
| fmt.Println("completed parsing the url") | |
| presetFileName := path.Base(parsedUrl.EscapedPath()) | |
| cmd := exec.Command("wget", "-O", presetFileName, urlStr) | |
| _, err = cmd.Output() | |
| if err != nil { | |
| panic(err) | |
| } | |
| fmt.Println("downloaded json file") | |
| changeViewTypKey(presetFileName) | |
| writeToS3(parsedUrl, presetFileName) | |
| // aws s3 cp file.txt s3://mybucket/ --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers full=uri=79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2be | |
| err = os.Remove(presetFileName) | |
| if err != nil { | |
| panic(err) | |
| } | |
| fmt.Println("deleted local json file") | |
| } | |
| } | |
| func changeViewTypKey(fileName string) { | |
| out, err := os.ReadFile(fileName) | |
| if err != nil { | |
| panic(err) | |
| } | |
| var preset map[string]interface{} | |
| err = json.Unmarshal(out, &preset) | |
| if err != nil { | |
| panic(err) | |
| } | |
| config := preset["config"].(map[string]interface{}) | |
| fmt.Println("current value: ", config["view_type"]) | |
| config["view_type"] = interface{}("GROUP_CALL") | |
| fmt.Println("changed value to group call") | |
| bytes, err := json.Marshal(preset) | |
| if err != nil { | |
| panic(err) | |
| } | |
| fmt.Println("marshalled values") | |
| err = os.WriteFile(fileName, bytes, 0666) | |
| if err != nil { | |
| panic(err) | |
| } | |
| fmt.Println("written to file") | |
| } | |
| func writeToS3(parsedUrl *url.URL, fileName string) { | |
| parsedUrl.Scheme = "s3" | |
| parsedUrl.Host = "dyte-configs" | |
| // parsedUrl.Query = url.Values{} | |
| q, err := url.ParseQuery(parsedUrl.RawQuery) | |
| q.Del("dt") | |
| parsedUrl.RawQuery = q.Encode() | |
| fmt.Println("constructed s3 url", parsedUrl.String()) | |
| // readValue(fileName) | |
| awsUploadCmd := exec.Command("aws", "s3", "cp", fileName, parsedUrl.String(), "--grants", "read=uri=http://acs.amazonaws.com/groups/global/AllUsers") | |
| _, err = awsUploadCmd.Output() | |
| if err != nil { | |
| panic(err) | |
| } | |
| fmt.Println("wrote file to aws", parsedUrl.String()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment