Documentation ¶
Index ¶
- Constants
- func ConfigureDotEnv(ctx context.Context, config *config.Config) (map[string]string, error)
- func GetSamples(mode string) (map[string]*SampleData, error)
- func Names(list map[string]*SampleData) []string
- type CreationResult
- type CreationStatus
- type SampleConfig
- type SampleConfigIntegration
- type SampleData
- type SampleList
- type SampleLister
- type SampleManager
- func (s *SampleManager) Cleanup(name string) error
- func (s *SampleManager) Copy(target string) error
- func (sampleManager *SampleManager) Create(ctx context.Context, sampleName string, selectedConfig *SelectedConfig, ...)
- func (s *SampleManager) DeleteCache(sample string) error
- func (s *SampleManager) GetFiles(path string) ([]string, error)
- func (s *SampleManager) GetFolders(path string) ([]string, error)
- func (s *SampleManager) GetSampleConfig(sampleName string, forceRefresh bool) (*SampleConfig, error)
- func (s *SampleManager) Initialize(app string) error
- func (s *SampleManager) MakeFolder(name string) (string, error)
- func (s *SampleManager) PostInstall() string
- func (s *SampleManager) WriteDotEnv(ctx context.Context, sampleLocation string) error
- type SelectedConfig
Constants ¶
const TestPublishableKeyPlaceholder = "pk_test..."
TestPublishableKeyPlaceholder is the placeholder for empty publishable key in the .env file
Variables ¶
This section is empty.
Functions ¶
func ConfigureDotEnv ¶ added in v1.13.7
ConfigureDotEnv returns a map of environment variables to copy into the .env file of the target project, based on the user's stripe-cli profile.
func GetSamples ¶ added in v1.6.0
func GetSamples(mode string) (map[string]*SampleData, error)
GetSamples returns a list that contains a mapping of Stripe Samples that we want to be available in the CLI to some of their metadata. TODO: what do we want to name these for it to be easier for users to select? TODO: should we group them by products for easier exploring?
func Names ¶
func Names(list map[string]*SampleData) []string
Names returns a list of all the sample's names
Types ¶
type CreationResult ¶ added in v1.6.0
type CreationResult struct { State CreationStatus Path string PostInstall string Err error }
CreationResult is the return value sent over a channel
type CreationStatus ¶ added in v1.6.0
type CreationStatus int
CreationStatus is the current step in the sample creation routine
const ( // WillInitialize means this sample will be initialized WillInitialize CreationStatus = iota // DidInitialize means this sample has finished initializing DidInitialize // WillCopy means the downloaded sample will be copied to the target path WillCopy // DidCopy means the downloaded sample has finished being copied to the target path DidCopy // WillConfigure means the .env of the sample will be configured with the user's Stripe account details WillConfigure // DidConfigure means the .env of the sample has finished being configured with the user's Stripe account details DidConfigure // DidConfigureWithoutTestPubKey means the .env of the sample has finished being configured without the publishable key DidConfigureWithoutTestPubKey // Done means sample creation is complete Done )
type SampleConfig ¶ added in v1.6.0
type SampleConfig struct { Name string `json:"name"` ConfigureDotEnv bool `json:"configureDotEnv"` PostInstall map[string]string `json:"postInstall"` Integrations []SampleConfigIntegration `json:"integrations"` }
SampleConfig contains all the configuration options for a sample
func (*SampleConfig) HasIntegrations ¶ added in v1.6.0
func (sc *SampleConfig) HasIntegrations() bool
HasIntegrations returns true if the sample has multiple integrations
func (*SampleConfig) IntegrationNames ¶ added in v1.6.0
func (sc *SampleConfig) IntegrationNames() []string
IntegrationNames returns the names of the available integrations for the sample
type SampleConfigIntegration ¶ added in v1.6.0
type SampleConfigIntegration struct { Name string `json:"name"` // Clients are the frontend clients built for each sample Clients []string `json:"clients"` // Servers are the backend server implementations available for a sample Servers []string `json:"servers"` }
SampleConfigIntegration is a particular integration for a sample
func (*SampleConfigIntegration) HasMultipleClients ¶ added in v1.6.0
func (i *SampleConfigIntegration) HasMultipleClients() bool
HasMultipleClients returns true if this integration has multiple options for the client language
func (*SampleConfigIntegration) HasMultipleServers ¶ added in v1.6.0
func (i *SampleConfigIntegration) HasMultipleServers() bool
HasMultipleServers returns true if this integration has multiple options for the server language
type SampleData ¶
type SampleData struct { Name string `json:"name"` URL string `json:"URL"` Description string `json:"description"` }
SampleData stores the information needed for Stripe Samples to operate in the CLI
func (*SampleData) BoldName ¶
func (sd *SampleData) BoldName() string
BoldName returns an ansi bold string for the name
func (*SampleData) GitRepo ¶
func (sd *SampleData) GitRepo() string
GitRepo returns a string of the repo with the .git prefix
type SampleList ¶ added in v1.3.9
type SampleList struct {
Samples []SampleData `json:"samples"`
}
SampleList is used to unmarshal the samples array from the JSON response
type SampleLister ¶ added in v1.13.7
type SampleLister interface {
ListSamples(mode string) (map[string]*SampleData, error)
}
SampleLister gets the list of valid stripe samples. It is used both in `stripe samples list` to show the users what they can do, and in `stripe samples create <name>` in order to look up the repo url corresponding to <name>
type SampleManager ¶ added in v1.13.7
type SampleManager struct { // Holds functionality for getting the list of stripe sample repositories. SampleLister SampleLister // Function to populating the .env file in a created sample // (using information from the user's stripe-cli config) ConfigureDotEnv func(ctx context.Context, config *config.Config) (map[string]string, error) // Filesystem operations Fs afero.Fs // Git operations. Git g.Interface Config *config.Config // Information (defined by the sample) about what integrations it supports // and how it ought to be set up by the CLI. SampleConfig SampleConfig // Represents the user selection about which part of the sample to copy over during // setup. SelectedConfig SelectedConfig // contains filtered or unexported fields }
SampleManager supports operations related to listing, cloning, and setup of Stripe samples. It contains configurable dependencies like `SampleLister` and `Fs` so that the behavior can be customized in tests or plugins, and it contains stateful properties like `repoPath`, `selectedConfig` that keep track of the operation as it goes along.
func NewSampleManager ¶ added in v1.13.7
func NewSampleManager(config *config.Config) (*SampleManager, error)
NewSampleManager creates a SampleManager with default behavior. I.e. it uses go-git for git operations, it uses the standard filesystem implementation, it lists samples by fetching samples.json from the standard samples-list repository, and it copies .env files in the standard way
func (*SampleManager) Cleanup ¶ added in v1.13.7
func (s *SampleManager) Cleanup(name string) error
Cleanup performs cleanup for the recently created sample
func (*SampleManager) Copy ¶ added in v1.13.7
func (s *SampleManager) Copy(target string) error
Copy will copy all of the files from the selected configuration above oves. This has a few different behaviors, depending on the configuration. Ultimately, we want the user to do as minimal of folder traversing as possible. What we want to end up with is:
|- example-sample/ +-- client/ +-- server/ +-- readme.md +-- ... `-- .env.example
The behavior here is:
- If there are no integrations available, copy the top-level files, the client folder, and the selected language inside of the server folder to the server top-level (example above)
- If the user selects an integration, mirror the structure above for the selected integration (example above)
func (*SampleManager) Create ¶ added in v1.13.7
func (sampleManager *SampleManager) Create( ctx context.Context, sampleName string, selectedConfig *SelectedConfig, destination string, forceRefresh bool, resultChan chan<- CreationResult, )
Create creates a sample at a destination with the selected integration, client language, and server language
func (*SampleManager) DeleteCache ¶ added in v1.13.7
func (s *SampleManager) DeleteCache(sample string) error
DeleteCache forces the local sample cache to refresh in case something goes awry during the initial clone or to clean out stale samples
func (*SampleManager) GetFiles ¶ added in v1.13.7
func (s *SampleManager) GetFiles(path string) ([]string, error)
GetFiles returns a list of files for a given path
func (*SampleManager) GetFolders ¶ added in v1.13.7
func (s *SampleManager) GetFolders(path string) ([]string, error)
GetFolders returns a list of all folders for a given path
func (*SampleManager) GetSampleConfig ¶ added in v1.13.7
func (s *SampleManager) GetSampleConfig(sampleName string, forceRefresh bool) (*SampleConfig, error)
GetSampleConfig returns the available config for this sample
func (*SampleManager) Initialize ¶ added in v1.13.7
func (s *SampleManager) Initialize(app string) error
Initialize gets the sample ready for the user to copy. It: 1. creates the sample cache folder if it doesn't exist 2. store the path of the local cache folder for later use 3. if the selected app does not exist in the local cache folder, clone it 4. if the selected app does exist in the local cache folder, pull changes 5. parse the sample cli config file
func (*SampleManager) MakeFolder ¶ added in v1.13.7
func (s *SampleManager) MakeFolder(name string) (string, error)
MakeFolder creates the folder that'll contain the Stripe app the user is creating
func (*SampleManager) PostInstall ¶ added in v1.13.7
func (s *SampleManager) PostInstall() string
PostInstall returns any installation for post installation instructions
func (*SampleManager) WriteDotEnv ¶ added in v1.13.7
func (s *SampleManager) WriteDotEnv(ctx context.Context, sampleLocation string) error
WriteDotEnv takes the .env.example from the provided location and modifies it to automatically configure it for the users settings
type SelectedConfig ¶ added in v1.6.0
type SelectedConfig struct { Integration *SampleConfigIntegration Client string Server string }
SelectedConfig is the sample config that the user has selected to create