Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

egctl create httpproxy cmd support update or create autocertmanager #1188

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update doc
  • Loading branch information
suchen-sci committed Jan 5, 2024
commit 8c5fdaf0f67236f6b5d720073cc14335b4f09070
32 changes: 29 additions & 3 deletions cmd/client/commandv2/create/createhttpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ egctl create httpproxy NAME --port PORT \
[--auto-cert] \
[--ca-cert-file CA_CERT_FILE] \
[--cert-file CERT_FILE] \
[--key-file KEY_FILE]
[--key-file KEY_FILE] \
[--auto-cert-email EMAIL] \
[--auto-cert-domain-name DOMAIN_NAME] \
[--dns-provider KEY=VALUE] \
[--dns-provider KEY2=VALUE2]

# Create a HTTPServer (with port 10080) and corresponding Pipelines to direct
# request with path "/bar" to "https://127.0.0.1:8080" and "https://127.0.0.1:8081" and
Expand All @@ -83,6 +87,27 @@ egctl create httpproxy demo --port 10080 \
# with path prefix "foo.com/prefix" to "https://127.0.0.1:8083".
egctl create httpproxy demo2 --port 10081 \
--rule="foo.com/prefix*=https://127.0.0.1:8083"

# Create HTTPServer, Pipelines with a new AutoCertManager.
# auto-cert-email is required for creating a new AutoCertManager.
# If an AutoCertManager exists, this updates its email field.
egctl create httpproxy demo2 --port 10081 \
--rule="/bar=https://127.0.0.1:8083" \
--auto-cert \
--auto-cert-email [email protected] \
--auto-cert-domain-name="*.foo.com" \
--dns-provider name=dnspod \
--dns-provider zone=megaease.com \
--dns-provider="apiToken=<tokenvalue>"

# Create HTTPServer, Pipelines with an existing AutoCertManager and update it.
egctl create httpproxy demo2 --port 10081 \
--rule="/bar=https://127.0.0.1:8083" \
--auto-cert \
--auto-cert-domain-name="*.foo.com" \
--dns-provider name=dnspod \
--dns-provider zone=megaease.com \
--dns-provider="apiToken=<tokenvalue>"
`

// HTTPProxyCmd returns create command of HTTPProxy.
Expand Down Expand Up @@ -225,10 +250,10 @@ func (o *HTTPProxyOptions) Parse() error {
return fmt.Errorf("auto cert domain name or dns provider is set, but auto cert is not enabled")
}
if o.AutoCertDomainName == "" {
return fmt.Errorf("auto cert domain name is required")
return fmt.Errorf("auto cert domain name is required when provide dns provider")
}
if len(o.AutoCertDNSProvider) == 0 {
return fmt.Errorf("auto cert dns provider is required")
return fmt.Errorf("auto cert dns provider is required when provide auto cert domain name")
}
}
o.dnsProvider = map[string]string{}
Expand Down Expand Up @@ -303,6 +328,7 @@ func (o *HTTPProxyOptions) translateRules() (routers.Rules, []*specs.PipelineSpe
return rules, pipelines
}

// TranslateAutoCertManager translates AutoCertManagerSpec.
func (o *HTTPProxyOptions) TranslateAutoCertManager() (*specs.AutoCertManagerSpec, error) {
url := general.MakePath(general.ObjectsURL)
body, err := general.HandleRequest(http.MethodGet, url, nil)
Expand Down
3 changes: 2 additions & 1 deletion cmd/client/commandv2/specs/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ type AutoCertManagerSpec struct {
autocertmanager.Spec `json:",inline"`
}

// NewAutoCertManagerSpec returns a new AutoCertManagerSpec.
func NewAutoCertManagerSpec() *AutoCertManagerSpec {
return &AutoCertManagerSpec{
Name: "default",
Name: "autocertmanager",
Kind: autocertmanager.Kind,
Spec: *getDefaultAutoCertManagerSpec(),
}
Expand Down
39 changes: 38 additions & 1 deletion docs/02.Tutorials/2.1.egctl-Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ egctl create httpproxy NAME --port PORT \
[--auto-cert] \
[--ca-cert-file CA_CERT_FILE] \
[--cert-file CERT_FILE] \
[--key-file KEY_FILE]
[--key-file KEY_FILE] \
[--auto-cert-email EMAIL] \
[--auto-cert-domain-name DOMAIN_NAME] \
[--dns-provider KEY=VALUE] \
[--dns-provider KEY2=VALUE2]
```

For example:
Expand Down Expand Up @@ -91,6 +95,39 @@ filters:
policy: roundRobin
```

You can use the `egctl create httpproxy` command to create or update an `AutoCertManager`. Below is an example command and its equivalent YAML configuration.

For example:

```bash
egctl create httpproxy demo2 --port 10081 \
--rule="/bar=https://127.0.0.1:8083" \
--auto-cert \
--auto-cert-email [email protected] \
--auto-cert-domain-name="*.foo.com" \
--dns-provider name=dnspod \
--dns-provider zone=megaease.com \
--dns-provider="apiToken=<tokenvalue>"
```
Parameters:

- `auto-cert-email`: Required for creating a new `AutoCertManager`. If an `AutoCertManager` exists, this updates its email field.
- `auto-cert-domain-name` and `dns-provider`: Specify the domain in the `AutoCertManager` config. This either appends to or updates the domains field of `AutoCertManager`.

Equivalent YAML Configuration

```yaml
kind: AutoCertManager
name: AutoCertManager
email: [email protected]
domains:
- name: "*.megaease.com"
dnsProvider:
name: dnspod
zone: megaease.com
apiToken: <token value>
```

## Viewing and finding resources

```bash
Expand Down
Loading