-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
247 additions
and
221 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cossim/coss-cli/pkg/apisix" | ||
"github.com/urfave/cli/v2" | ||
"io/ioutil" | ||
) | ||
|
||
func initRoute(context *cli.Context) error { | ||
apiKey := context.String("key") | ||
host := context.String("host") | ||
direct := context.Bool("direct") | ||
domain := context.String("domain") | ||
livekitDomain := context.String("livekit") | ||
routeHost := context.String("route-host") | ||
|
||
baseURL := host + "/apisix/admin/routes/" | ||
|
||
client := apisix.NewApiClient(apiKey, baseURL) | ||
|
||
route := client.GetRoutes(domain, routeHost, livekitDomain, direct) | ||
|
||
for i, route := range route { | ||
resp, err := client.SendRequest("PUT", fmt.Sprintf("%d", i+1), route) | ||
if err != nil { | ||
fmt.Printf("Error sending request for route %d: %v\n", i+1, err) | ||
continue | ||
} | ||
fmt.Printf("Route %d created successfully: %s\n", i+1, resp) | ||
} | ||
return nil | ||
} | ||
|
||
func uploadSSL(context *cli.Context) error { | ||
certPath := context.String("cert") | ||
keyPath := context.String("private_key") | ||
domain := context.String("domain") | ||
apiKey := context.String("key") | ||
host := context.String("host") | ||
num := context.Int("num") | ||
|
||
cert, err := ioutil.ReadFile(certPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to read certificate file: %v", err) | ||
} | ||
|
||
key, err := ioutil.ReadFile(keyPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to read key file: %v", err) | ||
} | ||
|
||
if domain == "" { | ||
return fmt.Errorf("domain name is required") | ||
} | ||
client := apisix.NewApiClient(apiKey, host) | ||
if err := client.UpdateSSL(cert, key, []string{domain}, num); err != nil { | ||
fmt.Printf("Error updating SSL: %v\n", err) | ||
} else { | ||
fmt.Printf("SSL updated successfully\n") | ||
} | ||
return nil | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/cossim/coss-cli/pkg/consul" | ||
"github.com/urfave/cli/v2" | ||
"strings" | ||
) | ||
|
||
func initConfig(cCtx *cli.Context) error { | ||
if cCtx.String("path") == "" { | ||
return fmt.Errorf("path is empty") | ||
} | ||
paths := strings.Split(cCtx.String("path"), ",") | ||
if len(paths) == 0 { | ||
return fmt.Errorf("no paths provided") | ||
} | ||
nameSpace := cCtx.String("namespace") | ||
host := cCtx.String("host") | ||
token := cCtx.String("token") | ||
token = token + "/" | ||
client := consul.NewConsulClient(host, nameSpace, "", token) | ||
|
||
for _, path := range paths { | ||
client.SetPath(path) | ||
err := client.PutConfig() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.