Skip to content

Commit

Permalink
Merge pull request #2314 from posit-dev/mnv-creds-services-in-line
Browse files Browse the repository at this point in the history
File Credentials Support
  • Loading branch information
marcosnav authored Sep 30, 2024
2 parents ef57890 + 6ed6c53 commit 5f2148a
Show file tree
Hide file tree
Showing 23 changed files with 604 additions and 638 deletions.
26 changes: 21 additions & 5 deletions cmd/publisher/commands/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ type CreateCredentialCommand struct {
}

func (cmd *CreateCredentialCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error {
cs := credentials.NewCredentialsService(logging.NewDiscardLogger())
cs, err := credentials.NewCredentialsService(logging.NewDiscardLogger())
if err != nil {
return err
}

cred, err := cs.Set(cmd.Name, cmd.URL, cmd.ApiKey)
if err != nil {
return err
Expand All @@ -45,8 +49,12 @@ type DeleteCredentialCommand struct {
}

func (cmd *DeleteCredentialCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error {
cs := credentials.NewCredentialsService(logging.NewDiscardLogger())
err := cs.Delete(cmd.GUID)
cs, err := credentials.NewCredentialsService(logging.NewDiscardLogger())
if err != nil {
return err
}

err = cs.Delete(cmd.GUID)
if err != nil {
return err
}
Expand All @@ -60,7 +68,11 @@ type GetCredentialCommand struct {
}

func (cmd *GetCredentialCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error {
cs := credentials.NewCredentialsService(logging.NewDiscardLogger())
cs, err := credentials.NewCredentialsService(logging.NewDiscardLogger())
if err != nil {
return err
}

cred, err := cs.Get(cmd.GUID)
if err != nil {
return err
Expand All @@ -79,7 +91,11 @@ type ListCredentialsCommand struct {
}

func (cmd *ListCredentialsCommand) Run(args *cli_types.CommonArgs, ctx *cli_types.CLIContext) error {
cs := credentials.NewCredentialsService(logging.NewDiscardLogger())
cs, err := credentials.NewCredentialsService(logging.NewDiscardLogger())
if err != nil {
return err
}

creds, err := cs.List()
if err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions cmd/publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ func main() {
defer pprof.StopCPUProfile()
}
ctx.Logger = events.NewCLILogger(cli.Verbose, os.Stderr)
ctx.Accounts = accounts.NewAccountList(ctx.Fs, ctx.Logger)
accounts, err := accounts.NewAccountList(ctx.Fs, ctx.Logger)
if err != nil {
Fatal(err)
}
ctx.Accounts = accounts

logVersion(ctx.Logger)
err := args.Run(&cli.CommonArgs)
err = args.Run(&cli.CommonArgs)
if err != nil {
Fatal(err)
}
Expand Down
4 changes: 0 additions & 4 deletions extensions/vscode/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ const credentialsContexts = {
EnvironmentVars: "posit.publisher.credentials.tree.item.environmentVars",
};

export const CredentialGUIs = {
EnvironmentGUID: "00000000-0000-0000-0000-000000000000",
};

const filesCommands = {
Refresh: "posit.publisher.files.refresh",
Exclude: "posit.publisher.files.exclude",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
:title="credential.name"
:description="credential.url"
:data-automation="`${credential.name}-list`"
:codicon="
credential.guid === CredentialGUIs.EnvironmentGUID
? 'codicon-bracket'
: 'codicon-key'
"
codicon="codicon-key"
align-icon-with-twisty
:data-vscode-context="vscodeContext(credential)"
/>
Expand All @@ -35,7 +31,6 @@ import { useHomeStore } from "src/stores/home";
import { useHostConduitService } from "src/HostConduitService";
import { Credential } from "../../../../../src/api";
import { CredentialGUIs } from "../../../../../src/constants";
import { WebviewToHostMessageType } from "../../../../../src/types/messages/webviewToHostMessages";
const home = useHomeStore();
Expand Down Expand Up @@ -64,10 +59,6 @@ const sectionActions = computed(() => {
});
const vscodeContext = (credential: Credential) => {
if (credential.guid === CredentialGUIs.EnvironmentGUID) {
return undefined;
}
return JSON.stringify({
credentialGUID: credential.guid,
credentialName: credential.name,
Expand Down
15 changes: 9 additions & 6 deletions internal/accounts/account_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ type defaultAccountList struct {

var _ AccountList = &defaultAccountList{}

func NewAccountList(fs afero.Fs, log logging.Logger) *defaultAccountList {
return &defaultAccountList{
providers: []AccountProvider{
NewCredentialsProvider(log),
},
log: log,
func NewAccountList(fs afero.Fs, log logging.Logger) (*defaultAccountList, error) {
cprovider, err := NewCredentialsProvider(log)
if err != nil {
return nil, err
}

return &defaultAccountList{
providers: []AccountProvider{cprovider},
log: log,
}, nil
}

func (l *defaultAccountList) GetAllAccounts() (accounts []Account, err error) {
Expand Down
3 changes: 2 additions & 1 deletion internal/accounts/account_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func (s *AccountListSuite) SetupSuite() {
func (s *AccountListSuite) TestNewAccountList() {
log := logging.New()
fs := utiltest.NewMockFs()
accountList := NewAccountList(fs, log)
accountList, err := NewAccountList(fs, log)
s.NoError(err)
s.Len(accountList.providers, 1)
s.Equal(log, accountList.log)
}
Expand Down
9 changes: 6 additions & 3 deletions internal/accounts/provider_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ type CredentialsProvider struct {
cs credentials.CredentialsService
}

func NewCredentialsProvider(log logging.Logger) *CredentialsProvider {
return &CredentialsProvider{
cs: credentials.NewCredentialsService(log),
func NewCredentialsProvider(log logging.Logger) (*CredentialsProvider, error) {
cs, err := credentials.NewCredentialsService(log)
if err != nil {
return nil, err
}

return &CredentialsProvider{cs}, nil
}

func (p *CredentialsProvider) Load() ([]Account, error) {
Expand Down
Loading

0 comments on commit 5f2148a

Please sign in to comment.