|
7 | 7 | "errors" |
8 | 8 | "fmt" |
9 | 9 | "io" |
| 10 | + "net/url" |
10 | 11 | "os" |
11 | 12 | "path" |
12 | 13 | "path/filepath" |
@@ -133,45 +134,71 @@ func readProxyOptions(optionsFilePath string, options *tygerproxy.ProxyOptions) |
133 | 134 | return errors.New("serverUrl must be specified") |
134 | 135 | } |
135 | 136 |
|
136 | | - if options.ManagedIdentity { |
137 | | - if options.ServicePrincipal != "" { |
138 | | - return errors.New("servicePrincipal cannot be specified when using managed identity") |
| 137 | + parsedUrl, err := url.Parse(options.ServerUrl) |
| 138 | + if err != nil { |
| 139 | + return fmt.Errorf("invalid serverUrl: %v", err) |
| 140 | + } |
| 141 | + |
| 142 | + if parsedUrl.Scheme == "ssh" || parsedUrl.Scheme == "http+unix" { |
| 143 | + if options.ManagedIdentity { |
| 144 | + return errors.New("managedIdentity cannot be specified when using SSH or Unix socket connection") |
139 | 145 | } |
140 | | - if options.CertificatePath != "" { |
141 | | - return errors.New("certificatePath cannot be specified when using managed identity") |
| 146 | + if options.GitHub { |
| 147 | + return errors.New("github cannot be specified when using SSH or Unix socket connection") |
142 | 148 | } |
143 | | - if options.CertificateThumbprint != "" { |
144 | | - return errors.New("certificateThumbprint cannot be specified when using managed identity") |
145 | | - } |
146 | | - } else if options.GitHub { |
147 | 149 | if options.ServicePrincipal != "" { |
148 | | - return errors.New("servicePrincipal cannot be specified when using GitHub authentication") |
| 150 | + return errors.New("servicePrincipal cannot be specified when using SSH or Unix socket connection") |
149 | 151 | } |
150 | 152 | if options.CertificatePath != "" { |
151 | | - return errors.New("certificatePath cannot be specified when using GitHub authentication") |
| 153 | + return errors.New("certificatePath cannot be specified when using SSH or Unix socket connection") |
152 | 154 | } |
153 | 155 | if options.CertificateThumbprint != "" { |
154 | | - return errors.New("certificateThumbprint cannot be specified when using GitHub authentication") |
| 156 | + return errors.New("certificateThumbprint cannot be specified when using SSH or Unix socket connection") |
155 | 157 | } |
156 | | - } else { |
157 | | - if options.ServicePrincipal == "" { |
158 | | - return errors.New("if both managedIdentity and github are both not true, servicePrincipal must be specified in the options file") |
| 158 | + if options.TargetFederatedIdentity != "" { |
| 159 | + return errors.New("targetFederatedIdentity cannot be specified when using SSH or Unix socket connection") |
159 | 160 | } |
160 | | - |
161 | | - if runtime.GOOS == "windows" { |
162 | | - if options.CertificatePath == "" && options.CertificateThumbprint == "" { |
163 | | - return errors.New("either certificatePath or certificateThumbprint must be specified in the options file") |
| 161 | + } else { |
| 162 | + if options.ManagedIdentity { |
| 163 | + if options.ServicePrincipal != "" { |
| 164 | + return errors.New("servicePrincipal cannot be specified when using managed identity") |
164 | 165 | } |
| 166 | + if options.CertificatePath != "" { |
| 167 | + return errors.New("certificatePath cannot be specified when using managed identity") |
| 168 | + } |
| 169 | + if options.CertificateThumbprint != "" { |
| 170 | + return errors.New("certificateThumbprint cannot be specified when using managed identity") |
| 171 | + } |
| 172 | + } else if options.GitHub { |
| 173 | + if options.ServicePrincipal != "" { |
| 174 | + return errors.New("servicePrincipal cannot be specified when using GitHub authentication") |
| 175 | + } |
| 176 | + if options.CertificatePath != "" { |
| 177 | + return errors.New("certificatePath cannot be specified when using GitHub authentication") |
| 178 | + } |
| 179 | + if options.CertificateThumbprint != "" { |
| 180 | + return errors.New("certificateThumbprint cannot be specified when using GitHub authentication") |
| 181 | + } |
| 182 | + } else { |
| 183 | + if options.ServicePrincipal == "" { |
| 184 | + return errors.New("if both managedIdentity and github are both not true, servicePrincipal must be specified in the options file") |
| 185 | + } |
| 186 | + |
| 187 | + if runtime.GOOS == "windows" { |
| 188 | + if options.CertificatePath == "" && options.CertificateThumbprint == "" { |
| 189 | + return errors.New("either certificatePath or certificateThumbprint must be specified in the options file") |
| 190 | + } |
165 | 191 |
|
166 | | - if options.CertificatePath != "" && options.CertificateThumbprint != "" { |
167 | | - return errors.New("certificatePath and certificateThumbprint cannot both be specified") |
| 192 | + if options.CertificatePath != "" && options.CertificateThumbprint != "" { |
| 193 | + return errors.New("certificatePath and certificateThumbprint cannot both be specified") |
| 194 | + } |
| 195 | + } else if options.CertificatePath == "" { |
| 196 | + return errors.New("certificatePath must be specified in the options file") |
168 | 197 | } |
169 | | - } else if options.CertificatePath == "" { |
170 | | - return errors.New("certificatePath must be specified in the options file") |
171 | | - } |
172 | 198 |
|
173 | | - if options.TargetFederatedIdentity != "" { |
174 | | - return errors.New("targetFederatedIdentity cannot be specified when using service principal authentication") |
| 199 | + if options.TargetFederatedIdentity != "" { |
| 200 | + return errors.New("targetFederatedIdentity cannot be specified when using service principal authentication") |
| 201 | + } |
175 | 202 | } |
176 | 203 | } |
177 | 204 |
|
|
0 commit comments