Skip to content

Commit

Permalink
fix: add godocs
Browse files Browse the repository at this point in the history
  • Loading branch information
amandahla committed Dec 11, 2024
1 parent b139ded commit 3fa9531
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/juju/offers.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func newOffersClient(sc SharedClient) *offersClient {
}
}

// CreateOffer creates offer managed by the offer resource.
func (c offersClient) CreateOffer(input *CreateOfferInput) (*CreateOfferResponse, []error) {
var errs []error

Expand Down Expand Up @@ -159,6 +160,7 @@ func (c offersClient) CreateOffer(input *CreateOfferInput) (*CreateOfferResponse
return &resp, nil
}

// ReadOffer reads offer managed by the offer resource.
func (c offersClient) ReadOffer(input *ReadOfferInput) (*ReadOfferResponse, error) {
conn, err := c.GetConnection(nil)
if err != nil {
Expand Down Expand Up @@ -190,6 +192,7 @@ func (c offersClient) ReadOffer(input *ReadOfferInput) (*ReadOfferResponse, erro
return &response, nil
}

// DestroyOffer destroys offer managed by the offer resource.
func (c offersClient) DestroyOffer(input *DestroyOfferInput) error {
conn, err := c.GetConnection(nil)
if err != nil {
Expand Down Expand Up @@ -257,7 +260,7 @@ func parseModelFromURL(url string) (result string, success bool) {
return result, true
}

// This function allows the integration resource to consume the offers managed by the offer resource
// ConsumeRemoteOffer allows the integration resource to consume the offers managed by the offer resource.
func (c offersClient) ConsumeRemoteOffer(input *ConsumeRemoteOfferInput) (*ConsumeRemoteOfferResponse, error) {
modelConn, err := c.GetConnection(&input.ModelName)
if err != nil {
Expand Down Expand Up @@ -338,7 +341,7 @@ func (c offersClient) ConsumeRemoteOffer(input *ConsumeRemoteOfferInput) (*Consu
return &response, nil
}

// This function allows the integration resource to destroy the offers managed by the offer resource
// RemoveRemoteOffer allows the integration resource to destroy the offers managed by the offer resource.
func (c offersClient) RemoveRemoteOffer(input *RemoveRemoteOfferInput) []error {
var errors []error
conn, err := c.GetConnection(&input.ModelName)
Expand Down Expand Up @@ -399,7 +402,7 @@ func (c offersClient) RemoveRemoteOffer(input *RemoveRemoteOfferInput) []error {
return nil
}

// This function adds access to an offer
// GrantOffer adds access to an offer managed by the access offer resource.
func (c offersClient) GrantOffer(input *GrantRevokeOfferInput) error {
conn, err := c.GetConnection(nil)
if err != nil {
Expand All @@ -421,7 +424,7 @@ func (c offersClient) GrantOffer(input *GrantRevokeOfferInput) error {
return nil
}

// This function revokes access to an offer.
// RevokeOffer revokes access to an offer managed by the access offer resource.
func (c offersClient) RevokeOffer(input *GrantRevokeOfferInput) error {
conn, err := c.GetConnection(nil)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions internal/provider/resource_access_offer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var _ resource.ResourceWithConfigure = &accessOfferResource{}
var _ resource.ResourceWithImportState = &accessOfferResource{}
var _ resource.ResourceWithConfigValidators = &accessOfferResource{}

// NewAccessOfferResource returns a new instance of the Access Offer resource.
func NewAccessOfferResource() resource.Resource {
return &accessOfferResource{}
}
Expand Down Expand Up @@ -105,6 +106,7 @@ func (a *accessOfferResource) Schema(_ context.Context, req resource.SchemaReque
}
}

// Create attempts to grant access to the offer.
func (a *accessOfferResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
// Check first if the client is configured
if a.client == nil {
Expand Down Expand Up @@ -156,6 +158,7 @@ func (a *accessOfferResource) Create(ctx context.Context, req resource.CreateReq
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

// Read reads users and permissions granted to the offer
func (a *accessOfferResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
// Check first if the client is configured
if a.client == nil {
Expand Down Expand Up @@ -214,6 +217,7 @@ func (a *accessOfferResource) Read(ctx context.Context, req resource.ReadRequest
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

// Update attempts to update the access to the offer.
func (a *accessOfferResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
// Check first if the client is configured
if a.client == nil {
Expand Down Expand Up @@ -320,6 +324,7 @@ func (a *accessOfferResource) Update(ctx context.Context, req resource.UpdateReq
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

// Delete remove access to the offer according to the resource.
func (a *accessOfferResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
// Check first if the client is configured
if a.client == nil {
Expand Down Expand Up @@ -356,6 +361,7 @@ func (a *accessOfferResource) Delete(ctx context.Context, req resource.DeleteReq
}
}

// Configure sets the access offer resource with provider data.
func (a *accessOfferResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
// Prevent panic if the provider has not been configured.
if req.ProviderData == nil {
Expand Down Expand Up @@ -383,6 +389,7 @@ func (r *accessOfferResource) ConfigValidators(ctx context.Context) []resource.C
}
}

// ImportState import existing resource to the state.
func (a *accessOfferResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
IDstr := req.ID
if len(strings.Split(IDstr, ":")) != 3 {
Expand Down

0 comments on commit 3fa9531

Please sign in to comment.