Skip to content

Commit

Permalink
Implement methods for user secrets management
Browse files Browse the repository at this point in the history
This commit introduces internal/juju/userSecret and adds method to add user secrets.
  • Loading branch information
anvial committed Mar 27, 2024
1 parent f2a76f8 commit 1e971f1
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions internal/juju/userSecret.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2024 Canonical Ltd.
// Licensed under the Apache License, Version 2.0, see LICENCE file for details.

package juju

import (
"strings"

"github.com/juju/juju/api/client/secrets"
)

type userSecretClient struct {

Check failure on line 12 in internal/juju/userSecret.go

View workflow job for this annotation

GitHub Actions / golangci-lint

type `userSecretClient` is unused (unused)
SharedClient
}

type AddUserSecretInput struct {
ModelName string
Name string
Value string
Description string
}

type AddUserSecretOutput struct {
SecretURI string
}

type ReadUserSecretInput struct {
ModelName string
Name string
}

type UpdateUserSecretInput struct {
ModelName string
Name string
Value string
}

type RemoveUserSecretInput struct {
ModelName string
Name string
}

func newUserSecretClient(sc SharedClient) *userSecretClient {

Check failure on line 43 in internal/juju/userSecret.go

View workflow job for this annotation

GitHub Actions / golangci-lint

func `newUserSecretClient` is unused (unused)
return &userSecretClient{
SharedClient: sc,
}
}

func (c *userSecretClient) AddUserSecret(input *AddUserSecretInput) (*AddUserSecretOutput, error) {

Check failure on line 49 in internal/juju/userSecret.go

View workflow job for this annotation

GitHub Actions / golangci-lint

func `(*userSecretClient).AddUserSecret` is unused (unused)
conn, err := c.GetConnection(&input.ModelName)
if err != nil {
return nil, err
}
defer func() { _ = conn.Close() }()

client := secrets.NewClient(conn)
secretURI, err := client.CreateSecret(input.Name, input.Description, parseSecretValueStringToMap(input.Value))
if err != nil {
return nil, err
}
return &AddUserSecretOutput{
SecretURI: secretURI,
}, nil
}

func parseSecretValueStringToMap(input string) map[string]string {

Check failure on line 66 in internal/juju/userSecret.go

View workflow job for this annotation

GitHub Actions / golangci-lint

func `parseSecretValueStringToMap` is unused (unused)
result := make(map[string]string)
pairs := strings.Split(input, " ")

for _, pair := range pairs {
kv := strings.Split(pair, "=")
if len(kv) == 2 {
result[kv[0]] = kv[1]
}
}

return result
}

0 comments on commit 1e971f1

Please sign in to comment.