Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor file upload function and update dependencies #493

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions modules/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package modules

import (
"fmt"
"io"
"os"
"path/filepath"
)

// ReadPayloadFromFile loads content from a file for upload
func ReadPayloadFromFile(filePath string) (string, error) {
absPath, err := filepath.Abs(filePath)
if err != nil {
return "", fmt.Errorf("failed to resolve absolute path: %v", err)
}

file, err := os.Open(absPath)
if err != nil {
return "", fmt.Errorf("failed to open file: %v", err)
}
defer file.Close()

content, err := io.ReadAll(file)
if err != nil {
return "", fmt.Errorf("failed to read file: %v", err)
}

return string(content), nil
}
61 changes: 61 additions & 0 deletions modules/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Module Package for Jamf Pro SDK

## Overview

The Module Package is designed to house a collection of reusable, utility functions. These functions are offered to enhance the development experience when creating recipes - complex operations that combine various Jamf Pro API actions to achieve specific outcomes.

## Purpose

The primary purpose of this module is to:

1. **Promote Code Reusability**: By centralizing common functions, we reduce redundancy across recipes and ensure consistent implementation.

2. **Simplify Recipe Development**: Developers can focus on the unique aspects of their recipes without reinventing common operations.

3. **Enhance Maintainability**: Updates to shared functions can be made in one place, benefiting all recipes that utilize them.

4. **Extend SDK Functionality**: While not directly related to CRUD operations, these modules complement the core SDK by providing additional utility.

## Key Features

- **Utility Functions**: A rich set of helper functions that address common needs in recipe development.
- **Platform-Agnostic**: Designed to work seamlessly across different environments and use cases.
- **Easy Integration**: Simple import process to use these functions in any recipe.
- **Continuous Expansion**: Regularly updated with new utilities based on community needs and feedback.

## Usage

To use functions from this module in your recipes:

```go
import (
"github.com/your-repo/jamfpro-sdk/modules"
)

func main() {
result := modules.SomeUtilityFunction(params)
// Use the result in your recipe
}
```

## Module Categories

The module package includes, but is not limited to, the following categories of functions:

1. **Data Manipulation**: Functions for parsing, formatting, and transforming data.
2. **File Operations**: Utilities for reading, writing, and managing files.
3. **Network Utilities**: Helper functions for network-related tasks.
4. **Validation**: Common validation routines used across different recipes.
5. **Logging and Debugging**: Enhanced logging and debugging capabilities.

## Contributing

We welcome contributions to the module package. If you have a utility function that you believe would be beneficial to the community, please submit a pull request with your proposed addition.

## Support

For questions, issues, or feature requests related to the module package, please open an issue in the GitHub repository or contact our support team.

---

By leveraging the Module Package, developers can create more efficient, maintainable, and robust recipes within the Jamf Pro ecosystem. This package embodies our commitment to providing a comprehensive and user-friendly development experience.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"fmt"
"log"
"os"

"github.com/deploymenttheory/go-api-sdk-jamfpro/modules"
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
)

Expand All @@ -21,7 +21,7 @@ func main() {
// Read the payload from a file
payloadFilePath := "/Users/dafyddwatkins/localtesting/terraform/support_files/mobileconfigurationprofiles/mobile-wifi.mobileconfig"

payload, err := readPayloadFromFile(payloadFilePath)
payload, err := modules.ReadPayloadFromFile(payloadFilePath)
if err != nil {
log.Fatalf("Error reading payload from file: %v", err)
}
Expand Down Expand Up @@ -67,12 +67,3 @@ func main() {
func stringPtr(s string) *string {
return &s
}

// readPayloadFromFile loads config profile for upload
func readPayloadFromFile(filePath string) (string, error) {
data, err := os.ReadFile(filePath)
if err != nil {
return "", err
}
return string(data), nil
}
Loading