Skip to content

Commit

Permalink
Serverless Functions (#58)
Browse files Browse the repository at this point in the history
* Add function management

Enables operator to create/update/delete functions via pusher api.

* Fix linter feedback

* Bump golang.org/x/text from 0.3.7 to 0.3.8

Bumps [golang.org/x/text](https://github.com/golang/text) from 0.3.7 to 0.3.8.
- [Release notes](https://github.com/golang/text/releases)
- [Commits](golang/text@v0.3.7...v0.3.8)

* Fix staging

Enhance config options to allow use in staging clusters

* Update status in README from alpha to beta

Co-authored-by: Robert Oles <[email protected]>
Co-authored-by: robertoles <[email protected]>
Co-authored-by: Ahmad Samiei <[email protected]>
Co-authored-by: Ahmad Samiei <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Agata Walukiewicz <[email protected]>
Co-authored-by: Vitaliy Kalachikhin <[email protected]>
Co-authored-by: Felipe Benevides <[email protected]>
  • Loading branch information
9 people authored May 3, 2023
1 parent e79ae93 commit 3e9a087
Show file tree
Hide file tree
Showing 25 changed files with 1,163 additions and 62 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.PHONY: build-mockgen
build-mockgen:
docker build -f mockgen.Dockerfile --tag pusher_cli_mockgen .

.PHONY: mocks
mocks: build-mockgen
docker run --rm --volume "$$(pwd):/src" pusher_cli_mockgen
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is a tool that allows developers access to their Pusher accounts via a command line interface.

This is an alpha release. We recommend using it for non-production apps. It may eat your laundry! We'd appreciate your feedback.
This is a beta release. We recommend using it for non-production apps unless otherwise advised. We'd appreciate your feedback.

## Usage

Expand Down Expand Up @@ -41,3 +41,17 @@ We [publish binaries on GitHub](https://github.com/pusher/cli/releases) and we u

1. `git tag -a v0.14 -m "v0.14"`
1. `git push origin v0.14`

### Configuration

`pusher login` creates a file `~/.config/pusher.json` (or updates it if it already exists).
If you need to point the Pusher CLI to different servers (e.g. when testing), you can change the `endpoint` value and add new name/value pairs as necessary:
```JSON
{
"endpoint": "https://cli.another.domain.com",
"token": "my-secret-api-key",
"apihost": "api-mycluster.another.domain.com",
"httphost": "sockjs-mycluster.another.domain.com",
"wshost": "ws-mycluster.another.domain.com"
}
```
8 changes: 4 additions & 4 deletions api/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (
)

//isAPIKeyValid returns true if the stored API key is valid.
func isAPIKeyValid() bool {
func (p *PusherApi) isAPIKeyValid() bool {
if viper.GetString("token") != "" {
_, err := GetAllApps()
_, err := p.GetAllApps()
if err == nil {
return true
}
}
return false
}

func validateKeyOrDie() {
if !isAPIKeyValid() {
func (p *PusherApi) validateKeyOrDie() {
if !p.isAPIKeyValid() {
fmt.Println("Your API key isn't valid. Add one with the `login` command.")
os.Exit(1)
}
Expand Down
10 changes: 5 additions & 5 deletions api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ type App struct {
Cluster string `json:"cluster"`
}

const getAppsAPIEndpoint = "/apps.json"
const GetAppsAPIEndpoint = "/apps.json"

func GetAllApps() ([]App, error) {
response, err := makeRequest("GET", getAppsAPIEndpoint, nil)
func (p *PusherApi) GetAllApps() ([]App, error) {
response, err := p.makeRequest("GET", GetAppsAPIEndpoint, nil)
if err != nil {
return nil, err
}
Expand All @@ -29,8 +29,8 @@ func GetAllApps() ([]App, error) {
return apps, nil
}

func GetApp(appID string) (*App, error) {
apps, err := GetAllApps()
func (p *PusherApi) GetApp(appID string) (*App, error) {
apps, err := p.GetAllApps()
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 3e9a087

Please sign in to comment.