-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from AirHelp/feat/add_delete_operation
Add delete option to allow keys removal
- Loading branch information
Showing
13 changed files
with
204 additions
and
7 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
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
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,23 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/AirHelp/treasury/types" | ||
"github.com/AirHelp/treasury/utils" | ||
) | ||
|
||
// Delete removeds specified secret for given key | ||
func (c *Client) Delete(key string) error { | ||
if err := utils.ValidateInputKey(key); err != nil { | ||
return err | ||
} | ||
|
||
secretObject := &types.DeleteObjectInput{ | ||
Key: key, | ||
} | ||
|
||
if err := c.Backend.DeleteObject(secretObject); err != nil { | ||
return err | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package client_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/AirHelp/treasury/client" | ||
test "github.com/AirHelp/treasury/test/backend" | ||
) | ||
|
||
func TestDelete(t *testing.T) { | ||
|
||
dummyClientOptions := &client.Options{ | ||
Backend: &test.MockBackendClient{}, | ||
S3BucketName: "fake_s3_bucket", | ||
} | ||
|
||
treasury, err := client.New(dummyClientOptions) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
err = treasury.Delete(test.Key9) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
// Check whether the key was deleted | ||
got, err := treasury.ReadValue(test.Key9) | ||
|
||
if err == nil { | ||
t.Errorf("Client.ReadValue() returned nil value for error when there should be one ") | ||
return | ||
} | ||
|
||
if got != "" { | ||
t.Errorf("Client.ReadValue() returned non empty string for deleted key") | ||
return | ||
} | ||
} |
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,59 @@ | ||
// Copyright © 2016 AirHelp Inc. devops@airhelp.com | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/AirHelp/treasury/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// deleteCmd represents the delete command | ||
var deleteCmd = &cobra.Command{ | ||
Use: "delete KEY", | ||
Short: "Remove secrets from Treasury", | ||
Long: `Remove secret with the given key from Treasury.`, | ||
RunE: delete, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(deleteCmd) | ||
deleteCmd.SuggestFor = []string{"remove"} | ||
} | ||
|
||
func delete(cmd *cobra.Command, args []string) error { | ||
if len(args) != 1 { | ||
return errors.New("Missing Key to delete.") | ||
} | ||
key := args[0] | ||
|
||
treasury, err := client.New(&client.Options{ | ||
Region: s3Region, | ||
S3BucketName: treasuryS3, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = treasury.Delete(key) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Key %s has been successfully deleted\n", key) | ||
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,2 @@ | ||
APPLICATION_SECRET_KEY={{ read "test/webapp/user_api_pass" }} | ||
NAME={{ .Name }} |
1 change: 0 additions & 1 deletion
1
test/resources/source.secret.tpl → .../resources/source.not_existing_secret.tpl
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
APPLICATION_SECRET_KEY={{ read "test/webapp/user_api_pass" }} | ||
APPLICATION_NON_EXISTING_KEY={{ read "test/none/user_api_pass" }} | ||
NAME={{ .Name }} |
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