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

fix: remove empty fields from output #67

Merged
merged 5 commits into from
Dec 11, 2023
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
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/spf13/cobra v1.3.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.10.1
github.com/stretchr/testify v1.7.0
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a
go.uber.org/mock v0.2.0
golang.org/x/net v0.17.0
Expand All @@ -20,12 +21,14 @@ require (

require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
Expand All @@ -34,4 +37,5 @@ require (
golang.org/x/text v0.13.0 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
11 changes: 11 additions & 0 deletions models/app-member.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ type AppMember struct {
json.RawMessage
AppId string `json:"appId"`
}

func (s *AppMember) MarshalJSON() ([]byte, error) {
var data map[string]any
if err := json.Unmarshal(s.RawMessage, &data); err != nil {
return nil, err
} else {
StripEmptyEntries(data)
data["appId"] = s.AppId
return json.Marshal(data)
}
}
12 changes: 12 additions & 0 deletions models/app-owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ type AppOwner struct {
AppId string `json:"appId"`
}

func (s *AppOwner) MarshalJSON() ([]byte, error) {
output := make(map[string]any)
output["appId"] = s.AppId

if owner, err := OmitEmpty(s.Owner); err != nil {
return nil, err
} else {
output["owner"] = owner
return json.Marshal(output)
}
}

type AppOwners struct {
Owners []AppOwner `json:"owners"`
AppId string `json:"appId"`
Expand Down
8 changes: 4 additions & 4 deletions models/azure/access_policy_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ package azure
// vault's tenant ID.
type AccessPolicyEntry struct {
// Application ID of the client making request on behalf of a principal
ApplicationId string `json:"applicationId"`
ApplicationId string `json:"applicationId,omitempty"`

// The object ID of a user, service principal or security group in the Azure Active Directory tenant for the vault.
// The object ID must be unique for the list of access policies.
ObjectId string `json:"objectId"`
ObjectId string `json:"objectId,omitempty"`

// Permissions the identity has for keys, secrets and certificates.
Permissions KeyVaultPermissions `json:"permissions"`
Permissions KeyVaultPermissions `json:"permissions,omitempty"`

// The Azure Active Directory tenant ID that should be used for authenticating requests to the key vault.
TenantId string `json:"tenantId"`
TenantId string `json:"tenantId,omitempty"`
}
4 changes: 2 additions & 2 deletions models/azure/addin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ import "github.com/gofrs/uuid"
// Microsoft 365 call the application in the context of a document the user is working on.
type AddIn struct {
Id uuid.UUID `json:"id,omitempty"`
Properties []KeyValue `json:"properties"`
Type string `json:"type"`
Properties []KeyValue `json:"properties,omitempty"`
Type string `json:"type,omitempty"`
}
4 changes: 2 additions & 2 deletions models/azure/additional_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ package azure
// Enables or disables a capability on the virtual machine or virtual machine scale set.
type AdditionalCapabilities struct {
// The flag that enables or disables hibernation capability on the VM.
HibernationEnabled bool `json:"hibernationEnabled"`
HibernationEnabled bool `json:"hibernationEnabled,omitempty"`

// The flag that enables or disables a capability to have one or more managed data disks with UltraSSD_LRS storage
// account type on the VM or VMSS. Managed disks with storage account type UltraSSD_LRS can be added to a virtual
// machine or virtual machine scale set only if this property is enabled.
UltraSSDEnabled bool `json:"ultraSSDEnabled"`
UltraSSDEnabled bool `json:"ultraSSDEnabled,omitempty"`
}
8 changes: 4 additions & 4 deletions models/azure/additional_unattend_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ package azure
// Windows Setup. Contents are defined by setting name, component name, and the pass in which the content is applied.
type AdditionalUnattendContent struct {
// The component name. Currently, the only allowable value is Microsoft-Windows-Shell-Setup.
ComponentName string `json:"componentName"`
ComponentName string `json:"componentName,omitempty"`

// Specifies the XML formatted content that is added to the unattend.xml file for the specified path and component.
// The XML must be less than 4KB and must include the root element for the setting or feature that is being inserted.
Content string `json:"content"`
Content string `json:"content,omitempty"`

// The pass name. Currently, the only allowable value is OobeSystem.
PassName string `json:"passName"`
PassName string `json:"passName,omitempty"`

// Specifies the name of the setting to which the content applies.
// Possible values are: FirstLogonCommands and AutoLogon.
SettingName string `json:"settingName"`
SettingName string `json:"settingName,omitempty"`
}
6 changes: 3 additions & 3 deletions models/azure/alt_security_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package azure

// For internal use only. This complex type will be deprecated in the future.
type AlternativeSecurityId struct {
Type int32 `json:"type"`
IdentityProvider string `json:"identity_provider"`
Type int32 `json:"type,omitempty"`
IdentityProvider string `json:"identity_provider,omitempty"`

// Base64Url encoded.
Key string `json:"key"`
Key string `json:"key,omitempty"`
}
10 changes: 5 additions & 5 deletions models/azure/api_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ import "github.com/gofrs/uuid"
// For more detail see https://docs.microsoft.com/en-us/graph/api/resources/apiapplication?view=graph-rest-1.0
type ApiApplication struct {
// When true, allows an application to use claims mapping without specifying a custom signing key.
AcceptMappedClaims bool `json:"acceptMappedClaims"`
AcceptMappedClaims bool `json:"acceptMappedClaims,omitempty"`

// Used for bundling consent if you have a solution that contains two parts: a client app and a custom web API app.
// If you set the appID of the client app to this value, the user only consents once to the client app. Azure AD
// knows that consenting to the client means implicitly consenting to the web API and automatically provisions
// service principals for both APIs at the same time. Both the client and the web API app must be registered in the
// same tenant.
KnownClientApplications []uuid.UUID `json:"knownClientApplications"`
KnownClientApplications []uuid.UUID `json:"knownClientApplications,omitempty"`

// The definition of the delegated permissions exposed by the web API represented by this application registration.
// These delegated permissions may be requested by a client application, and may be granted by users or
// administrators during consent. Delegated permissions are sometimes referred to as OAuth 2.0 scopes.
OAuth2PermissionScopes []PermissionScope `json:"oauth2PermissionScopes"`
OAuth2PermissionScopes []PermissionScope `json:"oauth2PermissionScopes,omitempty"`

// Lists the client applications that are pre-authorized with the specified delegated permissions to access this
// application's APIs. Users are not required to consent to any pre-authorized application (for the permissions
// specified). However, any additional permissions not listed in preAuthorizedApplications (requested through
// incremental consent for example) will require user consent.
PreAuthorizedApplications []PreAuthorizedApplication `json:"preAuthorizedApplications"`
PreAuthorizedApplications []PreAuthorizedApplication `json:"preAuthorizedApplications,omitempty"`

// Specifies the access token version expected by this resource.
// This changes the version and format of the JWT produced independent of the endpoint or client used to request the
Expand All @@ -55,5 +55,5 @@ type ApiApplication struct {
//
// If signInAudience on the application is configured as AzureADandPersonalMicrosoftAccount, the value for this
//property must be 2
RequestedAccessTokenVersion int32 `json:"requestedAccessTokenVersion"`
RequestedAccessTokenVersion int32 `json:"requestedAccessTokenVersion,omitempty"`
}
2 changes: 1 addition & 1 deletion models/azure/app_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ package azure
// Contains the list of gallery applications that should be made available to the VM/VMSS.
type ApplicationProfile struct {
// Specifies the gallery applications that should be made available to the VM/VMSS
GalleryApplications []VMGalleryApplication `json:"galleryApplications"`
GalleryApplications []VMGalleryApplication `json:"galleryApplications,omitempty"`
}
14 changes: 7 additions & 7 deletions models/azure/app_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import "github.com/gofrs/uuid"
// With appRoleAssignments, app roles can be assigned to users, groups, or other applications' service principals.
// For more detail see https://docs.microsoft.com/en-us/graph/api/resources/approle?view=graph-rest-1.0
type AppRole struct {
AllowedMemberTypes []string `json:"allowedMemberTypes"`
Description string `json:"description"`
DisplayName string `json:"displayName"`
Id uuid.UUID `json:"id"`
IsEnabled bool `json:"isEnabled"`
Origin string `json:"origin"`
Value string `json:"value"`
AllowedMemberTypes []string `json:"allowedMemberTypes,omitempty"`
Description string `json:"description,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Id uuid.UUID `json:"id,omitempty"`
IsEnabled bool `json:"isEnabled,omitempty"`
Origin string `json:"origin,omitempty"`
Value string `json:"value,omitempty"`
}
17 changes: 8 additions & 9 deletions models/azure/app_role_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ import "github.com/gofrs/uuid"
// Represents an application role that can be requested by (and granted to) a client application, or that can be used to
// assign an application to users or groups in a specified role.
//
//
// An app role assignment is a relationship between the assigned principal (a user, a group, or a service principal),
// a resource application (the app's service principal) and an app role defined on the resource application.
//
// With appRoleAssignments, app roles can be assigned to users, groups, or other applications' service principals.
// For more detail see https://docs.microsoft.com/en-us/graph/api/resources/approleassignment?view=graph-rest-1.0
type AppRoleAssignment struct {
AppRoleId uuid.UUID `json:"appRoleId"`
CreatedDateTime string `json:"createdDateTime"`
Id string `json:"id"`
PrincipalDisplayName string `json:"principalDisplayName"`
PrincipalId uuid.UUID `json:"principalId"`
PrincipalType string `json:"principalType"`
ResourceDisplayName string `json:"resourceDisplayName"`
ResourceId string `json:"resourceId"`
AppRoleId uuid.UUID `json:"appRoleId,omitempty"`
CreatedDateTime string `json:"createdDateTime,omitempty"`
Id string `json:"id,omitempty"`
PrincipalDisplayName string `json:"principalDisplayName,omitempty"`
PrincipalId uuid.UUID `json:"principalId,omitempty"`
PrincipalType string `json:"principalType,omitempty"`
ResourceDisplayName string `json:"resourceDisplayName,omitempty"`
ResourceId string `json:"resourceId,omitempty"`
}

type AppRoleAssignmentList struct {
Expand Down
4 changes: 2 additions & 2 deletions models/azure/app_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ type AppScope struct {
// Provides the display name of the app-specific resource represented by the app scope.
// Provided for display purposes since appScopeId is often an immutable, non-human-readable id.
// Read-only.
DisplayName string `json:"display_name"`
DisplayName string `json:"display_name,omitempty"`

// Describes the type of app-specific resource represented by the app scope.
// Provided for display purposes, so a user interface can convey to the user the kind of app specific resource
// represented by the app scope.
// Read-only.
Type string `json:"type"`
Type string `json:"type,omitempty"`
}
4 changes: 2 additions & 2 deletions models/azure/assigned_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ package azure
// For more detail see https://docs.microsoft.com/en-us/graph/api/resources/assignedlabel?view=graph-rest-1.0
type AssignedLabel struct {
// The unique identifier of the label.
LabelId string `json:"labelId"`
LabelId string `json:"labelId,omitempty"`

// The display name of the label. Read-only.
DisplayName string `json:"displayName"`
DisplayName string `json:"displayName,omitempty"`
}
4 changes: 2 additions & 2 deletions models/azure/assigned_license.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import "github.com/gofrs/uuid"
// Represents a license assigned to a user.
type AssignedLicense struct {
// A collection of the unique identifiers for plans that have been disabled.
DisabledPlans []uuid.UUID `json:"disabledPlans"`
DisabledPlans []uuid.UUID `json:"disabledPlans,omitempty"`

// The unique identifier for the SKU.
SkuId uuid.UUID `json:"skuId"`
SkuId uuid.UUID `json:"skuId,omitempty"`
}
8 changes: 4 additions & 4 deletions models/azure/assigned_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (
// Represents a plan assigned to user and organization entities.
type AssignedPlan struct {
// The date and time at which the plan was assigned using ISO 8601 format.
AssignedDateTime string `json:"assignedDateTime"`
AssignedDateTime string `json:"assignedDateTime,omitempty"`

// Condition of the capability assignment.
CapabilityStatus enums.CapabiltyStatus `json:"capabilityStatus"`
CapabilityStatus enums.CapabiltyStatus `json:"capabilityStatus,omitempty"`

// The name of the service.
Service string `json:"service"`
Service string `json:"service,omitempty"`

// A GUID that identifies the service plan.
ServicePlanId uuid.UUID `json:"servicePlanId"`
ServicePlanId uuid.UUID `json:"servicePlanId,omitempty"`
}
12 changes: 6 additions & 6 deletions models/azure/automatic_replies_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ import (
type AutomaticRepliesSetting struct {
// The set of audience external to the signed-in user's organization who will receive the {@link
// ExternalReplyMessage}.
ExternalAudience enums.ExternalAudienceScope `json:"externalAudience"`
ExternalAudience enums.ExternalAudienceScope `json:"externalAudience,omitempty"`

// The automatic reply to send to the specified eternal audience.
ExternalReplyMessage string `json:"externalReplyMessage"`
ExternalReplyMessage string `json:"externalReplyMessage,omitempty"`

// The automatic reply to send to the audience internal to the signed-in user's organization.
InternalReplyMessage string `json:"internalReplyMessage"`
InternalReplyMessage string `json:"internalReplyMessage,omitempty"`

// The date and time that automatic replies are set to end.
ScheduledEndDateTime DateTimeTimeZone `json:"scheduledEndDateTime"`
ScheduledEndDateTime DateTimeTimeZone `json:"scheduledEndDateTime,omitempty"`

// The date and time that automatic replies are set to begin.
ScheduledStartDateTime DateTimeTimeZone `json:"scheduledStartDateTime"`
ScheduledStartDateTime DateTimeTimeZone `json:"scheduledStartDateTime,omitempty"`

// Configuration status for automatic replies.
Status enums.AutoReplyStatus `json:"status"`
Status enums.AutoReplyStatus `json:"status,omitempty"`
}
16 changes: 8 additions & 8 deletions models/azure/available_patch_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ import (
// Describes the properties of a virtual machine instance view for available patch summary.
type AvailablePatchSummary struct {
// The activity ID of the operation that produced this result. It is used to correlate across CRP and extension logs.
AssessmentActivityId string `json:"assessmentActivityId"`
AssessmentActivityId string `json:"assessmentActivityId,omitempty"`

// The number of critical or security patches that have been detected as available and not yet installed.
CriticalAndSecurityPatchCount int `json:"criticalAndSecurityPatchCount"`
CriticalAndSecurityPatchCount int `json:"criticalAndSecurityPatchCount,omitempty"`

// The errors that were encountered during execution of the operation. The details array contains the list of them.
Error ODataError `json:"error"`
Error ODataError `json:"error,omitempty"`

// The UTC timestamp when the operation began.
LastModifiedTime string `json:"lastModifiedTime"`
LastModifiedTime string `json:"lastModifiedTime,omitempty"`

// The number of all available patches excluding critical and security.
OtherPatchCount int `json:"otherPatchCount"`
OtherPatchCount int `json:"otherPatchCount,omitempty"`

// The overall reboot status of the VM. It will be true when partially installed patches require a reboot to
// complete installation but the reboot has not yet occurred.
RebootPending bool `json:"rebootPending"`
RebootPending bool `json:"rebootPending,omitempty"`

// The UTC timestamp when the operation began.
StartTime string `json:"startTime"`
StartTime string `json:"startTime,omitempty"`

// The overall success or failure status of the operation. It remains "InProgress" until the operation completes.
// At that point it will become "Unknown", "Failed", "Succeeded", or "CompletedWithWarnings."
Status enums.PatchStatus `json:"status"`
Status enums.PatchStatus `json:"status,omitempty"`
}
2 changes: 1 addition & 1 deletion models/azure/billing_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ type BillingProfile struct {
// Also, the default max price is -1 if it is not provided by you.
//
// Minimum api-version: 2019-03-01.
MaxPrice float64 `json:"maxPrice"`
MaxPrice float64 `json:"maxPrice,omitempty"`
}
4 changes: 2 additions & 2 deletions models/azure/boot_diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package azure

type BootDiagnotics struct {
// Whether boot diagnostics should be enabled on the virtual machine.
Enabled bool `json:"enabled"`
Enabled bool `json:"enabled,omitempty"`

// Uri of the storage account to use for placing the console output and screenshot.
// If storageUri is not specified while enabling boot diagnostics, managed storage will be used.
StorageUri string `json:"storageUri"`
StorageUri string `json:"storageUri,omitempty"`
}
6 changes: 3 additions & 3 deletions models/azure/boot_diagnostics_instance_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ package azure
type BootDiagnoticsInstanceView struct {
// The console screenshot blob URI.
// NOTE: This will not be set if boot diagnostics is currently enabled with managed storage.
ConsoleScreenshotBlobUri string `json:"consoleScreenshotBlobUri"`
ConsoleScreenshotBlobUri string `json:"consoleScreenshotBlobUri,omitempty"`

// The serial console log blob Uri.
// NOTE: This will not be set if boot diagnostics is currently enabled with managed storage.
SerialConsoleLogBlobUri string `json:"serialConsoleLogBlobUri"`
SerialConsoleLogBlobUri string `json:"serialConsoleLogBlobUri,omitempty"`

// The boot diagnostics status information for the VM.
// NOTE: It will be set only if there are errors encountered in enabling boot diagnostics.
Status InstanceViewStatus `json:"status"`
Status InstanceViewStatus `json:"status,omitempty"`
}
2 changes: 1 addition & 1 deletion models/azure/capacity_reservation_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ type CapacityReservationProfile struct {
// Specifies the capacity reservation group resource id that should be used for allocating the virtual machine or
// scaleset vm instances provided enough capacity has been reserved. Please refer to
// https://aka.ms/CapacityReservation for more details.
CapacityReservationGroup SubResource `json:"capacityReservationGroup"`
CapacityReservationGroup SubResource `json:"capacityReservationGroup,omitempty"`
}
Loading
Loading