-
Notifications
You must be signed in to change notification settings - Fork 96
Added support for Private Image Sharing #800
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
Merged
ezilber-akamai
merged 8 commits into
linode:proj/private-image-sharing
from
ezilber-akamai:TPT-3819-private-image-sharing
Sep 22, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cd42793
Added support for Private Image Sharing
ezilber-akamai 07337f2
Merge branch 'proj/private-image-sharing' into TPT-3819-private-image…
ezilber-akamai d77ef68
Add missing endpoint
ezilber-akamai c91e46c
Fix lint
ezilber-akamai 64adc68
Addressed copilot suggestions
ezilber-akamai 094eaf5
Reran monthly transfer fixture
ezilber-akamai a483c28
Addressed PR comments
ezilber-akamai e5bc5ba
More PR comments
ezilber-akamai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,208 @@ | ||
| package linodego | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "time" | ||
|
|
||
| "github.com/linode/linodego/internal/parseabletime" | ||
| ) | ||
|
|
||
| // ConsumerImageShareGroup represents an ImageShareGroup that the consumer is a member of. | ||
| type ConsumerImageShareGroup struct { | ||
| ID int `json:"id"` | ||
| UUID string `json:"uuid"` | ||
| Label string `json:"label"` | ||
| Description string `json:"description"` | ||
| IsSuspended bool `json:"is_suspended"` | ||
| Created *time.Time `json:"-"` | ||
| Updated *time.Time `json:"-"` | ||
| } | ||
|
|
||
| // UnmarshalJSON implements the json.Unmarshaler interface | ||
| func (isg *ConsumerImageShareGroup) UnmarshalJSON(b []byte) error { | ||
| type Mask ConsumerImageShareGroup | ||
|
|
||
| p := struct { | ||
| *Mask | ||
|
|
||
| Created *parseabletime.ParseableTime `json:"created"` | ||
| Updated *parseabletime.ParseableTime `json:"updated"` | ||
| }{ | ||
| Mask: (*Mask)(isg), | ||
| } | ||
|
|
||
| if err := json.Unmarshal(b, &p); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| isg.Created = (*time.Time)(p.Created) | ||
| isg.Updated = (*time.Time)(p.Updated) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // ImageShareGroupToken contains information about a token created by a consumer. | ||
| // The token itself is only visible once upon creation. | ||
| type ImageShareGroupToken struct { | ||
| TokenUUID string `json:"token_uuid"` | ||
| Status string `json:"status"` | ||
| Label string `json:"label"` | ||
| ValidForShareGroupUUID string `json:"valid_for_sharegroup_uuid"` | ||
| Created *time.Time `json:"-"` | ||
| Updated *time.Time `json:"-"` | ||
| Expiry *time.Time `json:"-"` | ||
| ShareGroupUUID *string `json:"sharegroup_uuid"` | ||
| ShareGroupLabel *string `json:"sharegroup_label"` | ||
| } | ||
|
|
||
| // UnmarshalJSON implements the json.Unmarshaler interface | ||
| func (t *ImageShareGroupToken) UnmarshalJSON(b []byte) error { | ||
| type Mask ImageShareGroupToken | ||
|
|
||
| p := struct { | ||
| *Mask | ||
|
|
||
| Created *parseabletime.ParseableTime `json:"created"` | ||
| Updated *parseabletime.ParseableTime `json:"updated"` | ||
| Expiry *parseabletime.ParseableTime `json:"expiry"` | ||
| }{ | ||
| Mask: (*Mask)(t), | ||
| } | ||
|
|
||
| if err := json.Unmarshal(b, &p); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| t.Created = (*time.Time)(p.Created) | ||
| t.Updated = (*time.Time)(p.Updated) | ||
| t.Expiry = (*time.Time)(p.Expiry) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // ImageShareGroupCreateTokenResponse represents the response when the consumer | ||
| // creates a single-use ImageShareGroup membership token. | ||
| // The token itself is only provided upon creation, and must be given to the producer | ||
| // via an outside medium for the consumer to be added as a member of the producer's ImageShareGroup. | ||
| type ImageShareGroupCreateTokenResponse struct { | ||
| Token string `json:"token"` | ||
| TokenUUID string `json:"token_uuid"` | ||
| Status string `json:"status"` | ||
| Label string `json:"label"` | ||
| ValidForShareGroupUUID string `json:"valid_for_sharegroup_uuid"` | ||
| Created *time.Time `json:"-"` | ||
| Updated *time.Time `json:"-"` | ||
| Expiry *time.Time `json:"-"` | ||
| ShareGroupUUID *string `json:"sharegroup_uuid"` | ||
| ShareGroupLabel *string `json:"sharegroup_label"` | ||
| } | ||
|
|
||
| // UnmarshalJSON implements the json.Unmarshaler interface | ||
| func (t *ImageShareGroupCreateTokenResponse) UnmarshalJSON(b []byte) error { | ||
| type Mask ImageShareGroupCreateTokenResponse | ||
|
|
||
| p := struct { | ||
| *Mask | ||
|
|
||
| Created *parseabletime.ParseableTime `json:"created"` | ||
| Updated *parseabletime.ParseableTime `json:"updated"` | ||
| Expiry *parseabletime.ParseableTime `json:"expiry"` | ||
| }{ | ||
| Mask: (*Mask)(t), | ||
| } | ||
|
|
||
| if err := json.Unmarshal(b, &p); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| t.Created = (*time.Time)(p.Created) | ||
| t.Updated = (*time.Time)(p.Updated) | ||
| t.Expiry = (*time.Time)(p.Expiry) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // ImageShareGroupCreateTokenOptions fields are those accepted by ImageShareGroupCreateToken | ||
| type ImageShareGroupCreateTokenOptions struct { | ||
| Label *string `json:"label,omitempty"` | ||
| ValidForShareGroupUUID string `json:"valid_for_sharegroup_uuid"` | ||
| } | ||
|
|
||
| // ImageShareGroupUpdateTokenOptions fields are those accepted by ImageShareGroupUpdateToken | ||
| type ImageShareGroupUpdateTokenOptions struct { | ||
| Label string `json:"label"` | ||
| } | ||
|
|
||
| // ImageShareGroupListTokens lists information about all the ImageShareGroupTokens created by the user. | ||
| // The tokens themselves are only visible once upon creation. | ||
| func (c *Client) ImageShareGroupListTokens(ctx context.Context, opts *ListOptions) ([]ImageShareGroupToken, error) { | ||
| return getPaginatedResults[ImageShareGroupToken]( | ||
| ctx, | ||
| c, | ||
| "/images/sharegroups/tokens", | ||
| opts, | ||
| ) | ||
| } | ||
|
|
||
| // ImageShareGroupGetToken gets information about the specified ImageShareGroupToken created by the user. | ||
| // the tokens themselves are only visible once upon creation. | ||
| func (c *Client) ImageShareGroupGetToken(ctx context.Context, tokenUUID string) (*ImageShareGroupToken, error) { | ||
| return doGETRequest[ImageShareGroupToken]( | ||
| ctx, | ||
| c, | ||
| formatAPIPath("images/sharegroups/tokens/%s", tokenUUID), | ||
| ) | ||
| } | ||
|
|
||
| // ImageShareGroupCreateToken allows the consumer to create a single-use ImageShareGroup membership | ||
| // token for a specific ImageShareGroup owned by the producer. | ||
| func (c *Client) ImageShareGroupCreateToken(ctx context.Context, opts ImageShareGroupCreateTokenOptions) (*ImageShareGroupCreateTokenResponse, error) { | ||
| return doPOSTRequest[ImageShareGroupCreateTokenResponse]( | ||
| ctx, | ||
| c, | ||
| formatAPIPath("images/sharegroups/tokens"), | ||
| opts, | ||
| ) | ||
| } | ||
|
|
||
| // ImageShareGroupUpdateToken allows the consumer to update an ImageShareGroupToken's label. | ||
| func (c *Client) ImageShareGroupUpdateToken(ctx context.Context, tokenUUID string, opts ImageShareGroupUpdateTokenOptions) (*ImageShareGroupToken, error) { | ||
| return doPUTRequest[ImageShareGroupToken]( | ||
| ctx, | ||
| c, | ||
| formatAPIPath("images/sharegroups/tokens/%s", tokenUUID), | ||
| opts, | ||
| ) | ||
| } | ||
|
|
||
| // ImageShareGroupRemoveToken allows the consumer to remove an individual ImageShareGroupToken from an ImageShareGroup | ||
| // this token has been accepted into. | ||
| func (c *Client) ImageShareGroupRemoveToken(ctx context.Context, tokenUUID string) error { | ||
| return doDELETERequest( | ||
| ctx, | ||
| c, | ||
| formatAPIPath("images/sharegroups/tokens/%s", tokenUUID), | ||
| ) | ||
| } | ||
|
|
||
| // ImageShareGroupGetByToken gets information about the ImageShareGroup that the | ||
| // consumer's specified token has been accepted into. | ||
| func (c *Client) ImageShareGroupGetByToken(ctx context.Context, tokenUUID string) (*ConsumerImageShareGroup, error) { | ||
| return doGETRequest[ConsumerImageShareGroup]( | ||
| ctx, | ||
| c, | ||
| formatAPIPath("images/sharegroups/tokens/%s/sharegroup", tokenUUID), | ||
| ) | ||
| } | ||
|
|
||
| // ImageShareGroupGetImagesByToken lists the images in the ImageShareGroup that the | ||
| // consumer's specified token has been accepted into. | ||
| func (c *Client) ImageShareGroupGetImagesByToken(ctx context.Context, tokenUUID string, opts *ListOptions) ([]Image, error) { | ||
| return getPaginatedResults[Image]( | ||
| ctx, | ||
| c, | ||
| formatAPIPath("images/sharegroups/tokens/%s/sharegroup/images", tokenUUID), | ||
| opts, | ||
| ) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.