Skip to content

Commit

Permalink
Basic Setup For Firebase Shell Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
MukeshKumarBagaria committed Jun 29, 2023
1 parent a39d64a commit 4510f47
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
70 changes: 70 additions & 0 deletions plugins/firebase/access_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package firebase

import (
"context"

"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/importer"
"github.com/1Password/shell-plugins/sdk/provision"
"github.com/1Password/shell-plugins/sdk/schema"
"github.com/1Password/shell-plugins/sdk/schema/credname"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
)

func AccessToken() schema.CredentialType {
return schema.CredentialType{
Name: credname.AccessToken,
DocsURL: sdk.URL("https://firebase.google.com/docs/cli#cli-ci-systems"),
ManagementURL: sdk.URL("https://firebase.google.com/docs/cli#cli-ci-systems"),
Fields: []schema.CredentialField{
{
Name: fieldname.Token,
MarkdownDescription: "Token used to authenticate to firebase.",
Secret: true,
Composition: &schema.ValueComposition{
Length: 53,
Prefix: "dummy_firebase_", // TODO: Check if this is correct
Charset: schema.Charset{
Lowercase: true,
Digits: true,
},
},
},
},
DefaultProvisioner: provision.EnvVars(defaultEnvVarMapping),
Importer: importer.TryAll(
importer.TryEnvVarPair(defaultEnvVarMapping),
TryfirebaseConfigFile(),
)}
}

var defaultEnvVarMapping = map[string]sdk.FieldName{
"FIREBASE_TOKEN": fieldname.Token, // TODO: Check if this is correct
}

// TODO: Check if the platform stores the Access Token in a local config file, and if so,
// implement the function below to add support for importing it.
func TryfirebaseConfigFile() sdk.Importer {
return importer.TryFile("~/path/to/config/file.yml", func(ctx context.Context, contents importer.FileContents, in sdk.ImportInput, out *sdk.ImportAttempt) {
// var config Config
// if err := contents.ToYAML(&config); err != nil {
// out.AddError(err)
// return
// }

// if config.Token == "" {
// return
// }

// out.AddCandidate(sdk.ImportCandidate{
// Fields: map[sdk.FieldName]string{
// fieldname.Token: config.Token,
// },
// })
})
}

// TODO: Implement the config file schema
// type Config struct {
// Token string
// }
55 changes: 55 additions & 0 deletions plugins/firebase/access_token_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package firebase

import (
"testing"

"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/plugintest"
"github.com/1Password/shell-plugins/sdk/schema/fieldname"
)

func TestAccessTokenProvisioner(t *testing.T) {
plugintest.TestProvisioner(t, AccessToken().DefaultProvisioner, map[string]plugintest.ProvisionCase{
"default": {
ItemFields: map[sdk.FieldName]string{ // TODO: Check if this is correct
fieldname.Token: "dummy_firebase_3bhfuelt31a99503j251bua8rov58m2example",
},
ExpectedOutput: sdk.ProvisionOutput{
Environment: map[string]string{
"FIREBASE_TOKEN": "dummy_firebase_3bhfuelt31a99503j251bua8rov58m2example",
},
},
},
})
}

func TestAccessTokenImporter(t *testing.T) {
plugintest.TestImporter(t, AccessToken().Importer, map[string]plugintest.ImportCase{
"environment": {
Environment: map[string]string{ // TODO: Check if this is correct
"FIREBASE_TOKEN": "dummy_firebase_3bhfuelt31a99503j251bua8rov58m2example",
},
ExpectedCandidates: []sdk.ImportCandidate{
{
Fields: map[sdk.FieldName]string{
fieldname.Token: "dummy_firebase_3bhfuelt31a99503j251bua8rov58m2example",
},
},
},
},
// TODO: If you implemented a config file importer, add a test file example in firebase/test-fixtures
// and fill the necessary details in the test template below.
"config file": {
Files: map[string]string{
// "~/path/to/config.yml": plugintest.LoadFixture(t, "config.yml"),
},
ExpectedCandidates: []sdk.ImportCandidate{
// {
// Fields: map[sdk.FieldName]string{
// fieldname.Token: "dummy_firebase_3bhfuelt31a99503j251bua8rov58m2example",
// },
// },
},
},
})
}
25 changes: 25 additions & 0 deletions plugins/firebase/firebase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package firebase

import (
"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/needsauth"
"github.com/1Password/shell-plugins/sdk/schema"
"github.com/1Password/shell-plugins/sdk/schema/credname"
)

func firebaseCLI() schema.Executable {
return schema.Executable{
Name: "Firebase CLI",
Runs: []string{"firebase"},
DocsURL: sdk.URL("https://firebase.google.com/docs/cli"),
NeedsAuth: needsauth.IfAll(
needsauth.NotForHelpOrVersion(),
needsauth.NotWithoutArgs(),
),
Uses: []schema.CredentialUsage{
{
Name: credname.AccessToken,
},
},
}
}
22 changes: 22 additions & 0 deletions plugins/firebase/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package firebase

import (
"github.com/1Password/shell-plugins/sdk"
"github.com/1Password/shell-plugins/sdk/schema"
)

func New() schema.Plugin {
return schema.Plugin{
Name: "firebase",
Platform: schema.PlatformInfo{
Name: "firebase",
Homepage: sdk.URL("https://firebase.google.com/"),
},
Credentials: []schema.CredentialType{
AccessToken(),
},
Executables: []schema.Executable{
firebaseCLI(),
},
}
}

0 comments on commit 4510f47

Please sign in to comment.