github.com/drycc/workflow-cli@v1.5.3-0.20240322092846-d4ee25983af9/cmd/tls.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 6 "github.com/drycc/controller-sdk-go/tls" 7 ) 8 9 // TLSInfo prints info about the TLS settings for the given app. 10 func (d *DryccCmd) TLSInfo(appID string) error { 11 s, appID, err := load(d.ConfigFile, appID) 12 13 if err != nil { 14 return err 15 } 16 17 tls, err := tls.Info(s.Client, appID) 18 if d.checkAPICompatibility(s.Client, err) != nil { 19 return err 20 } 21 table := d.getDefaultFormatTable( 22 []string{"UUID", "OWNER", "CERTS-AUTO", "HTTPS-ENFORCED", "EMAIL", "SERVER"}, 23 ) 24 data := []string{ 25 tls.UUID, 26 tls.Owner, 27 fmt.Sprintf("%v", tls.CertsAutoEnabled != nil && *(tls.CertsAutoEnabled)), 28 fmt.Sprintf("%v", tls.HTTPSEnforced != nil && *(tls.HTTPSEnforced)), 29 safeGetString(""), 30 safeGetString(""), 31 } 32 if tls.Issuer != nil { 33 data[4] = safeGetString(tls.Issuer.Email) 34 data[5] = safeGetString(tls.Issuer.Server) 35 } 36 table.Append(data) 37 table.Render() 38 return nil 39 } 40 41 // TLSForceEnable enables the router to enforce https-only requests to the application. 42 func (d *DryccCmd) TLSForceEnable(appID string) error { 43 s, appID, err := load(d.ConfigFile, appID) 44 45 if err != nil { 46 return err 47 } 48 49 d.Printf("Enabling https-only requests for %s... ", appID) 50 51 quit := progress(d.WOut) 52 _, err = tls.EnableHTTPSEnforced(s.Client, appID) 53 quit <- true 54 <-quit 55 if d.checkAPICompatibility(s.Client, err) != nil { 56 return err 57 } 58 59 d.Println("done") 60 return nil 61 } 62 63 // TLSForceDisable disables the router to enforce https-only requests to the application. 64 func (d *DryccCmd) TLSForceDisable(appID string) error { 65 s, appID, err := load(d.ConfigFile, appID) 66 67 if err != nil { 68 return err 69 } 70 71 d.Printf("Disabling https-only requests for %s... ", appID) 72 73 quit := progress(d.WOut) 74 _, err = tls.DisableHTTPSEnforced(s.Client, appID) 75 quit <- true 76 <-quit 77 if d.checkAPICompatibility(s.Client, err) != nil { 78 return err 79 } 80 81 d.Println("done") 82 return nil 83 } 84 85 // TLSAutoEnable enables certs-auto requests to the application. 86 func (d *DryccCmd) TLSAutoEnable(appID string) error { 87 s, appID, err := load(d.ConfigFile, appID) 88 89 if err != nil { 90 return err 91 } 92 93 d.Printf("Enabling certs-auto requests for %s... ", appID) 94 95 quit := progress(d.WOut) 96 _, err = tls.EnableCertsAutoEnabled(s.Client, appID) 97 quit <- true 98 <-quit 99 if d.checkAPICompatibility(s.Client, err) != nil { 100 return err 101 } 102 103 d.Println("done") 104 return nil 105 } 106 107 // TLSAutoDisable disables certs-auto requests to the application. 108 func (d *DryccCmd) TLSAutoDisable(appID string) error { 109 s, appID, err := load(d.ConfigFile, appID) 110 111 if err != nil { 112 return err 113 } 114 115 d.Printf("Disabling certs-auto requests for %s... ", appID) 116 117 quit := progress(d.WOut) 118 _, err = tls.DisableCertsAutoEnabled(s.Client, appID) 119 quit <- true 120 <-quit 121 if d.checkAPICompatibility(s.Client, err) != nil { 122 return err 123 } 124 125 d.Println("done") 126 return nil 127 } 128 129 // TLSAutoIssuer add issuer requests to the application. 130 func (d *DryccCmd) TLSAutoIssuer(appID string, email string, server string, keyID string, keySecret string) error { 131 s, appID, err := load(d.ConfigFile, appID) 132 133 if err != nil { 134 return err 135 } 136 137 d.Printf("Adding issuer requests for %s... ", appID) 138 139 quit := progress(d.WOut) 140 _, err = tls.AddCertsIssuer(s.Client, appID, email, server, keyID, keySecret) 141 quit <- true 142 <-quit 143 if d.checkAPICompatibility(s.Client, err) != nil { 144 return err 145 } 146 147 d.Println("done") 148 return nil 149 }